2016-06-06 11 views
2

My Test-Klasse:java.lang.AssertionError: Cassandra Dämon startet nicht innerhalb Timeout

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")); 
} 
} 

Meine simpleWithCreateKeyspace.cql Datei:

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'); 

Ausnahme:

java.lang.AssertionError: Cassandra daemon did not start within timeout at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:130) at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:85) at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:64) at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:56) at org.cassandraunit.BaseCassandraUnit.before(BaseCassandraUnit.java:28) at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at 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) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Antwort

0

Diese Klasse geholfen Probleme

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")); 
} 
    } 
+0

Was war das Problem zu lösen? – jbird

0

In Mein Fall, der Server hat IMMER innerhalb der Standard-10-Sekunden-Fenster bis gestern gestartet. Heute dauert es 50 bis 70 Sekunden. Keine gültige Erklärung. Es sieht so aus, als ob die einzige Möglichkeit darin besteht, das Timeout zu erhöhen.