|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|