Search in sources :

Example 1 with TimelineEvent

use of org.springframework.boot.context.metrics.buffering.StartupTimeline.TimelineEvent 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 2 with TimelineEvent

use of org.springframework.boot.context.metrics.buffering.StartupTimeline.TimelineEvent in project spring-boot by spring-projects.

the class BufferingApplicationStartup method record.

private void record(BufferedStartupStep step) {
    if (this.filter.test(step) && this.estimatedSize.get() < this.capacity) {
        this.estimatedSize.incrementAndGet();
        this.events.add(new TimelineEvent(step, this.clock.instant()));
    }
    while (true) {
        BufferedStartupStep current = this.current.get();
        BufferedStartupStep next = getLatestActive(current);
        if (this.current.compareAndSet(current, next)) {
            return;
        }
    }
}
Also used : TimelineEvent(org.springframework.boot.context.metrics.buffering.StartupTimeline.TimelineEvent)

Aggregations

TimelineEvent (org.springframework.boot.context.metrics.buffering.StartupTimeline.TimelineEvent)2 Test (org.junit.jupiter.api.Test)1 StartupStep (org.springframework.core.metrics.StartupStep)1