我有一个将嵌入式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
文件夹中本质上是无用的。
建议深表感谢。