de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent Java Examples
The following examples show how to use
de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PagerdutyNotifierTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_resolve() { StepVerifier.create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion() + 1, StatusInfo.ofDown()))) .verifyComplete(); reset(restTemplate); StatusInfo up = StatusInfo.ofUp(); when(repository.find(INSTANCE.getId())).thenReturn(Mono.just(INSTANCE.withStatusInfo(up))); StepVerifier .create(notifier .notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion() + 2, up))) .verifyComplete(); Map<String, Object> expected = new HashMap<>(); expected.put("service_key", "--service--"); expected.put("incident_key", "App/-id-"); expected.put("event_type", "resolve"); expected.put("description", "App/-id- is UP"); Map<String, Object> details = new HashMap<>(); details.put("from", "DOWN"); details.put("to", up); expected.put("details", details); verify(restTemplate).postForEntity(eq(PagerdutyNotifier.DEFAULT_URI), eq(expected), eq(Void.class)); }
Example #2
Source File: SlackNotifierTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_trigger() { notifier.setChannel(channel); notifier.setIcon(icon); StepVerifier.create( notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofUp()))) .verifyComplete(); clearInvocations(restTemplate); StepVerifier.create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofDown()))) .verifyComplete(); Object expected = expectedMessage("danger", user, icon, channel, standardMessage("DOWN")); verify(restTemplate).postForEntity(any(URI.class), eq(expected), eq(Void.class)); }
Example #3
Source File: SlackNotifierTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_resolve_with_given_message() { notifier.setMessage(message); notifier.setChannel(channel); notifier.setIcon(icon); StepVerifier.create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofDown()))) .verifyComplete(); clearInvocations(restTemplate); StepVerifier.create( notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofUp()))) .verifyComplete(); Object expected = expectedMessage("good", user, icon, channel, message); verify(restTemplate).postForEntity(any(URI.class), eq(expected), eq(Void.class)); }
Example #4
Source File: SlackNotifierTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_resolve_without_channel_and_icon() { StepVerifier .create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofDown()))) .verifyComplete(); clearInvocations(restTemplate); StepVerifier .create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofUp()))) .verifyComplete(); Object expected = expectedMessage("good", user, null, null, standardMessage("UP")); verify(restTemplate).postForEntity(any(URI.class), eq(expected), eq(Void.class)); }
Example #5
Source File: StatusUpdaterTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void should_change_status_to_down_with_details() { String body = "{ \"foo\" : \"bar\" }"; this.wireMock.stubFor( get("/health").willReturn(status(503).withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) .withHeader("Content-Length", Integer.toString(body.length())).withBody(body))); StepVerifier.create(this.eventStore).expectSubscription() .then(() -> StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete()) .assertNext((event) -> assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class)).thenCancel() .verify(); StepVerifier.create(this.repository.find(this.instance.getId())).assertNext((app) -> { assertThat(app.getStatusInfo().getStatus()).isEqualTo("DOWN"); assertThat(app.getStatusInfo().getDetails()).containsEntry("foo", "bar"); }).verifyComplete(); }
Example #6
Source File: DiscordNotifierTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_resolve_minimum_configuration() { StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofDown() ))).verifyComplete(); clearInvocations(restTemplate); StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofUp() ))).verifyComplete(); Object expected = expectedMessage(null, false, null, standardMessage("UP")); verify(restTemplate).postForEntity(eq(webhookUri), eq(expected), eq(Void.class)); }
Example #7
Source File: InstanceStatusChangedEventMixinTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void verifyDeserializeWithOnlyRequiredProperties() throws JSONException, JsonProcessingException { String json = new JSONObject().put("instance", "test123").put("timestamp", 1587751031.000000000) .put("type", "STATUS_CHANGED").put("statusInfo", new JSONObject().put("status", "OFFLINE")).toString(); InstanceStatusChangedEvent event = objectMapper.readValue(json, InstanceStatusChangedEvent.class); assertThat(event).isNotNull(); assertThat(event.getInstance()).isEqualTo(InstanceId.of("test123")); assertThat(event.getVersion()).isEqualTo(0L); assertThat(event.getTimestamp()).isEqualTo(Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS)); StatusInfo statusInfo = event.getStatusInfo(); assertThat(statusInfo).isNotNull(); assertThat(statusInfo.getStatus()).isEqualTo("OFFLINE"); assertThat(statusInfo.getDetails()).isEmpty(); }
Example #8
Source File: OpsGenieNotifierTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_resolve() { StepVerifier.create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion() + 1, StatusInfo.ofDown()))) .verifyComplete(); reset(restTemplate); when(repository.find(INSTANCE.getId())).thenReturn(Mono.just(INSTANCE.withStatusInfo(StatusInfo.ofUp()))); StepVerifier .create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion() + 2, StatusInfo.ofUp()))) .verifyComplete(); verify(restTemplate).exchange(eq("https://api.opsgenie.com/v2/alerts/App_-id-/close"), eq(HttpMethod.POST), eq(expectedRequest("DOWN", "UP")), eq(Void.class)); }
Example #9
Source File: SlackNotifierTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_trigger() { notifier.setChannel(channel); notifier.setIcon(icon); StepVerifier .create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofUp()))) .verifyComplete(); clearInvocations(restTemplate); StepVerifier .create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofDown()))) .verifyComplete(); Object expected = expectedMessage("danger", user, icon, channel, standardMessage("DOWN")); verify(restTemplate).postForEntity(any(URI.class), eq(expected), eq(Void.class)); }
Example #10
Source File: LetsChatNotifierTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_resolve_with_custom_message() { notifier.setMessage("TEST"); StepVerifier.create(notifier.notify( new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofDown()))) .verifyComplete(); clearInvocations(restTemplate); StepVerifier.create( notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofUp()))) .verifyComplete(); HttpEntity<?> expected = expectedMessage("TEST"); verify(restTemplate).exchange(eq(URI.create(String.format("%s/rooms/%s/messages", host, room))), eq(HttpMethod.POST), eq(expected), eq(Void.class)); }
Example #11
Source File: MailNotifierTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void should_send_mail_using_custom_template_with_additional_properties() throws IOException, MessagingException { notifier.setTemplate("/de/codecentric/boot/admin/server/notify/custom-mail.html"); notifier.getAdditionalProperties().put("customProperty", "HELLO WORLD!"); StepVerifier .create(notifier.notify( new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofDown()))) .verifyComplete(); ArgumentCaptor<MimeMessage> mailCaptor = ArgumentCaptor.forClass(MimeMessage.class); verify(sender).send(mailCaptor.capture()); MimeMessage mail = mailCaptor.getValue(); String body = extractBody(mail.getDataHandler()); assertThat(body).isEqualTo(loadExpectedBody("expected-custom-mail")); }
Example #12
Source File: MailNotifierTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void should_send_mail_using_default_template() throws IOException, MessagingException { Map<String, Object> details = new HashMap<>(); details.put("Simple Value", 1234); details.put("Complex Value", singletonMap("Nested Simple Value", "99!")); StepVerifier.create(notifier.notify( new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofDown(details)))) .verifyComplete(); ArgumentCaptor<MimeMessage> mailCaptor = ArgumentCaptor.forClass(MimeMessage.class); verify(sender).send(mailCaptor.capture()); MimeMessage mail = mailCaptor.getValue(); assertThat(mail.getSubject()).isEqualTo("application-name (cafebabe) is DOWN"); assertThat(mail.getRecipients(Message.RecipientType.TO)).containsExactly(new InternetAddress("[email protected]")); assertThat(mail.getRecipients(Message.RecipientType.CC)).containsExactly(new InternetAddress("[email protected]")); assertThat(mail.getFrom()).containsExactly(new InternetAddress("SBA <[email protected]>")); assertThat(mail.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8"); String body = extractBody(mail.getDataHandler()); assertThat(body).isEqualTo(loadExpectedBody("expected-default-mail")); }
Example #13
Source File: MicrosoftTeamsNotifierTest.java From Moss with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void test_onApplicationStatusChangedEvent_resolve() { InstanceStatusChangedEvent event = new InstanceStatusChangedEvent(instance.getId(), 1L, StatusInfo.ofUp()); StepVerifier.create(notifier.doNotify(event, instance)).verifyComplete(); ArgumentCaptor<HttpEntity<Message>> entity = ArgumentCaptor.forClass(HttpEntity.class); verify(mockRestTemplate).postForEntity(eq(URI.create("http://example.com")), entity.capture(), eq(Void.class)); assertThat(entity.getValue().getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON); assertMessage(entity.getValue().getBody(), notifier.getStatusChangedTitle(), notifier.getMessageSummary(), String.format(notifier.getStatusActivitySubtitlePattern(), instance.getRegistration().getName(), instance.getId(), StatusInfo.ofUnknown().getStatus(), StatusInfo.ofUp().getStatus() ) ); }
Example #14
Source File: SlackNotifierTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_resolve_with_given_user() { String anotherUser = "another user"; notifier.setUsername(anotherUser); notifier.setChannel(channel); notifier.setIcon(icon); StepVerifier.create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofDown()))) .verifyComplete(); clearInvocations(restTemplate); StepVerifier.create( notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofUp()))) .verifyComplete(); Object expected = expectedMessage("good", anotherUser, icon, channel, standardMessage("UP")); verify(restTemplate).postForEntity(any(URI.class), eq(expected), eq(Void.class)); }
Example #15
Source File: StatusUpdaterTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void should_change_status_to_offline() { this.wireMock.stubFor(get("/health").willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); StepVerifier.create(this.eventStore).expectSubscription() .then(() -> StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete()) .assertNext((event) -> assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class)).thenCancel() .verify(); StepVerifier.create(this.repository.find(this.instance.getId())).assertNext((app) -> { assertThat(app.getStatusInfo().getStatus()).isEqualTo("OFFLINE"); assertThat(app.getStatusInfo().getDetails()).containsKeys("message", "exception"); }).verifyComplete(); StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete(); }
Example #16
Source File: DiscordNotifierTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_resolve() { notifier.setUsername(username); notifier.setAvatarUrl(avatarUrl); notifier.setTts(true); StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofDown() ))).verifyComplete(); clearInvocations(restTemplate); StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofUp() ))).verifyComplete(); Object expected = expectedMessage(username, true, avatarUrl, standardMessage("UP")); verify(restTemplate).postForEntity(eq(webhookUri), eq(expected), eq(Void.class)); }
Example #17
Source File: StatusUpdaterTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_change_status_to_down_with_details() { String body = "{ \"foo\" : \"bar\" }"; wireMock.stubFor(get("/health").willReturn(status(503).withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE ) .withHeader( "Content-Length", Integer.toString(body.length()) ) .withBody(body))); StepVerifier.create(eventStore) .expectSubscription() .then(() -> StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete()) .assertNext(event -> assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class)) .thenCancel() .verify(); StepVerifier.create(repository.find(instance.getId())).assertNext(app -> { assertThat(app.getStatusInfo().getStatus()).isEqualTo("DOWN"); assertThat(app.getStatusInfo().getDetails()).containsEntry("foo", "bar"); }).verifyComplete(); }
Example #18
Source File: StatusUpdaterTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_change_status_to_down_without_details_incompatible_content_type() { wireMock.stubFor(get("/health").willReturn(status(503))); StepVerifier.create(eventStore) .expectSubscription() .then(() -> StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete()) .assertNext(event -> assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class)) .thenCancel() .verify(); StepVerifier.create(repository.find(instance.getId())).assertNext(app -> { assertThat(app.getStatusInfo().getStatus()).isEqualTo("DOWN"); assertThat(app.getStatusInfo().getDetails()).containsEntry("status", 503) .containsEntry("error", "Service Unavailable"); }).verifyComplete(); }
Example #19
Source File: StatusUpdaterTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_change_status_to_down_without_details_no_body() { wireMock.stubFor(get("/health").willReturn(status(503).withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE ))); StepVerifier.create(eventStore) .expectSubscription() .then(() -> StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete()) .assertNext(event -> assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class)) .thenCancel() .verify(); StepVerifier.create(repository.find(instance.getId())).assertNext(app -> { assertThat(app.getStatusInfo().getStatus()).isEqualTo("DOWN"); assertThat(app.getStatusInfo().getDetails()).containsEntry("status", 503) .containsEntry("error", "Service Unavailable"); }).verifyComplete(); }
Example #20
Source File: StatusUpdaterTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_change_status_to_offline() { wireMock.stubFor(get("/health").willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); StepVerifier.create(eventStore) .expectSubscription() .then(() -> StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete()) .assertNext(event -> assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class)) .thenCancel() .verify(); 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(); }
Example #21
Source File: StatusUpdaterTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_retry() { wireMock.stubFor(get("/health").inScenario("retry") .whenScenarioStateIs(STARTED) .willReturn(aResponse().withFixedDelay(5000)) .willSetStateTo("recovered")); wireMock.stubFor(get("/health").inScenario("retry").whenScenarioStateIs("recovered").willReturn(ok())); StepVerifier.create(eventStore) .expectSubscription() .then(() -> StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete()) .assertNext(event -> assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class)) .thenCancel() .verify(); StepVerifier.create(repository.find(instance.getId())) .assertNext(app -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UP")) .verifyComplete(); }
Example #22
Source File: DiscordNotifierTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_resolve() { notifier.setUsername(username); notifier.setAvatarUrl(avatarUrl); notifier.setTts(true); StepVerifier .create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofDown()))) .verifyComplete(); clearInvocations(restTemplate); StepVerifier .create(notifier.notify( new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofUp()))) .verifyComplete(); Object expected = expectedMessage(username, true, avatarUrl, standardMessage("UP")); verify(restTemplate).postForEntity(eq(webhookUri), eq(expected), eq(Void.class)); }
Example #23
Source File: TelegramNotifierTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_resolve() { StepVerifier .create(notifier.notify( new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofDown()))) .verifyComplete(); clearInvocations(restTemplate); StepVerifier .create(notifier.notify( new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofUp()))) .verifyComplete(); verify(restTemplate).getForObject( eq("https://telegram.com/bot--token-/sendmessage?chat_id={chat_id}&text={text}" + "&parse_mode={parse_mode}&disable_notification={disable_notification}"), eq(Void.class), eq(getParameters("UP"))); }
Example #24
Source File: HipchatNotifierTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_trigger() { StatusInfo infoDown = StatusInfo.ofDown(); @SuppressWarnings("unchecked") ArgumentCaptor<HttpEntity<Map<String, Object>>> httpRequest = ArgumentCaptor.forClass( (Class<HttpEntity<Map<String, Object>>>) (Class<?>) HttpEntity.class); when(restTemplate.postForEntity(isA(String.class), httpRequest.capture(), eq(Void.class))).thenReturn( ResponseEntity.ok().build()); StepVerifier.create( notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofUp()))) .verifyComplete(); StepVerifier.create( notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), infoDown))) .verifyComplete(); assertThat(httpRequest.getValue(). getHeaders()).containsEntry("Content-Type", Collections.singletonList("application/json")); Map<String, Object> body = httpRequest.getValue().getBody(); assertThat(body).containsEntry("color", "red"); assertThat(body).containsEntry("message", "<strong>App</strong>/-id- is <strong>DOWN</strong>"); assertThat(body).containsEntry("notify", Boolean.TRUE); assertThat(body).containsEntry("message_format", "html"); }
Example #25
Source File: TelegramNotifierTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void test_onApplicationEvent_resolve() { StepVerifier.create(notifier.notify( new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofDown()))) .verifyComplete(); clearInvocations(restTemplate); StepVerifier.create( notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofUp()))) .verifyComplete(); verify(restTemplate).getForObject( eq("https://telegram.com/bot--token-/sendmessage?chat_id={chat_id}&text={text}" + "&parse_mode={parse_mode}&disable_notification={disable_notification}"), eq(Void.class), eq(getParameters("UP"))); }
Example #26
Source File: MailNotifierTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_send_mail_using_custom_template_with_additional_properties() throws IOException, MessagingException { notifier.setTemplate("/de/codecentric/boot/admin/server/notify/custom-mail.html"); notifier.getAdditionalProperties().put("customProperty", "HELLO WORLD!"); StepVerifier.create(notifier.notify( new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofDown()))) .verifyComplete(); ArgumentCaptor<MimeMessage> mailCaptor = ArgumentCaptor.forClass(MimeMessage.class); verify(sender).send(mailCaptor.capture()); MimeMessage mail = mailCaptor.getValue(); String body = extractBody(mail.getDataHandler()); assertThat(body).isEqualTo(loadExpectedBody("expected-custom-mail")); }
Example #27
Source File: NotificationTriggerTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_notify_on_event() throws InterruptedException { //given Notifier notifier = mock(Notifier.class); TestPublisher<InstanceEvent> events = TestPublisher.create(); NotificationTrigger trigger = new NotificationTrigger(notifier, events); trigger.start(); Thread.sleep(500L); //wait for subscription //when registered event is emitted InstanceStatusChangedEvent event = new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofDown()); events.next(event); //then should notify verify(notifier, times(1)).notify(event); //when registered event is emitted but the trigger has been stopped trigger.stop(); clearInvocations(notifier); events.next(new InstanceRegisteredEvent(instance.getId(), instance.getVersion(), instance.getRegistration())); //then should not notify verify(notifier, never()).notify(event); }
Example #28
Source File: StatusUpdaterTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void should_change_status_to_down_without_details_no_body() { this.wireMock.stubFor( get("/health").willReturn(status(503).withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE))); StepVerifier.create(this.eventStore).expectSubscription() .then(() -> StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete()) .assertNext((event) -> assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class)).thenCancel() .verify(); StepVerifier.create(this.repository.find(this.instance.getId())).assertNext((app) -> { assertThat(app.getStatusInfo().getStatus()).isEqualTo("DOWN"); assertThat(app.getStatusInfo().getDetails()).containsEntry("status", 503).containsEntry("error", "Service Unavailable"); }).verifyComplete(); }
Example #29
Source File: RemindingNotifier.java From spring-boot-admin with Apache License 2.0 | 5 votes |
protected boolean shouldStartReminder(InstanceEvent event) { if (event instanceof InstanceStatusChangedEvent) { return Arrays.binarySearch(this.reminderStatuses, ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus()) >= 0; } return false; }
Example #30
Source File: HazelcastNotificationTriggerTest.java From spring-boot-admin with Apache License 2.0 | 5 votes |
@Test void should_trigger_notifications() { // given then notifier has subscribed to the events and no notification was sent // before this.sentNotifications.clear(); this.trigger.start(); await().until(this.events::wasSubscribed); // when registered event is emitted InstanceStatusChangedEvent event = new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofDown()); this.events.next(event); // then should notify verify(this.notifier, times(1)).notify(event); }