Open TvdW opened 4 years ago
... this would be even better if I mentioned what actually goes wrong.
java.lang.NoClassDefFoundError: org/cassandraunit/shaded/io/netty/util/concurrent/FastThreadLocal
at org.apache.cassandra.config.DatabaseDescriptor.applySimpleConfig(DatabaseDescriptor.java:614)
at org.apache.cassandra.config.DatabaseDescriptor.applyAll(DatabaseDescriptor.java:324)
at org.apache.cassandra.config.DatabaseDescriptor.daemonInitialization(DatabaseDescriptor.java:153)
at org.apache.cassandra.config.DatabaseDescriptor.daemonInitialization(DatabaseDescriptor.java:137)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:145)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:108)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:88)
at my.package.CassandraTestUtils.setUp(CassandraTestUtils.java:42)
at my.package.CassandraTestCase.setUp(CassandraTestCase.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.RunBefores.invokeMethod(RunBefores.java:33)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.lang.ClassNotFoundException: org.cassandraunit.shaded.io.netty.util.concurrent.FastThreadLocal
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 44 more
same issue happens to me...
We're in the same boat. Latest version of the library suffers from ClassNotFound exceptions.
I also had the above problem, I understood that there is currently no library that would allow creating embedded Cassandra for testing with Spring 2.3.x and Java 11.
hi, for the moment i used test containers for testing cassandra in java 11 and worked like a charm.
All you need to do is:
GenericContainer<?> cassandra =
new GenericContainer<>("cassandra:3").withExposedPorts(9042);
cassandra.start();
I also had the above problem, I understood that there is currently no library that would allow creating embedded Cassandra for testing with Spring 2.3.x and Java 11.
I've managed non shaded version work with SpringBoot 2.3.1
<dependencies>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-spring</artifactId>
<scope>test</scope>
<version>4.3.1.0</version>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
You must also make sure you use old version of Google Guava in the project 25.1-jre
I switched to testcontainers as well:
@EnableAutoConfiguration
@ContextConfiguration(initializers = MyRepositoryTest.Initializer)
@EnableCassandraRepositories(basePackages = "my.package.repository")
class MyRepositoryTest extends Specification {
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
void initialize(ConfigurableApplicationContext applicationContext) {
CassandraContainer cassandra = new CassandraContainer()
cassandra.withInitScript(new ClassPathResource('setup.cql').path)
cassandra.start()
TestPropertyValues.of(
"spring.data.cassandra.contact-points=127.0.0.1",
"spring.data.cassandra.port=${cassandra.getMappedPort(9042)}",
'spring.data.cassandra.local-datacenter=datacenter1',
'spring.data.cassandra.keyspace-name=my_key_space'
).applyTo(applicationContext);
}
}
...
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>cassandra</artifactId>
<version>1.14.3</version>
<scope>test</scope>
</dependency>
Inspirered from https://stackoverflow.com/questions/57529031/how-to-use-testcontainers-cassandra-with-spring-data-for-apache-cassandra
Test containers are the great way for local junit tests, but unfortunately for eg jenkins when we don't want to use docker is useless. I'm still thinking how to test cassandra without docker :/
@Crovitz Why do you don't want to use docker on your jenkins? We're using these testcontainers without any issues on our jenkins nodes eg. for frontendtests with different browsers and now for cassandra.
@Chr3is okey perhaps i should change my deployment way, but does it really affect the length of deploy, because it must run docker and container with exposed port?
@Crovitz in our case we have nodes which run directly on hardware and nodes which are run on vms. But docker is always directly installed on the host so builds running with jenkins can access the docker deamon. This means builds won't start a docker deamon - the deamon is running the whole time. The most expensive part is probably downloading the image but this should be cached on the host machine after the first download/build. In terms of performance you should be fine. And a big advantage is that you do not depend on an os. So your tests can be run without any problems on every os eg. windows, mac, linux they just need to have docker installed (which is/should probably always the case nowadays). You should give it a try and make your own expirience :).
@Chr3is thank you for reply, sound like a great solution. I will try to do it like you ;)
I'm having the same issue. The cause of it is that io.netty
is transparent dependency of Cassandra's java-driver-core
, which is marked "optional" in cassandra-unit
. Therefore, cassandra-shaded
doesn't have dependency on io.netty
at all.
I solved this issue by having my own cassandra-unit-repack
project that tweak the dependency and shading configurations. It works fine with spring-boot 2.3.1 and Java 11.
Hope this helps
Hi @stonedu1011 , Do you mind to provide a PR about that?
Is there any workaround for this issue, enabling the use of the shaded jar? Any plan to merge the Pull Request?
The pom.xml of cassandra-unit-shaded specifies that it should shade
io.netty
, however for some reason it doesn't end up doing so, as of the 4.3.1.0 release. This renders the shaded package useless, as it cannot start Cassandra.Compare:
I suspect this is somehow related to changes in the dependency tree from the com.datastax.oss modules, but it's not clear to me what the fix should be.