Search in sources :

Example 6 with InstanceRegisteredEvent

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();
}
Also used : JSONObject(org.json.JSONObject) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 7 with InstanceRegisteredEvent

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));
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Test(org.junit.jupiter.api.Test)

Example 8 with InstanceRegisteredEvent

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();
}
Also used : InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 9 with InstanceRegisteredEvent

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);
}
Also used : InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 10 with InstanceRegisteredEvent

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();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)22 Test (org.junit.jupiter.api.Test)20 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)5 Registration (de.codecentric.boot.admin.server.domain.values.Registration)5 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)4 InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)4 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)4 Instant (java.time.Instant)4 JSONObject (org.json.JSONObject)3 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)2 HttpEntity (org.springframework.http.HttpEntity)2 InstanceEndpointsDetectedEvent (de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent)1 InstanceInfoChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent)1 InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)1 Endpoints (de.codecentric.boot.admin.server.domain.values.Endpoints)1 Info (de.codecentric.boot.admin.server.domain.values.Info)1 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)1 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)1 HttpHeaders (org.springframework.http.HttpHeaders)1