Commit b7a02fed authored by Andy Wilkinson's avatar Andy Wilkinson

Make the Maven plugin’s start and stop tests more robust

 - Verify that isReady has been called
 - When forking, use a random port for JMX
 - Don’t wait for application termination as it introduces a race
   condition and verifying that shutdown has been requested is
   sufficient

See gh-2525
parent 50af2b14
......@@ -10,6 +10,24 @@
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-jmx-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>jmx.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
......@@ -30,6 +48,7 @@
</executions>
<configuration>
<fork>true</fork>
<jmxPort>${jmx.port}</jmxPort>
</configuration>
</plugin>
</plugins>
......
......@@ -17,6 +17,7 @@
package org.test;
import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.ObjectName;
......@@ -47,7 +48,6 @@ public class SampleApplication {
}
waitAttempts++;
}
System.out.println("Application has terminated gracefully");
}
......@@ -67,6 +67,7 @@ public class SampleApplication {
@Override
public boolean isReady() {
System.out.println("isReady: " + this.ready);
return this.ready;
}
......
import static org.junit.Assert.assertTrue
def file = new File(basedir, "build.log")
assertTrue 'Start should have waited for application to be ready', file.text.contains("isReady: true")
assertTrue 'Shutdown should have been invoked', file.text.contains("Shutdown requested")
assertTrue 'Application should have terminated', file.text.contains("Application has terminated gracefully")
......@@ -47,7 +47,6 @@ public class SampleApplication {
}
waitAttempts++;
}
System.out.println("Application has terminated gracefully");
}
......@@ -67,6 +66,7 @@ public class SampleApplication {
@Override
public boolean isReady() {
System.out.println("isReady: " + this.ready);
return this.ready;
}
......
import static org.junit.Assert.assertTrue
def file = new File(basedir, "build.log")
assertTrue 'Start should have waited for application to be ready', file.text.contains("isReady: true")
assertTrue 'Shutdown should have been invoked', file.text.contains("Shutdown requested")
assertTrue 'Application should have terminated', file.text.contains("Application has terminated gracefully")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment