java.lang.AssertionError:Cassandra守护程序未在超时内启动
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java.lang.AssertionError:Cassandra守护程序未在超时内启动相关的知识,希望对你有一定的参考价值。
我的测试班:
public class NetworkSettingsDaoTest {
@Rule
public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet("simpleWithCreateKeyspace.cql"));
public static Session session;
public static NetworkSettingsDao networkSettingsDao;
@Before
public void init() throws ConfigurationException, TTransportException, IOException, InterruptedException{
EmbeddedCassandraServerHelper.startEmbeddedCassandra(5600000L);
//Thread.sleep(4*1000); //workaround for weak machine
session = cassandraCQLUnit.getSession();
networkSettingsDao = new NetworkSettingsDao();
}
@Test
public void should_have_started_and_execute_cql_script() throws Exception {
ResultSet result = session.execute("select * from mytable WHERE id='myKey01'");
assertThat(result.iterator().next().getString("value"), is("myValue01"));
}
}
我的simpleWithCreateKeyspace.cql文件:
CREATE KEYSPACE NETWORKSETTINGS WITH replication={'class' : 'SimpleStrategy', 'replication_factor':1};
USE NETWORKSETTINGS;
CREATE TABLE STBDevice(
KEY varchar,
SETTINGS_COLUMN varchar,
AMSIP varchar,
PRIMARY KEY(KEY));
INSERT INTO STBDevice(KEY, SETTINGS_COLUMN,AMSIP) values('myKey01','myColumn1','myAMSIP1');
例外:
java.lang.AssertionError:Cassandra守护程序未在org中的org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:130)的org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:85)的超时内启动。 cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:64)在org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:56)在org.cassandraunit.BaseCassandraUnit.before(BaseCassandraUnit.java:28)在org.junit .rules.ExternalResource $ 1.evaluate(ExternalResource.java:46)org.junit.rules.RunRules.evaluate(RunRules.java:20)atg.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)at org org.junit.ru上的org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)中的.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) nners.ParentRunner $ 3.run(ParentRunner.java:238)org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:63)org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)at org .junit.runners.ParentRunner.access $ 000(ParentRunner.java:53)org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:229)org.junit.runners.ParentRunner.run(ParentRunner.java:309) )org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)at org。 eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)位于org.eclipse.jdt的org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)。 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)中的internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
就我而言,服务器始终在默认的10秒窗口内启动,直到昨天。今天需要50至70秒。没有有效的解释。因此,看起来唯一的选择是增加超时。
看起来,这取决于你在Cassandra上发出的查询数量。如果你有太多的查询要运行,那么你需要增加EmbeddedCassandra注释的超时。 @EmbeddedCassandra(timeout = 100000L)
这堂课帮助解决了问题
package org.cassandraunit.test.spring.cql;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
import org.cassandraunit.spring.CassandraDataSet;
import org.cassandraunit.spring.CassandraUnitTestExecutionListener;
import org.cassandraunit.spring.EmbeddedCassandra;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({ CassandraUnitTestExecutionListener.class })
@CassandraDataSet(value = { "simple.cql" })
@EmbeddedCassandra
public class SpringCQLScriptLoadTest {
@Test
public void should_have_started_and_execute_cql_script() throws Exception {
Cluster cluster = Cluster.builder()
.addContactPoints("127.0.0.1")
.withPort(9142)
.build();
Session session = cluster.connect("cassandra_unit_keyspace");
ResultSet result = session.execute("select * from mytable WHERE id='myKey01'");
assertThat(result.iterator().next().getString("value"), is("myValue01"));
}
}
以上是关于java.lang.AssertionError:Cassandra守护程序未在超时内启动的主要内容,如果未能解决你的问题,请参考以下文章
java.lang.AssertionError:找到的值显示为空
mockMVC 方法 GET java.lang.AssertionError:预期状态:200 实际:500
更新到 Android Studio 4.1 时出现 java.lang.AssertionError
Mvn clean package 给出了一个意外的 java.lang.AssertionError
EasyMock set方法报错: java.lang.AssertionError
AndroidX.Test ActivityScenario: java.lang.AssertionError: Activity 永远不会变为请求状态“[RESUMED]”(最后一个生命周期转换