Search in sources :

Example 6 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class ProbeEndpointsStrategyTest method should_return_detect_endpoints.

@Test
public void should_return_detect_endpoints() {
    // given
    Instance instance = Instance.create(InstanceId.of("id")).register(Registration.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/metrics")).willReturn(ok()));
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/stats")).willReturn(ok()));
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/info")).willReturn(ok()));
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/non-exist")).willReturn(notFound()));
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/error")).willReturn(serverError()));
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/exception")).willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));
    ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy(this.instanceWebClient, new String[] { "metrics:stats", "metrics", "info", "non-exist", "error", "exception" });
    // when
    StepVerifier.create(strategy.detectEndpoints(instance)).expectNext(Endpoints.single("metrics", this.wireMock.url("/mgmt/stats")).withEndpoint("info", // 
    this.wireMock.url("/mgmt/info"))).verifyComplete();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Test(org.junit.jupiter.api.Test)

Example 7 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class ProbeEndpointsStrategyTest method should_return_empty.

@Test
public void should_return_empty() {
    // given
    Instance instance = Instance.create(InstanceId.of("id")).register(Registration.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/stats")).willReturn(aResponse().withStatus(HttpStatus.NOT_FOUND_404)));
    ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy(this.instanceWebClient, new String[] { "metrics:stats" });
    // when
    StepVerifier.create(strategy.detectEndpoints(instance)).verifyComplete();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Test(org.junit.jupiter.api.Test)

Example 8 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class ProbeEndpointsStrategyTest method should_retry.

@Test
public void should_retry() {
    // given
    Instance instance = Instance.create(InstanceId.of("id")).register(Registration.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/metrics")).inScenario("retry").whenScenarioStateIs(STARTED).willReturn(aResponse().withFixedDelay(5000)).willSetStateTo("recovered"));
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/metrics")).inScenario("retry").whenScenarioStateIs("recovered").willReturn(ok()));
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/stats")).willReturn(ok()));
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/info")).willReturn(ok()));
    this.wireMock.stubFor(options(urlEqualTo("/mgmt/non-exist")).willReturn(notFound()));
    ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy(this.instanceWebClient, new String[] { "metrics:stats", "metrics", "info", "non-exist" });
    // when
    StepVerifier.create(strategy.detectEndpoints(instance)).expectNext(Endpoints.single("metrics", this.wireMock.url("/mgmt/stats")).withEndpoint("info", // 
    this.wireMock.url("/mgmt/info"))).verifyComplete();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Test(org.junit.jupiter.api.Test)

Example 9 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class FilteringNotifierTest method test_filter.

@Test
public void test_filter() {
    TestNotifier delegate = new TestNotifier();
    FilteringNotifier notifier = new FilteringNotifier(delegate, repository);
    AbstractNotificationFilter trueFilter = new AbstractNotificationFilter() {

        @Override
        public boolean filter(InstanceEvent event, Instance instance) {
            return true;
        }
    };
    notifier.addFilter(trueFilter);
    StepVerifier.create(notifier.notify(event)).verifyComplete();
    assertThat(delegate.getEvents()).doesNotContain(event);
    notifier.removeFilter(trueFilter.getId());
    StepVerifier.create(notifier.notify(event)).verifyComplete();
    assertThat(delegate.getEvents()).contains(event);
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) TestNotifier(de.codecentric.boot.admin.server.notify.TestNotifier) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) Test(org.junit.jupiter.api.Test)

Example 10 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class EndpointDetectorTest method should_update_endpoints.

@Test
public void should_update_endpoints() {
    // given
    Registration registration = Registration.create("foo", "http://health").managementUrl("http://mgmt").build();
    Instance instance = Instance.create(InstanceId.of("onl")).register(registration).withStatusInfo(StatusInfo.ofUp());
    StepVerifier.create(repository.save(instance)).expectNextCount(1).verifyComplete();
    Instance noActuator = Instance.create(InstanceId.of("noActuator")).register(Registration.create("foo", "http://health").build()).withStatusInfo(StatusInfo.ofUp());
    StepVerifier.create(repository.save(noActuator)).expectNextCount(1).verifyComplete();
    Instance offline = Instance.create(InstanceId.of("off")).register(registration).withStatusInfo(StatusInfo.ofOffline());
    StepVerifier.create(repository.save(offline)).expectNextCount(1).verifyComplete();
    Instance unknown = Instance.create(InstanceId.of("unk")).register(registration).withStatusInfo(StatusInfo.ofUnknown());
    StepVerifier.create(repository.save(unknown)).expectNextCount(1).verifyComplete();
    when(strategy.detectEndpoints(any(Instance.class))).thenReturn(Mono.just(Endpoints.single("id", "url")));
    // when/then
    StepVerifier.create(Flux.from(eventStore).log("FOO", Level.SEVERE)).expectSubscription().then(() -> StepVerifier.create(detector.detectEndpoints(offline.getId())).verifyComplete()).then(() -> StepVerifier.create(detector.detectEndpoints(unknown.getId())).verifyComplete()).then(() -> StepVerifier.create(detector.detectEndpoints(noActuator.getId())).verifyComplete()).expectNoEvent(Duration.ofMillis(100L)).then(() -> StepVerifier.create(detector.detectEndpoints(instance.getId())).verifyComplete()).assertNext((event) -> assertThat(event).isInstanceOf(InstanceEndpointsDetectedEvent.class)).thenCancel().verify();
    StepVerifier.create(repository.find(instance.getId())).assertNext((app) -> assertThat(app.getEndpoints()).isEqualTo(Endpoints.single("id", "url").withEndpoint("health", "http://health"))).verifyComplete();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StepVerifier(reactor.test.StepVerifier) InstanceEndpointsDetectedEvent(de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EndpointDetectionStrategy(de.codecentric.boot.admin.server.services.endpoints.EndpointDetectionStrategy) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) Level(java.util.logging.Level) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Flux(reactor.core.publisher.Flux) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) Duration(java.time.Duration) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) ConcurrentMapEventStore(de.codecentric.boot.admin.server.eventstore.ConcurrentMapEventStore) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) Mockito.mock(org.mockito.Mockito.mock) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) InstanceEndpointsDetectedEvent(de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

Instance (de.codecentric.boot.admin.server.domain.entities.Instance)44 Test (org.junit.jupiter.api.Test)42 Registration (de.codecentric.boot.admin.server.domain.values.Registration)23 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)16 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 StepVerifier (reactor.test.StepVerifier)14 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)13 BeforeEach (org.junit.jupiter.api.BeforeEach)13 Mono (reactor.core.publisher.Mono)10 InstanceRepository (de.codecentric.boot.admin.server.domain.entities.InstanceRepository)9 EventsourcingInstanceRepository (de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository)8 InMemoryEventStore (de.codecentric.boot.admin.server.eventstore.InMemoryEventStore)8 Flux (reactor.core.publisher.Flux)8 ArrayList (java.util.ArrayList)7 Collections.singletonMap (java.util.Collections.singletonMap)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Application (de.codecentric.boot.admin.server.domain.entities.Application)6 Info (de.codecentric.boot.admin.server.domain.values.Info)6 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)6 Mockito.mock (org.mockito.Mockito.mock)6