ops4j / org.ops4j.pax.exam2

Pax Exam is a testing framework for OSGi
https://ops4j1.jira.com/wiki/spaces/PAXEXAM4/
Apache License 2.0
84 stars 100 forks source link

Unclosed streams in KarafTestContainer cause failure of Karaf integration tests on Windows #1027

Closed vassilz closed 2 years ago

vassilz commented 3 years ago

Streams in org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer#setupSystemProperties and org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer#updateLogProperties are not closed.

Karaf integration tests also replace the log configuration file: KarafDistributionOption.replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg", getConfigFile("/etc/org.ops4j.pax.logging.cfg")),

This leads to file access errors on Windows: java.lang.RuntimeException: Container never came up at org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer.stop(KarafTestContainer.java:688) at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.tearDown(EagerSingleStagedReactor.java:118) at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.afterClass(EagerSingleStagedReactor.java:132) at org.ops4j.pax.exam.spi.reactors.ReactorManager.afterClass(ReactorManager.java:441) at org.ops4j.pax.exam.junit.impl.ProbeRunner.run(ProbeRunner.java:107) at org.ops4j.pax.exam.junit.PaxExam.run(PaxExam.java:93) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)

Process finished with exit code -2

java.lang.IllegalStateException: Error occured while replacing file C:\Users\vasil\IdeaProjects\karaf\itests\test\target\exam\95aa38e2-a6a1-405e-8072-afe35347a34e\etc\org.ops4j.pax.logging.cfg

at org.ops4j.pax.exam.karaf.container.internal.KarafConfigurationFile.replace(KarafConfigurationFile.java:47)
at org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer.updateUserSetProperties(KarafTestContainer.java:474)
at org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer.start(KarafTestContainer.java:189)
at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.setUp(EagerSingleStagedReactor.java:86)
at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.beforeClass(EagerSingleStagedReactor.java:136)
at org.ops4j.pax.exam.spi.reactors.ReactorManager.beforeClass(ReactorManager.java:457)
at org.ops4j.pax.exam.junit.impl.ProbeRunner.run(ProbeRunner.java:97)
at org.ops4j.pax.exam.junit.PaxExam.run(PaxExam.java:93)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)

Caused by: java.nio.file.FileSystemException: C:\Users\vasil\IdeaProjects\karaf\itests\test\target\exam\95aa38e2-a6a1-405e-8072-afe35347a34e\etc\org.ops4j.pax.logging.cfg: The process cannot access the file because it is being used by another process.

at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
at java.base/sun.nio.fs.WindowsFileCopy.copy(WindowsFileCopy.java:164)
at java.base/sun.nio.fs.WindowsFileSystemProvider.copy(WindowsFileSystemProvider.java:279)
at java.base/java.nio.file.Files.copy(Files.java:1287)
at org.apache.commons.io.FileUtils.doCopyFile(FileUtils.java:1392)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:885)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:835)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:802)
at org.ops4j.pax.exam.karaf.container.internal.KarafConfigurationFile.replace(KarafConfigurationFile.java:44)
... 12 more
vassilz commented 3 years ago

PR: https://github.com/ops4j/org.ops4j.pax.exam2/pull/1028