Search in sources :

Example 1 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_empty_on_error.

@Test
public void should_return_empty_on_error() {
    // 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(get("/mgmt").willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));
    QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
    // 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 2 with Instance

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

the class InfoUpdaterTest method should_clear_info_on_exception.

@Test
public void should_clear_info_on_exception() {
    this.updater = new InfoUpdater(this.repository, InstanceWebClient.builder().build());
    // given
    Instance instance = Instance.create(InstanceId.of("onl")).register(Registration.create("foo", this.wireMock.url("/health")).build()).withEndpoints(Endpoints.single("info", this.wireMock.url("/info"))).withStatusInfo(StatusInfo.ofUp()).withInfo(Info.from(singletonMap("foo", "bar")));
    StepVerifier.create(this.repository.save(instance)).expectNextCount(1).verifyComplete();
    this.wireMock.stubFor(get("/info").willReturn(okJson("{ \"foo\": \"bar\" }").withFixedDelay(1500)));
    // when
    StepVerifier.create(this.eventStore).expectSubscription().then(() -> StepVerifier.create(this.updater.updateInfo(instance.getId())).verifyComplete()).assertNext((event) -> assertThat(event).isInstanceOf(InstanceInfoChangedEvent.class)).thenCancel().verify();
    StepVerifier.create(this.repository.find(instance.getId())).assertNext((app) -> assertThat(app.getInfo()).isEqualTo(Info.empty())).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StepVerifier(reactor.test.StepVerifier) InstanceExchangeFilterFunctions.timeout(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.timeout) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Endpoint(de.codecentric.boot.admin.server.domain.values.Endpoint) WireMock.okJson(com.github.tomakehurst.wiremock.client.WireMock.okJson) Info(de.codecentric.boot.admin.server.domain.values.Info) InstanceExchangeFilterFunctions.rewriteEndpointUrl(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.rewriteEndpointUrl) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) AfterAll(org.junit.jupiter.api.AfterAll) InstanceExchangeFilterFunctions.retry(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.retry) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) WireMock.serverError(com.github.tomakehurst.wiremock.client.WireMock.serverError) Collections.singletonMap(java.util.Collections.singletonMap) InstanceWebClient(de.codecentric.boot.admin.server.web.client.InstanceWebClient) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) Registration(de.codecentric.boot.admin.server.domain.values.Registration) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) Collections.emptyMap(java.util.Collections.emptyMap) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) STARTED(com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED) Options(com.github.tomakehurst.wiremock.core.Options) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) AfterEach(org.junit.jupiter.api.AfterEach) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Test(org.junit.jupiter.api.Test)

Example 3 with Instance

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

the class InfoUpdaterTest method should_clear_info_on_http_error.

@Test
public void should_clear_info_on_http_error() {
    // given
    Instance instance = Instance.create(InstanceId.of("onl")).register(Registration.create("foo", this.wireMock.url("/health")).build()).withEndpoints(Endpoints.single("info", this.wireMock.url("/info"))).withStatusInfo(StatusInfo.ofUp()).withInfo(Info.from(singletonMap("foo", "bar")));
    StepVerifier.create(this.repository.save(instance)).expectNextCount(1).verifyComplete();
    this.wireMock.stubFor(get("/info").willReturn(serverError()));
    // when
    StepVerifier.create(this.eventStore).expectSubscription().then(() -> StepVerifier.create(this.updater.updateInfo(instance.getId())).verifyComplete()).assertNext((event) -> assertThat(event).isInstanceOf(InstanceInfoChangedEvent.class)).thenCancel().verify();
    StepVerifier.create(this.repository.find(instance.getId())).assertNext((app) -> assertThat(app.getInfo()).isEqualTo(Info.empty())).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StepVerifier(reactor.test.StepVerifier) InstanceExchangeFilterFunctions.timeout(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.timeout) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Endpoint(de.codecentric.boot.admin.server.domain.values.Endpoint) WireMock.okJson(com.github.tomakehurst.wiremock.client.WireMock.okJson) Info(de.codecentric.boot.admin.server.domain.values.Info) InstanceExchangeFilterFunctions.rewriteEndpointUrl(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.rewriteEndpointUrl) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) AfterAll(org.junit.jupiter.api.AfterAll) InstanceExchangeFilterFunctions.retry(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.retry) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) WireMock.serverError(com.github.tomakehurst.wiremock.client.WireMock.serverError) Collections.singletonMap(java.util.Collections.singletonMap) InstanceWebClient(de.codecentric.boot.admin.server.web.client.InstanceWebClient) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) Registration(de.codecentric.boot.admin.server.domain.values.Registration) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) Collections.emptyMap(java.util.Collections.emptyMap) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) STARTED(com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED) Options(com.github.tomakehurst.wiremock.core.Options) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) AfterEach(org.junit.jupiter.api.AfterEach) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with Instance

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

the class InfoUpdaterTest method should_update_info_for_online_with_info_endpoint_only.

