Search in sources :

Example 1 with StartupStep

use of org.springframework.core.metrics.StartupStep in project spring-boot by spring-projects.

the class BufferingApplicationStartupTests method taggingShouldFailWhenRemovingEntry.

@Test
void taggingShouldFailWhenRemovingEntry() {
    BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(2);
    StartupStep step = applicationStartup.start("first");
    step.tag("name", "value");
    assertThatThrownBy(() -> step.getTags().iterator().remove()).isInstanceOf(UnsupportedOperationException.class);
}
Also used : StartupStep(org.springframework.core.metrics.StartupStep) Test(org.junit.jupiter.api.Test)

Example 2 with StartupStep

use of org.springframework.core.metrics.StartupStep in project spring-boot by spring-projects.

the class BufferingApplicationStartupTests method shouldNotRecordEventsWhenFiltered.

@Test
void shouldNotRecordEventsWhenFiltered() {
    BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(5);
    applicationStartup.addFilter((step) -> step.getName().startsWith("spring"));
    applicationStartup.start("spring.first").end();
    StartupStep filtered = applicationStartup.start("filtered.second");
    applicationStartup.start("spring.third").end();
    filtered.end();
    List<TimelineEvent> events = applicationStartup.getBufferedTimeline().getEvents();
    assertThat(events).hasSize(2);
    StartupTimeline.TimelineEvent firstEvent = events.get(0);
    assertThat(firstEvent.getStartupStep().getId()).isEqualTo(0);
    assertThat(firstEvent.getStartupStep().getParentId()).isNull();
    StartupTimeline.TimelineEvent secondEvent = events.get(1);
    assertThat(secondEvent.getStartupStep().getId()).isEqualTo(2);
    assertThat(secondEvent.getStartupStep().getParentId()).isEqualTo(1);
}
Also used : TimelineEvent(org.springframework.boot.context.metrics.buffering.StartupTimeline.TimelineEvent) StartupStep(org.springframework.core.metrics.StartupStep) TimelineEvent(org.springframework.boot.context.metrics.buffering.StartupTimeline.TimelineEvent) Test(org.junit.jupiter.api.Test)

Example 3 with StartupStep

use of org.springframework.core.metrics.StartupStep in project spring-boot by spring-projects.

the class ServletWebServerApplicationContext method createWebServer.

private void createWebServer() {
    WebServer webServer = this.webServer;
    ServletContext servletContext = getServletContext();
    if (webServer == null && servletContext == null) {
        StartupStep createWebServer = this.getApplicationStartup().start("spring.boot.webserver.create");
        ServletWebServerFactory factory = getWebServerFactory();
        createWebServer.tag("factory", factory.getClass().toString());
        this.webServer = factory.getWebServer(getSelfInitializer());
        createWebServer.end();
        getBeanFactory().registerSingleton("webServerGracefulShutdown", new WebServerGracefulShutdownLifecycle(this.webServer));
        getBeanFactory().registerSingleton("webServerStartStop", new WebServerStartStopLifecycle(this, this.webServer));
    } else if (servletContext != null) {
        try {
            getSelfInitializer().onStartup(servletContext);
        } catch (ServletException ex) {
            throw new ApplicationContextException("Cannot initialize servlet context", ex);
        }
    }
    initPropertySources();
}
Also used : ServletException(jakarta.servlet.ServletException) ServletWebServerFactory(org.springframework.boot.web.servlet.server.ServletWebServerFactory) WebServer(org.springframework.boot.web.server.WebServer) StartupStep(org.springframework.core.metrics.StartupStep) WebServerGracefulShutdownLifecycle(org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle) ServletContext(jakarta.servlet.ServletContext) ApplicationContextException(org.springframework.context.ApplicationContextException)

Example 4 with StartupStep

use of org.springframework.core.metrics.StartupStep in project spring-boot by spring-projects.

the class SpringApplicationRunListeners method doWithListeners.

private void doWithListeners(String stepName, Consumer<SpringApplicationRunListener> listenerAction, Consumer<StartupStep> stepAction) {
    StartupStep step = this.applicationStartup.start(stepName);
    this.listeners.forEach(listenerAction);
    if (stepAction != null) {
        stepAction.accept(step);
    }
    step.end();
}
Also used : StartupStep(org.springframework.core.metrics.StartupStep)

Example 5 with StartupStep

use of org.springframework.core.metrics.StartupStep in project spring-boot by spring-projects.

the class ReactiveWebServerApplicationContext method createWebServer.

private void createWebServer() {
    WebServerManager serverManager = this.serverManager;
    if (serverManager == null) {
        StartupStep createWebServer = this.getApplicationStartup().start("spring.boot.webserver.create");
        String webServerFactoryBeanName = getWebServerFactoryBeanName();
        ReactiveWebServerFactory webServerFactory = getWebServerFactory(webServerFactoryBeanName);
        createWebServer.tag("factory", webServerFactory.getClass().toString());
        boolean lazyInit = getBeanFactory().getBeanDefinition(webServerFactoryBeanName).isLazyInit();
        this.serverManager = new WebServerManager(this, webServerFactory, this::getHttpHandler, lazyInit);
        getBeanFactory().registerSingleton("webServerGracefulShutdown", new WebServerGracefulShutdownLifecycle(this.serverManager.getWebServer()));
        getBeanFactory().registerSingleton("webServerStartStop", new WebServerStartStopLifecycle(this.serverManager));
        createWebServer.end();
    }
    initPropertySources();
}
Also used : StartupStep(org.springframework.core.metrics.StartupStep) WebServerGracefulShutdownLifecycle(org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle) ReactiveWebServerFactory(org.springframework.boot.web.reactive.server.ReactiveWebServerFactory)

Aggregations

StartupStep (org.springframework.core.metrics.StartupStep)12 Test (org.junit.jupiter.api.Test)6 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Supplier (java.util.function.Supplier)2 PostConstruct (javax.annotation.PostConstruct)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)2 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)2 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)2 Assertions.assertThatNoException (org.assertj.core.api.Assertions.assertThatNoException)2