嵌入的cassandra单元测试,junit4.12+gradle4.9运行到nosuchfileexception中

crcmnpdw  于 2021-06-10  发布在  Cassandra
关注(0)|答案(1)|浏览(335)

我有一个测试,初始化嵌入式Cassandra为

EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.CASSANDRA_RNDPORT_YML_FILE, <timeout>)

初始化时在gradle中抛出以下堆栈跟踪

19:16:46.043 [DEBUG] [TestEventLogger]     FSWriteError in target/embeddedCassandra/hints
19:16:46.043 [DEBUG] [TestEventLogger]         at org.apache.cassandra.io.util.FileUtils.deleteWithConfirm(FileUtils.java:137)
19:16:46.043 [DEBUG] [TestEventLogger]         at org.apache.cassandra.io.util.FileUtils.deleteWithConfirm(FileUtils.java:154)
19:16:46.043 [DEBUG] [TestEventLogger]         at org.apache.cassandra.io.util.FileUtils.deleteRecursive(FileUtils.java:443)
19:16:46.043 [DEBUG] [TestEventLogger]         at org.apache.cassandra.io.util.FileUtils.deleteRecursive(FileUtils.java:439)
19:16:46.043 [DEBUG] [TestEventLogger]         at org.cassandraunit.utils.EmbeddedCassandraServerHelper.rmdir(EmbeddedCassandraServerHelper.java:282)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:87)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:70)
19:16:46.044 [DEBUG] [TestEventLogger]         at com.testapp.communicator.common.CassandraSampleStoreTest.<init>(CassandraSampleStoreTest.java:61)
19:16:46.044 [DEBUG] [TestEventLogger]         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
19:16:46.044 [DEBUG] [TestEventLogger]         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
19:16:46.044 [DEBUG] [TestEventLogger]         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
19:16:46.044 [DEBUG] [TestEventLogger]         at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
19:16:46.044 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
19:16:46.044 [DEBUG] [TestEventLogger]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
19:16:46.044 [DEBUG] [TestEventLogger]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
19:16:46.044 [DEBUG] [TestEventLogger]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
19:16:46.045 [DEBUG] [TestEventLogger]         at java.lang.reflect.Method.invoke(Method.java:498)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
19:16:46.045 [DEBUG] [TestEventLogger]         at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:118)
19:16:46.045 [DEBUG] [TestEventLogger]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
19:16:46.045 [DEBUG] [TestEventLogger]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
19:16:46.045 [DEBUG] [TestEventLogger]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
19:16:46.045 [DEBUG] [TestEventLogger]         at java.lang.reflect.Method.invoke(Method.java:498)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:175)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:157)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
19:16:46.045 [DEBUG] [TestEventLogger]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
19:16:46.045 [DEBUG] [TestEventLogger]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
19:16:46.045 [DEBUG] [TestEventLogger]         at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
19:16:46.045 [DEBUG] [TestEventLogger]         at java.lang.Thread.run(Thread.java:748)
19:16:46.045 [DEBUG] [TestEventLogger]
19:16:46.045 [DEBUG] [TestEventLogger]         Caused by:
19:16:46.045 [DEBUG] [TestEventLogger]         java.nio.file.NoSuchFileException: target/embeddedCassandra/hints
19:16:46.045 [DEBUG] [TestEventLogger]             at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
19:16:46.045 [DEBUG] [TestEventLogger]             at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
19:16:46.045 [DEBUG] [TestEventLogger]             at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
19:16:46.046 [DEBUG] [TestEventLogger]             at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:244)
19:16:46.046 [DEBUG] [TestEventLogger]             at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
19:16:46.046 [DEBUG] [TestEventLogger]             at java.nio.file.Files.delete(Files.java:1126)
19:16:46.046 [DEBUG] [TestEventLogger]             at org.apache.cassandra.io.util.FileUtils.deleteWithConfirm(FileUtils.java:131)
19:16:46.046 [DEBUG] [TestEventLogger]             ... 53 more

上面清楚地告诉我们,它之所以发生是因为它无法在它正在寻找的地方找到它正在寻找的资源。但我尝试在这里实现其他解决方案,比如将资源复制到 ${buildDir}/classes 或者设置源代码集等。这个问题仅限于gradle构建,在使用maven测试运行时不是问题。
target/embeddedCassandra/hints 是从embeddedcassandraserverhelper代码中获取的,我无法将其更改为在类加载器的上下文中使用 getClassLoader() 将资源复制到 build/classes 文件夹本来就没用。
非常感谢您的建议。

wvmv3b1j

wvmv3b1j1#

作为替代,我可以向你求婚https://github.com/nosan/embedded-cassandra 项目

相关问题