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
pull/3013/head
Andy Wilkinson 10 years ago
parent 50af2b144b
commit b7a02feda8

@ -10,6 +10,24 @@
</properties> </properties>
<build> <build>
<plugins> <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> <plugin>
<groupId>@project.groupId@</groupId> <groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId> <artifactId>@project.artifactId@</artifactId>
@ -30,6 +48,7 @@
</executions> </executions>
<configuration> <configuration>
<fork>true</fork> <fork>true</fork>
<jmxPort>${jmx.port}</jmxPort>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

@ -17,6 +17,7 @@
package org.test; package org.test;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.ObjectName; import javax.management.ObjectName;
@ -47,7 +48,6 @@ public class SampleApplication {
} }
waitAttempts++; waitAttempts++;
} }
System.out.println("Application has terminated gracefully");
} }
@ -67,6 +67,7 @@ public class SampleApplication {
@Override @Override
public boolean isReady() { public boolean isReady() {
System.out.println("isReady: " + this.ready);
return this.ready; return this.ready;
} }

@ -1,6 +1,5 @@
import static org.junit.Assert.assertTrue import static org.junit.Assert.assertTrue
def file = new File(basedir, "build.log") 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 '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++; waitAttempts++;
} }
System.out.println("Application has terminated gracefully");
} }
@ -67,6 +66,7 @@ public class SampleApplication {
@Override @Override
public boolean isReady() { public boolean isReady() {
System.out.println("isReady: " + this.ready);
return this.ready; return this.ready;
} }

@ -1,6 +1,5 @@
import static org.junit.Assert.assertTrue import static org.junit.Assert.assertTrue
def file = new File(basedir, "build.log") 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 'Shutdown should have been invoked', file.text.contains("Shutdown requested")
assertTrue 'Application should have terminated', file.text.contains("Application has terminated gracefully")

Loading…
Cancel
Save