Browse Source

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 11 years ago
parent
commit
b7a02feda8
  1. 19
      spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-fork/pom.xml
  2. 3
      spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-fork/src/main/java/org/test/SampleApplication.java
  3. 3
      spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-fork/verify.groovy
  4. 2
      spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop/src/main/java/org/test/SampleApplication.java
  5. 3
      spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop/verify.groovy

19
spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-fork/pom.xml

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

3
spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-fork/src/main/java/org/test/SampleApplication.java

@ -17,6 +17,7 @@ @@ -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 { @@ -47,7 +48,6 @@ public class SampleApplication {
}
waitAttempts++;
}
System.out.println("Application has terminated gracefully");
}
@ -67,6 +67,7 @@ public class SampleApplication { @@ -67,6 +67,7 @@ public class SampleApplication {
@Override
public boolean isReady() {
System.out.println("isReady: " + this.ready);
return this.ready;
}

3
spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop-fork/verify.groovy

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
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")

2
spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop/src/main/java/org/test/SampleApplication.java

@ -47,7 +47,6 @@ public class SampleApplication { @@ -47,7 +47,6 @@ public class SampleApplication {
}
waitAttempts++;
}
System.out.println("Application has terminated gracefully");
}
@ -67,6 +66,7 @@ public class SampleApplication { @@ -67,6 +66,7 @@ public class SampleApplication {
@Override
public boolean isReady() {
System.out.println("isReady: " + this.ready);
return this.ready;
}

3
spring-boot-tools/spring-boot-maven-plugin/src/it/start-stop/verify.groovy

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
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")

Loading…
Cancel
Save