gpt4 book ai didi

java.nio.file.FileSystemException : cannot access the file because it is being used by another process

转载 作者:太空宇宙 更新时间:2023-11-04 12:20:32 26 4
gpt4 key购买 nike

我正在使用 Junit 编写单元测试类,并且还使用 power-mocking 概念来模拟方法内创建的对象。

测试类:

@PowerMockIgnore("javax.management.*")
@RunWith(PowerMockRunner.class)
@PrepareForTest(Client.class)
public class ClientTest {
private static final Logger logger = LoggerFactory
.getLogger(ClientTest.class);

private static Client client;

private static DetailsDao detailsDao;
public static Session session;
private static IDevicesDao devicesDao;
private static IUserDao userDao;
private static IDao dao;
private static IValidator validator;



@BeforeClass
public static void setup() throws Exception {

logger.info("*************** Testing ClientTest Started *******************");

session = Connection.get(); // Here getting error

detailsDao = mock(DetailsDao.class);
devicesDao = mock(IDevicesDao.class);
userDao = mock(UserDao.class);
validator = mock(IValidator.class);
dao= mock(IDao.class);

client = new Client(detailsDao, session, devicesDao, userDao, dao, validator);
}

如果我删除 @RunWith(PowerMockRunner.class) 那么它工作正常...但我必须仅使用 PowerMockRunner 运行此测试。

异常:

[10:45:50] sumanth nama: Tests run: 1, Failures: 0, Errors: 1, Skipped: 0,      Time elapsed: 1.234 sec <<< FAILURE!
com.service.clientTest Time elapsed: 1.234 sec <<< ERROR!
FSWriteError in target\embeddedCassandra\commitlog\CommitLog-4-1470892233532.log
at org.apache.cassandra.io.util.FileUtils.deleteWithConfirm(FileUtils.java:135)
at org.apache.cassandra.io.util.FileUtils.deleteRecursive(FileUtils.java:381)
at org.apache.cassandra.io.util.FileUtils.deleteRecursive(FileUtils.java:377)
at org.apache.cassandra.io.util.FileUtils.deleteRecursive(FileUtils.java:377)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.rmdir(EmbeddedCassandraSer verHelper.java:266)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:81)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:64)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:56)
at com.charter.aesd.crossmso.wifi.dao.Connection.get(Connection.java:26)
at com.service.ClientTest.setup(ClientTest.java:76)
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:497)
at org.junit.internal.runners.ClassRoadie.runBefores(ClassRoadie.java:57)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at o rg.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
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:497)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.nio.file.FileSystemException: target\embeddedCassandra\commitlog\CommitLog-4-1470892233532.log: The process cannot access the file because it is being used by another process.

我不明白...为什么它无法使用 power mock runner 创建 cassandra session ...

最佳答案

还模拟了 session ,然后它运行时没有任何错误。

已替换

session = Connection.get();

session = mock(Session.class);

关于java.nio.file.FileSystemException : cannot access the file because it is being used by another process,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38889477/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com