parent
3432044997
commit
a5537bd2e1
@ -1 +0,0 @@
|
|||||||
invoker.goals=clean verify
|
|
@ -1,61 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>org.springframework.boot.maven.it</groupId>
|
|
||||||
<artifactId>start-stop-automatic-fork</artifactId>
|
|
||||||
<version>0.0.1.BUILD-SNAPSHOT</version>
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<maven.compiler.source>@java.version@</maven.compiler.source>
|
|
||||||
<maven.compiler.target>@java.version@</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>build-helper-maven-plugin</artifactId>
|
|
||||||
<version>@build-helper-maven-plugin.version@</version>
|
|
||||||
<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>
|
|
||||||
<version>@project.version@</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>pre-integration-test</id>
|
|
||||||
<goals>
|
|
||||||
<goal>start</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<jvmArguments>-Dfoo=bar</jvmArguments>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>post-integration-test</id>
|
|
||||||
<goals>
|
|
||||||
<goal>stop</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<jmxPort>${jmx.port}</jmxPort>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2017 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.test;
|
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
|
|
||||||
import javax.management.MBeanServer;
|
|
||||||
import javax.management.ObjectName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This sample app simulates the JMX Mbean that is exposed by the Spring Boot application.
|
|
||||||
*/
|
|
||||||
public class SampleApplication {
|
|
||||||
|
|
||||||
private static final Object lock = new Object();
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
|
||||||
ObjectName name = new ObjectName(
|
|
||||||
"org.springframework.boot:type=Admin,name=SpringApplication");
|
|
||||||
SpringApplicationAdmin mbean = new SpringApplicationAdmin();
|
|
||||||
mbs.registerMBean(mbean, name);
|
|
||||||
|
|
||||||
// Flag the app as ready
|
|
||||||
mbean.ready = true;
|
|
||||||
|
|
||||||
int waitAttempts = 0;
|
|
||||||
while (!mbean.shutdownInvoked) {
|
|
||||||
if (waitAttempts > 30) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Shutdown should have been invoked by now");
|
|
||||||
}
|
|
||||||
synchronized (lock) {
|
|
||||||
lock.wait(250);
|
|
||||||
}
|
|
||||||
waitAttempts++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface SpringApplicationAdminMXBean {
|
|
||||||
|
|
||||||
boolean isReady();
|
|
||||||
|
|
||||||
void shutdown();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static class SpringApplicationAdmin implements SpringApplicationAdminMXBean {
|
|
||||||
|
|
||||||
private boolean ready;
|
|
||||||
|
|
||||||
private boolean shutdownInvoked;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isReady() {
|
|
||||||
System.out.println("isReady: " + this.ready);
|
|
||||||
return this.ready;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void shutdown() {
|
|
||||||
this.shutdownInvoked = true;
|
|
||||||
System.out.println("Shutdown requested");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
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")
|
|
Loading…
Reference in New Issue