use of org.springframework.core.metrics.StartupStep in project spring-framework by spring-projects.
the class AnnotationConfigApplicationContext method register.
// ---------------------------------------------------------------------
// Implementation of AnnotationConfigRegistry
// ---------------------------------------------------------------------
/**
* Register one or more component classes to be processed.
* <p>Note that {@link #refresh()} must be called in order for the context
* to fully process the new classes.
* @param componentClasses one or more component classes — for example,
* {@link Configuration @Configuration} classes
* @see #scan(String...)
* @see #refresh()
*/
@Override
public void register(Class<?>... componentClasses) {
Assert.notEmpty(componentClasses, "At least one component class must be specified");
StartupStep registerComponentClass = this.getApplicationStartup().start("spring.context.component-classes.register").tag("classes", () -> Arrays.toString(componentClasses));
this.reader.register(componentClasses);
registerComponentClass.end();
}
use of org.springframework.core.metrics.StartupStep in project spring-boot by spring-projects.
the class SpringApplicationTests method customApplicationStartupPublishStartupStepsWithFailure.
@Test
void customApplicationStartupPublishStartupStepsWithFailure() {
ApplicationStartup applicationStartup = mock(ApplicationStartup.class);
StartupStep startupStep = mock(StartupStep.class);
given(applicationStartup.start(anyString())).willReturn(startupStep);
given(startupStep.tag(anyString(), anyString())).willReturn(startupStep);
given(startupStep.tag(anyString(), ArgumentMatchers.<Supplier<String>>any())).willReturn(startupStep);
SpringApplication application = new SpringApplication(BrokenPostConstructConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
application.setApplicationStartup(applicationStartup);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(application::run);
then(applicationStartup).should().start("spring.boot.application.starting");
then(applicationStartup).should().start("spring.boot.application.environment-prepared");
then(applicationStartup).should().start("spring.boot.application.failed");
long startCount = mockingDetails(applicationStartup).getInvocations().stream().filter((invocation) -> invocation.getMethod().toString().contains("start(")).count();
long endCount = mockingDetails(startupStep).getInvocations().stream().filter((invocation) -> invocation.getMethod().toString().contains("end(")).count();
assertThat(startCount).isEqualTo(endCount);
}
use of org.springframework.core.metrics.StartupStep in project spring-boot by spring-projects.
the class SpringApplicationTests method customApplicationStartupPublishStartupSteps.
@Test
void customApplicationStartupPublishStartupSteps() {
ApplicationStartup applicationStartup = mock(ApplicationStartup.class);
StartupStep startupStep = mock(StartupStep.class);
given(applicationStartup.start(anyString())).willReturn(startupStep);
given(startupStep.tag(anyString(), anyString())).willReturn(startupStep);
given(startupStep.tag(anyString(), ArgumentMatchers.<Supplier<String>>any())).willReturn(startupStep);
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
application.setApplicationStartup(applicationStartup);
this.context = application.run();
assertThat(this.context.getBean(ApplicationStartup.class)).isEqualTo(applicationStartup);
then(applicationStartup).should().start("spring.boot.application.starting");
then(applicationStartup).should().start("spring.boot.application.environment-prepared");
then(applicationStartup).should().start("spring.boot.application.context-prepared");
then(applicationStartup).should().start("spring.boot.application.context-loaded");
then(applicationStartup).should().start("spring.boot.application.started");
then(applicationStartup).should().start("spring.boot.application.ready");
long startCount = mockingDetails(applicationStartup).getInvocations().stream().filter((invocation) -> invocation.getMethod().toString().contains("start(")).count();
long endCount = mockingDetails(startupStep).getInvocations().stream().filter((invocation) -> invocation.getMethod().toString().contains("end(")).count();
assertThat(startCount).isEqualTo(endCount);
}
use of org.springframework.core.metrics.StartupStep in project spring-boot by spring-projects.
the class BufferingApplicationStartupTests method outOfOrderWithMultipleEndCallsShouldNotFail.
// gh-25792
@Test
void outOfOrderWithMultipleEndCallsShouldNotFail() {
BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(200);
StartupStep one = applicationStartup.start("one");
StartupStep two = applicationStartup.start("two");
StartupStep three = applicationStartup.start("three");
two.end();
two.end();
two.end();
StartupStep four = applicationStartup.start("four");
four.end();
three.end();
one.end();
}
use of org.springframework.core.metrics.StartupStep in project spring-boot by spring-projects.
the class BufferingApplicationStartupTests method taggingShouldFailWhenEventAlreadyRecorded.
@Test
void taggingShouldFailWhenEventAlreadyRecorded() {
BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(2);
StartupStep step = applicationStartup.start("first");
step.end();
assertThatThrownBy(() -> step.tag("name", "value")).isInstanceOf(IllegalStateException.class).hasMessage("StartupStep has already ended.");
}
Aggregations