Merge branch '1.3.x
This commit is contained in:
commit
c974de0119
|
@ -30,6 +30,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||
*
|
||||
* @author Dave Syer
|
||||
* @author Christian Dupuis
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "endpoints.shutdown")
|
||||
public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>>
|
||||
|
@ -61,8 +62,7 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>>
|
|||
return SHUTDOWN_MESSAGE;
|
||||
}
|
||||
finally {
|
||||
new Thread(new Runnable() {
|
||||
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
@ -73,8 +73,9 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>>
|
|||
}
|
||||
ShutdownEndpoint.this.context.close();
|
||||
}
|
||||
|
||||
}).start();
|
||||
});
|
||||
thread.setContextClassLoader(getClass().getClassLoader());
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package org.springframework.boot.actuate.endpoint;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -34,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoint> {
|
||||
|
||||
|
@ -50,18 +54,31 @@ public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoin
|
|||
|
||||
@Test
|
||||
public void invoke() throws Exception {
|
||||
CountDownLatch latch = this.context.getBean(Config.class).latch;
|
||||
assertThat((String) getEndpointBean().invoke().get("message"))
|
||||
.startsWith("Shutting down");
|
||||
Config config = this.context.getBean(Config.class);
|
||||
ClassLoader previousTccl = Thread.currentThread().getContextClassLoader();
|
||||
Map<String, Object> result;
|
||||
Thread.currentThread().setContextClassLoader(
|
||||
new URLClassLoader(new URL[0], getClass().getClassLoader()));
|
||||
try {
|
||||
result = getEndpointBean().invoke();
|
||||
}
|
||||
finally {
|
||||
Thread.currentThread().setContextClassLoader(previousTccl);
|
||||
}
|
||||
assertThat((String) result.get("message")).startsWith("Shutting down");
|
||||
assertThat(this.context.isActive()).isTrue();
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(config.latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(config.threadContextClassLoader)
|
||||
.isEqualTo(getClass().getClassLoader());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
public static class Config {
|
||||
|
||||
private CountDownLatch latch = new CountDownLatch(1);
|
||||
private final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
private volatile ClassLoader threadContextClassLoader;
|
||||
|
||||
@Bean
|
||||
public ShutdownEndpoint endpoint() {
|
||||
|
@ -75,6 +92,8 @@ public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoin
|
|||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextClosedEvent event) {
|
||||
Config.this.threadContextClassLoader = Thread.currentThread()
|
||||
.getContextClassLoader();
|
||||
Config.this.latch.countDown();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue