Search in sources :

Example 1 with STARTED

use of com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED in project spring-boot-admin by codecentric.

the class InfoUpdaterTest method should_retry.

@Test
public void should_retry() {
    // 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();
    this.wireMock.stubFor(get("/info").inScenario("retry").whenScenarioStateIs(STARTED).willReturn(aResponse().withFixedDelay(5000)).willSetStateTo("recovered"));
    String body = "{ \"foo\": \"bar\" }";
    this.wireMock.stubFor(get("/info").inScenario("retry").whenScenarioStateIs("recovered").willReturn(okJson(body).withHeader("Content-Length", Integer.toString(body.length()))));
    // 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.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)

Aggregations

WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMock.get (com.github.tomakehurst.wiremock.client.WireMock.get)1 WireMock.okJson (com.github.tomakehurst.wiremock.client.WireMock.okJson)1 WireMock.serverError (com.github.tomakehurst.wiremock.client.WireMock.serverError)1 Options (com.github.tomakehurst.wiremock.core.Options)1 STARTED (com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED)1 EventsourcingInstanceRepository (de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository)1 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)1 InstanceRepository (de.codecentric.boot.admin.server.domain.entities.InstanceRepository)1 InstanceInfoChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent)1 Endpoint (de.codecentric.boot.admin.server.domain.values.Endpoint)1 Endpoints (de.codecentric.boot.admin.server.domain.values.Endpoints)1 Info (de.codecentric.boot.admin.server.domain.values.Info)1 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)1 Registration (de.codecentric.boot.admin.server.domain.values.Registration)1 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)1 InMemoryEventStore (de.codecentric.boot.admin.server.eventstore.InMemoryEventStore)1 InstanceExchangeFilterFunctions.retry (de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.retry)1 InstanceExchangeFilterFunctions.rewriteEndpointUrl (de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.rewriteEndpointUrl)1