簡體   English   中英

java.nio.file.FileSystemException:無法訪問該文件,因為它正由另一個進程使用

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

我正在使用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 = Connection.get();

session = mock(Session.class);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM