Polish "Add support for GET requests for /actuator/startup"

See gh-24717
This commit is contained in:
Stephane Nicoll
2021-01-11 09:12:53 +01:00
parent 4b8d6efc12
commit 632c1239e6
4 changed files with 66 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -16,13 +16,17 @@
package org.springframework.boot.actuate.startup;
import java.util.function.Consumer;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringBootVersion;
import org.springframework.boot.actuate.startup.StartupEndpoint.StartupResponse;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.metrics.ApplicationStartup;
import static org.assertj.core.api.Assertions.assertThat;
@@ -37,11 +41,8 @@ class StartupEndpointTests {
@Test
void startupEventsAreFound() {
BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(256);
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withInitializer((context) -> context.setApplicationStartup(applicationStartup))
.withUserConfiguration(EndpointConfiguration.class);
contextRunner.run((context) -> {
StartupEndpoint.StartupResponse startup = context.getBean(StartupEndpoint.class).startup();
testStartupEndpoint(applicationStartup, (startupEndpoint) -> {
StartupResponse startup = startupEndpoint.startup();
assertThat(startup.getSpringBootVersion()).isEqualTo(SpringBootVersion.getVersion());
assertThat(startup.getTimeline().getStartTime())
.isEqualTo(applicationStartup.getBufferedTimeline().getStartTime());
@@ -49,28 +50,32 @@ class StartupEndpointTests {
}
@Test
void bufferIsDrained() {
void bufferWithGetIsNotDrained() {
BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(256);
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withInitializer((context) -> context.setApplicationStartup(applicationStartup))
.withUserConfiguration(EndpointConfiguration.class);
contextRunner.run((context) -> {
StartupEndpoint.StartupResponse startup = context.getBean(StartupEndpoint.class).startup();
testStartupEndpoint(applicationStartup, (startupEndpoint) -> {
StartupResponse startup = startupEndpoint.startupSnapshot();
assertThat(startup.getTimeline().getEvents()).isNotEmpty();
assertThat(applicationStartup.getBufferedTimeline().getEvents()).isNotEmpty();
});
}
@Test
void bufferWithPostIsDrained() {
BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(256);
testStartupEndpoint(applicationStartup, (startupEndpoint) -> {
StartupResponse startup = startupEndpoint.startup();
assertThat(startup.getTimeline().getEvents()).isNotEmpty();
assertThat(applicationStartup.getBufferedTimeline().getEvents()).isEmpty();
});
}
@Test
void bufferIsNotDrained() {
BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(256);
private void testStartupEndpoint(ApplicationStartup applicationStartup, Consumer<StartupEndpoint> startupEndpoint) {
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withInitializer((context) -> context.setApplicationStartup(applicationStartup))
.withUserConfiguration(EndpointConfiguration.class);
contextRunner.run((context) -> {
StartupEndpoint.StartupResponse startup = context.getBean(StartupEndpoint.class).startupSnapshot();
assertThat(startup.getTimeline().getEvents()).isNotEmpty();
assertThat(applicationStartup.getBufferedTimeline().getEvents()).isNotEmpty();
assertThat(context).hasSingleBean(StartupEndpoint.class);
startupEndpoint.accept(context.getBean(StartupEndpoint.class));
});
}