2

We have some unit tests that unfortunately create memory-mapped NIO files that cannot be deleted by the process that created them (some windows issue).

Regardless, I would like to run some sort of clean up after these tests, whether they passed or not. I was going to run a small ant script at the prepare-package phase, but if any test fails, surefire exits immediately.

Apart from going to the failsafe plugin which has a post-test phase, is there any clever way I can run my cleanup regardless of pass or fail?

I suspect not - I've gone through all the surefire config options...

edit: memory-mapped nio files cannot be deleted in the same process, even by deleteOnExit.

marathon
  • 7,881
  • 17
  • 74
  • 137

3 Answers3

2

You should bound the thing you want to do into the post-integration-test lifecycle phase which is running afterwards the integration-test phase which is handled by the maven-failsafe-plugin. It might work if you configure the maven-clean-plugin to do so.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • if surefire fails on a test, it doesn't seem to fire off any more phases. It just forces maven to exit. – marathon Aug 24 '12 at 03:41
  • 2
    Of course, cause failing tests is an indication that's something wrong which needs to be fixed first before continuing. You can use mvn -Dmaven.test.failure.ignore=true (but i don't recommend that). – khmarbaise Aug 24 '12 at 07:22
  • 1
    @marathon Failsafe is designed so that even if the tests fail, the `post-integration-test` phase still runs and does any cleanup – artbristol Aug 24 '12 at 08:13
  • 1
    @artbristol that's supposed to be the case, but I haven't seen a good sample pom file that demonstrates it along with how everything needs to be configured. I'm having a somewhat similar problem as marathon and I'm sure it's a configuration problem, but I can't figure out what I'm doing wrong. But marathon wants to try to do it without failsafe, anyway. – Rebeccah May 17 '17 at 22:49
1

I would make sure the files are created in either target/ or the OS's temporary directory (using System.getProperty("java.io.tmpdir"). Then they will be cleaned up automatically when you run mvn clean, or eventually by the OS.

artbristol
  • 32,010
  • 5
  • 70
  • 103
0

Add following dependancy in pom and remove existing from your POM

        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19.1</version>
                </plugin>
            </plugins>
        </build>
vaquar khan
  • 10,864
  • 5
  • 72
  • 96