jsevellec / cassandra-unit

Utility tool to load Data into Cassandra to help you writing good isolated JUnit Test into your application
GNU Lesser General Public License v3.0
424 stars 0 forks source link

Tests fail in dropKeyspaces() in case of timeout. #220

Open kporowski opened 7 years ago

kporowski commented 7 years ago

It looks like when there is a timeout on 'DROP KEYSPACE mytestkeyspace' CassandraUnitDependencyInjectionIntegrationTestExecutionListener.afterTestClass() fails and test is marked as Error, even though it passed correctly. See attached logs:

INFO org.apache.cassandra.service.MigrationManager - Drop Keyspace 'mytestkeyspace'
WARN com.datastax.driver.core.RequestHandler - Not retrying statement because it is not idempotent (this message will be logged only once).
Note that this version of the driver changes the default retry behavior for non-idempotent statements: they won't be automatically retried anymore.
The driver marks statements non-idempotent by default, so you should explicitly call setIdempotent(true) if your statements are safe to retry.
See http://goo.gl/4HrSby for more details.
WARN org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.cassandraunit.spring.CassandraUnitDependencyInjectionIntegrationTestExecutionListener@574134ba] to process 'after class' callback for test class
com.datastax.driver.core.exceptions.OperationTimedOutException: [localhost/127.0.0.1:40480] Timed out waiting for server response
    at com.datastax.driver.core.exceptions.OperationTimedOutException.copy(OperationTimedOutException.java:44) ~[cassandra-driver-core-3.1.3.jar:?]
    at com.datastax.driver.core.exceptions.OperationTimedOutException.copy(OperationTimedOutException.java:26) ~[cassandra-driver-core-3.1.3.jar:?]
    at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:37) ~[cassandra-driver-core-3.1.3.jar:?]
    at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:245) ~[cassandra-driver-core-3.1.3.jar:?]
    at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:68) ~[cassandra-driver-core-3.1.3.jar:?]
    at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:43) ~[cassandra-driver-core-3.1.3.jar:?]
    at org.cassandraunit.utils.EmbeddedCassandraServerHelper.dropKeyspacesWithNativeDriver(EmbeddedCassandraServerHelper.java:318) ~[cassandra-unit-3.1.1.0.jar:?]
    at org.cassandraunit.utils.EmbeddedCassandraServerHelper.dropKeyspaces(EmbeddedCassandraServerHelper.java:288) ~[cassandra-unit-3.1.1.0.jar:?]
    at org.cassandraunit.utils.EmbeddedCassandraServerHelper.cleanEmbeddedCassandra(EmbeddedCassandraServerHelper.java:187) ~[cassandra-unit-3.1.1.0.jar:?]
    at org.cassandraunit.spring.AbstractCassandraUnitTestExecutionListener.cleanServer(AbstractCassandraUnitTestExecutionListener.java:104) ~[cassandra-unit-spring-3.1.1.0.jar:?]
    at org.cassandraunit.spring.CassandraUnitDependencyInjectionIntegrationTestExecutionListener.afterTestClass(CassandraUnitDependencyInjectionIntegrationTestExecutionListener.java:37) ~[cassandra-unit-spring-3.1.1.0.jar:?]
    at org.springframework.test.context.TestContextManager.afterTestClass(TestContextManager.java:363) [spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:77) [spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) [spring-test-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283) [surefire-junit4-2.18.1.jar:2.18.1]
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173) [surefire-junit4-2.18.1.jar:2.18.1]
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153) [surefire-junit4-2.18.1.jar:2.18.1]
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128) [surefire-junit4-2.18.1.jar:2.18.1]
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203) [surefire-booter-2.18.1.jar:2.18.1]
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155) [surefire-booter-2.18.1.jar:2.18.1]
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103) [surefire-booter-2.18.1.jar:2.18.1]
Caused by: com.datastax.driver.core.exceptions.OperationTimedOutException: [localhost/127.0.0.1:40480] Timed out waiting for server response
    at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onTimeout(RequestHandler.java:770) ~[cassandra-driver-core-3.1.3.jar:?]
    at com.datastax.driver.core.Connection$ResponseHandler$1.run(Connection.java:1374) ~[cassandra-driver-core-3.1.3.jar:?]
    at io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:581) ~[netty-common-4.0.31.Final.jar:4.0.31.Final]
    at io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:655) ~[netty-common-4.0.31.Final.jar:4.0.31.Final]
    at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:367) ~[netty-common-4.0.31.Final.jar:4.0.31.Final]
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) ~[netty-common-4.0.31.Final.jar:4.0.31.Final]
    at java.lang.Thread.run(Thread.java:745) ~[?:1.8.0_101]
kporowski commented 7 years ago

What should be the proper behavior:

dewafer commented 7 years ago

Same problem here, solved by this one: https://github.com/jsevellec/cassandra-unit/issues/210#issuecomment-270396532

tipso78 commented 7 years ago

Hi I have the same problem but the kporowski solution not work in my case. Any idea ? thank you

kporowski commented 7 years ago

There is a quick and dirty fix until this issue is diagnosed and fixed.

You can implement your custom class, that inherits from org.cassandraunit.spring.CassandraUnitDependencyInjectionIntegrationTestExecutionListener, and overrides its methods with implementation that can retry/ignore exceptions during startup/cleanup of server. Then use it in @TestExecutionListeners instead of org.cassandraunit.spring.CassandraUnitDependencyInjectionIntegrationTestExecutionListener.

tipso78 commented 7 years ago

Thank you for your very fast answer. The quick fix worked but i ashamed of this quick fixe. Any other idea ?