@Test
public void should_update_info_for_online_with_info_endpoint_only() {
    // given
    Registration registration = Registration.create("foo", this.wireMock.url("/health")).build();
    Instance instance = Instance.create(InstanceId.of("onl")).register(registration).withEndpoints(Endpoints.single("info", this.wireMock.url("/info"))).withStatusInfo(StatusInfo.ofUp());
    StepVerifier.create(this.repository.save(instance)).expectNextCount(1).verifyComplete();
    String body = "{ \"foo\": \"bar\" }";
    this.wireMock.stubFor(get("/info").willReturn(okJson(body).withHeader("Content-Length", Integer.toString(body.length()))));
    Instance noInfo = Instance.create(InstanceId.of("noinfo")).register(registration).withEndpoints(Endpoints.single("beans", this.wireMock.url("/beans"))).withStatusInfo(StatusInfo.ofUp());
    StepVerifier.create(this.repository.save(noInfo)).expectNextCount(1).verifyComplete();
    Instance offline = Instance.create(InstanceId.of("off")).register(registration).withStatusInfo(StatusInfo.ofOffline());
    StepVerifier.create(this.repository.save(offline)).expectNextCount(1).verifyComplete();
    Instance unknown = Instance.create(InstanceId.of("unk")).register(registration).withStatusInfo(StatusInfo.ofUnknown());
    StepVerifier.create(this.repository.save(unknown)).expectNextCount(1).verifyComplete();
    // when
    StepVerifier.create(this.eventStore).expectSubscription().then(() -> StepVerifier.create(this.updater.updateInfo(offline.getId())).verifyComplete()).then(() -> StepVerifier.create(this.updater.updateInfo(unknown.getId())).verifyComplete()).then(() -> StepVerifier.create(this.updater.updateInfo(noInfo.getId())).verifyComplete()).expectNoEvent(Duration.ofMillis(100L)).then(() -> StepVerifier.create(this.updater.updateInfo(instance.getId())).verifyComplete()).assertNext((event) -> assertThat(event).isInstanceOf(InstanceInfoChangedEvent.class)).thenCancel().verify();
    StepVerifier.create(this.repository.find(instance.getId())).assertNext((app) -> assertThat(app.getInfo()).isEqualTo(Info.from(singletonMap("foo", "bar")))).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StepVerifier(reactor.test.StepVerifier) InstanceExchangeFilterFunctions.timeout(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.timeout) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Endpoint(de.codecentric.boot.admin.server.domain.values.Endpoint) WireMock.okJson(com.github.tomakehurst.wiremock.client.WireMock.okJson) Info(de.codecentric.boot.admin.server.domain.values.Info) InstanceExchangeFilterFunctions.rewriteEndpointUrl(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.rewriteEndpointUrl) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) AfterAll(org.junit.jupiter.api.AfterAll) InstanceExchangeFilterFunctions.retry(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.retry) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) WireMock.serverError(com.github.tomakehurst.wiremock.client.WireMock.serverError) Collections.singletonMap(java.util.Collections.singletonMap) InstanceWebClient(de.codecentric.boot.admin.server.web.client.InstanceWebClient) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) Registration(de.codecentric.boot.admin.server.domain.values.Registration) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) Collections.emptyMap(java.util.Collections.emptyMap) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) STARTED(com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED) Options(com.github.tomakehurst.wiremock.core.Options) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) AfterEach(org.junit.jupiter.api.AfterEach) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Test(org.junit.jupiter.api.Test)

Example 5 with Instance

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

the class StatusUpdaterTest method should_change_status_to_down.

@Test
public void should_change_status_to_down() {
    String body = "{ \"status\" : \"UP\", \"details\" : { \"foo\" : \"bar\" } }";
    this.wireMock.stubFor(get("/health").willReturn(okForContentType(ActuatorMediaType.V2_JSON, body).withHeader("Content-Length", Integer.toString(body.length()))));
    StepVerifier.create(this.eventStore).expectSubscription().then(() -> StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete()).assertNext((event) -> {
        assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class);
        assertThat(event.getInstance()).isEqualTo(this.instance.getId());
        InstanceStatusChangedEvent statusChangedEvent = (InstanceStatusChangedEvent) event;
        assertThat(statusChangedEvent.getStatusInfo().getStatus()).isEqualTo("UP");
        assertThat(statusChangedEvent.getStatusInfo().getDetails()).isEqualTo(singletonMap("foo", "bar"));
    }).thenCancel().verify();
    StepVerifier.create(this.repository.find(this.instance.getId())).assertNext((app) -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UP")).verifyComplete();
    StepVerifier.create(this.repository.computeIfPresent(this.instance.getId(), (key, instance) -> Mono.just(instance.deregister()))).then(() -> StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete()).thenCancel().verify();
    StepVerifier.create(this.repository.find(this.instance.getId())).assertNext((app) -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UNKNOWN")).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ActuatorMediaType(org.springframework.boot.actuate.endpoint.http.ActuatorMediaType) StepVerifier(reactor.test.StepVerifier) InstanceExchangeFilterFunctions.timeout(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.timeout) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Endpoint(de.codecentric.boot.admin.server.domain.values.Endpoint) WireMock.okJson(com.github.tomakehurst.wiremock.client.WireMock.okJson) InstanceExchangeFilterFunctions.rewriteEndpointUrl(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.rewriteEndpointUrl) WireMock.ok(com.github.tomakehurst.wiremock.client.WireMock.ok) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) AfterAll(org.junit.jupiter.api.AfterAll) InstanceExchangeFilterFunctions.retry(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.retry) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) Fault(com.github.tomakehurst.wiremock.http.Fault) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) ConcurrentMapEventStore(de.codecentric.boot.admin.server.eventstore.ConcurrentMapEventStore) Collections.singletonMap(java.util.Collections.singletonMap) InstanceWebClient(de.codecentric.boot.admin.server.web.client.InstanceWebClient) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) WireMock.okForContentType(com.github.tomakehurst.wiremock.client.WireMock.okForContentType) Registration(de.codecentric.boot.admin.server.domain.values.Registration) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) Collections.emptyMap(java.util.Collections.emptyMap) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) MediaType(org.springframework.http.MediaType) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) WireMock.status(com.github.tomakehurst.wiremock.client.WireMock.status) Mono(reactor.core.publisher.Mono) STARTED(com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED) Options(com.github.tomakehurst.wiremock.core.Options) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) AfterEach(org.junit.jupiter.api.AfterEach) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) 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