use of de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent in project spring-boot-admin by codecentric.
the class InstanceRegisteredEventMixinTest method verifyDeserializeWithOnlyRequiredProperties.
@Test
public void verifyDeserializeWithOnlyRequiredProperties() throws JSONException, JsonProcessingException {
String json = new JSONObject().put("instance", "test123").put("timestamp", 1587751031.000000000).put("type", "REGISTERED").put("registration", new JSONObject().put("name", "test").put("healthUrl", "http://localhost:9080/heath")).toString();
InstanceRegisteredEvent event = objectMapper.readValue(json, InstanceRegisteredEvent.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));
Registration registration = event.getRegistration();
assertThat(registration).isNotNull();
assertThat(registration.getName()).isEqualTo("test");
assertThat(registration.getManagementUrl()).isNull();
assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:9080/heath");
assertThat(registration.getServiceUrl()).isNull();
assertThat(registration.getSource()).isNull();
assertThat(registration.getMetadata()).isEmpty();
}
use of de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent in project spring-boot-admin by codecentric.
the class StatusUpdateTriggerTest method should_start_and_stop_monitor.
@Test
public void should_start_and_stop_monitor() throws Exception {
// given
this.trigger.stop();
this.trigger.setInterval(Duration.ofMillis(10));
this.trigger.setLifetime(Duration.ofMillis(10));
this.trigger.start();
await().until(this.events::wasSubscribed);
this.events.next(new InstanceRegisteredEvent(this.instance.getId(), 0L, this.instance.getRegistration()));
Thread.sleep(50L);
// then it should start updating one time for registration and at least once for
// monitor
verify(this.updater, atLeast(2)).updateStatus(this.instance.getId());
// given long lifetime
this.trigger.setLifetime(Duration.ofSeconds(10));
Thread.sleep(50L);
clearInvocations(this.updater);
// when the lifetime is not expired
Thread.sleep(50L);
// should never update
verify(this.updater, never()).updateStatus(any(InstanceId.class));
// when trigger ist destroyed
this.trigger.setLifetime(Duration.ofMillis(10));
this.trigger.stop();
clearInvocations(this.updater);
Thread.sleep(15L);
// it should stop updating
verify(this.updater, never()).updateStatus(any(InstanceId.class));
}
use of de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent in project spring-boot-admin by codecentric.
the class AbstractEventStoreTest method should_shorten_log_on_exceeded_capacity.
@Test
public void should_shorten_log_on_exceeded_capacity() {
InstanceEventStore store = createStore(2);
InstanceEvent event1 = new InstanceRegisteredEvent(id, 0L, registration);
InstanceEvent event2 = new InstanceStatusChangedEvent(id, 1L, StatusInfo.ofDown());
InstanceEvent event3 = new InstanceStatusChangedEvent(id, 2L, StatusInfo.ofUp());
StepVerifier.create(store.append(asList(event1, event2, event3))).verifyComplete();
StepVerifier.create(store.findAll()).expectNext(event1, event3).verifyComplete();
}
use of de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent in project spring-boot-admin by codecentric.
the class NotificationTriggerTest method should_notify_on_event.
@Test
public void should_notify_on_event() throws InterruptedException {
// given the notifier subscribed to the events
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);
// when registered event is emitted but the trigger has been stopped
this.trigger.stop();
clearInvocations(this.notifier);
this.events.next(new InstanceRegisteredEvent(this.instance.getId(), this.instance.getVersion(), this.instance.getRegistration()));
// then should not notify
verify(this.notifier, never()).notify(event);
}
use of de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent in project spring-boot-admin by codecentric.
the class InstanceIdNotificationFilterTest method test_filterByName.
@Test
public void test_filterByName() {
NotificationFilter filter = new InstanceIdNotificationFilter(InstanceId.of("cafebabe"), null);
Instance filteredInstance = Instance.create(InstanceId.of("cafebabe")).register(Registration.create("foo", "http://health").build());
InstanceRegisteredEvent filteredEvent = new InstanceRegisteredEvent(filteredInstance.getId(), filteredInstance.getVersion(), filteredInstance.getRegistration());
assertThat(filter.filter(filteredEvent, filteredInstance)).isTrue();
Instance ignoredInstance = Instance.create(InstanceId.of("-")).register(Registration.create("foo", "http://health").build());
InstanceRegisteredEvent ignoredEvent = new InstanceRegisteredEvent(ignoredInstance.getId(), ignoredInstance.getVersion(), ignoredInstance.getRegistration());
assertThat(filter.filter(ignoredEvent, ignoredInstance)).isFalse();
}
Aggregations