Commit 65b95047 by Thomas Bosch Committed by Johannes Edmeier

Polish test

parent b7aa64ee
......@@ -25,6 +25,7 @@ import de.codecentric.boot.admin.server.domain.values.Registration;
import de.codecentric.boot.admin.server.eventstore.ConcurrentMapEventStore;
import de.codecentric.boot.admin.server.eventstore.InMemoryEventStore;
import de.codecentric.boot.admin.server.web.client.InstanceWebClient;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import java.time.Duration;
......@@ -36,8 +37,10 @@ import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import com.github.tomakehurst.wiremock.core.Options;
import com.github.tomakehurst.wiremock.http.Fault;
import com.github.tomakehurst.wiremock.junit.WireMockClassRule;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.ok;
import static com.github.tomakehurst.wiremock.client.WireMock.okForContentType;
......@@ -66,7 +69,7 @@ public class StatusUpdaterTest {
StepVerifier.create(repository.save(instance)).expectNextCount(1).verifyComplete();
updater = new StatusUpdater(repository,
new InstanceWebClient(instance -> HttpHeaders.EMPTY, Duration.ofSeconds(5), Duration.ofSeconds(20)));
new InstanceWebClient(instance -> HttpHeaders.EMPTY, Duration.ofSeconds(5), Duration.ofSeconds(10)));
}
@Test
......@@ -93,6 +96,16 @@ public class StatusUpdaterTest {
StepVerifier.create(repository.find(instance.getId()))
.assertNext(app -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UP"))
.verifyComplete();
StepVerifier.create(
repository.computeIfPresent(instance.getId(), (key, instance) -> Mono.just(instance.deregister())))
.then(() -> StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete())
.thenCancel()
.verify();
StepVerifier.create(repository.find(instance.getId()))
.assertNext(app -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UNKNOWN"))
.verifyComplete();
}
@Test
......@@ -168,21 +181,20 @@ public class StatusUpdaterTest {
@Test
public void test_update_offline() {
Instance offlineInstance = Instance.create(InstanceId.of("offline"))
.register(Registration.create("foo", "http://0.0.0.0/health").build());
StepVerifier.create(repository.save(offlineInstance)).expectNextCount(1).verifyComplete();
wireMock.stubFor(get("/health").willReturn(aResponse().withFault(Fault.CONNECTION_RESET_BY_PEER)));
StepVerifier.create(eventStore)
.expectSubscription()
.then(() -> StepVerifier.create(updater.updateStatus(offlineInstance.getId())).verifyComplete())
.then(() -> StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete())
.assertNext(event -> assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class))
.thenCancel()
.verify();
StepVerifier.create(repository.find(offlineInstance.getId())).assertNext(app -> {
StepVerifier.create(repository.find(instance.getId())).assertNext(app -> {
assertThat(app.getStatusInfo().getStatus()).isEqualTo("OFFLINE");
assertThat(app.getStatusInfo().getDetails()).containsKeys("message", "exception");
}).verifyComplete();
StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment