Search in sources :

Example 36 with Instance

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

the class QueryIndexEndpointStrategyTest 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());
    String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"/mgmt/metrics/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"/mgmt/stats\"},\"info\":{\"templated\":false,\"href\":\"/mgmt/info\"}}}";
    this.wireMock.stubFor(get("/mgmt").inScenario("retry").whenScenarioStateIs(STARTED).willReturn(aResponse().withFault(Fault.CONNECTION_RESET_BY_PEER)).willSetStateTo("recovered"));
    this.wireMock.stubFor(get("/mgmt").inScenario("retry").whenScenarioStateIs("recovered").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)));
    QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
    // when
    StepVerifier.create(strategy.detectEndpoints(instance)).expectNext(// 
    Endpoints.single("metrics", "/mgmt/stats").withEndpoint("info", "/mgmt/info")).verifyComplete();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Test(org.junit.jupiter.api.Test)

Example 37 with Instance

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

the class QueryIndexEndpointStrategyTest method should_return_endpoints.

@Test
public void should_return_endpoints() {
    // given
    Instance instance = Instance.create(InstanceId.of("id")).register(Registration.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
    String host = "https://localhost:" + this.wireMock.httpsPort();
    String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"" + host + "/mgmt/metrics/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"" + host + "/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"" + host + "/mgmt/stats\"},\"info\":{\"templated\":false,\"href\":\"" + host + "/mgmt/info\"}}}";
    this.wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)));
    QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
    // when
    StepVerifier.create(strategy.detectEndpoints(instance)).expectNext(// 
    Endpoints.single("metrics", host + "/mgmt/stats").withEndpoint("info", host + "/mgmt/info")).verifyComplete();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Test(org.junit.jupiter.api.Test)

Example 38 with Instance

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

the class ApplicationRegistryTest method getApplications_allRegisteredApplications.

@Test
public void getApplications_allRegisteredApplications() {
    Instance instance1 = getInstance("App1");
    Instance instance2 = getInstance("App2");
    when(this.instanceRegistry.getInstances()).thenReturn(Flux.just(instance1, instance2));
    StepVerifier.create(this.applicationRegistry.getApplications()).recordWith(ArrayList::new).thenConsumeWhile((a) -> true).consumeRecordedWith((applications) -> assertThat(applications.stream().map(Application::getName)).containsExactlyInAnyOrder("App1", "App2")).verifyComplete();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) CsvSource(org.junit.jupiter.params.provider.CsvSource) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Application(de.codecentric.boot.admin.server.domain.entities.Application) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Flux(reactor.core.publisher.Flux) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InstanceEventPublisher(de.codecentric.boot.admin.server.eventstore.InstanceEventPublisher) BuildVersion(de.codecentric.boot.admin.server.domain.values.BuildVersion) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Application(de.codecentric.boot.admin.server.domain.entities.Application) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 39 with Instance

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

the class ApplicationRegistryTest method getApplication_matchingRegisteredApplications.

@Test
public void getApplication_matchingRegisteredApplications() {
    Instance instance = getInstance("App1");
    when(this.instanceRegistry.getInstances("App1")).thenReturn(Flux.just(instance));
    StepVerifier.create(this.applicationRegistry.getApplication("App1")).assertNext((app) -> assertThat(app.getName()).isEqualTo("App1")).verifyComplete();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) CsvSource(org.junit.jupiter.params.provider.CsvSource) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Application(de.codecentric.boot.admin.server.domain.entities.Application) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Flux(reactor.core.publisher.Flux) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InstanceEventPublisher(de.codecentric.boot.admin.server.eventstore.InstanceEventPublisher) BuildVersion(de.codecentric.boot.admin.server.domain.values.BuildVersion) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with Instance

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

the class ApplicationRegistryTest method getStatus.

@ParameterizedTest
@CsvSource({ "UP, UP, UP", "DOWN, DOWN, DOWN", "UNKNOWN, UNKNOWN, UNKNOWN", "UP, DOWN, RESTRICTED", "UP, UNKNOWN, RESTRICTED", "UP, OUT_OF_SERVICE, RESTRICTED", "UP, OFFLINE, RESTRICTED", "UP, RESTRICTED, RESTRICTED", "DOWN, UP, RESTRICTED" })
public void getStatus(String instance1Status, String instance2Status, String expectedApplicationStatus) {
    Instance instance1 = getInstance("App1").withStatusInfo(StatusInfo.valueOf(instance1Status));
    Instance instance2 = getInstance("App1").withStatusInfo(StatusInfo.valueOf(instance2Status));
    when(this.instanceRegistry.getInstances()).thenReturn(Flux.just(instance1, instance2));
    StepVerifier.create(this.applicationRegistry.getApplications()).recordWith(ArrayList::new).thenConsumeWhile((a) -> true).consumeRecordedWith((applications) -> assertThat(applications.stream().map(Application::getStatus)).containsExactly(expectedApplicationStatus)).verifyComplete();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) CsvSource(org.junit.jupiter.params.provider.CsvSource) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Application(de.codecentric.boot.admin.server.domain.entities.Application) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Flux(reactor.core.publisher.Flux) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InstanceEventPublisher(de.codecentric.boot.admin.server.eventstore.InstanceEventPublisher) BuildVersion(de.codecentric.boot.admin.server.domain.values.BuildVersion) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Application(de.codecentric.boot.admin.server.domain.entities.Application) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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