Search in sources :

Example 1 with InstanceInfoChangedEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent in project spring-boot-admin by codecentric.

the class InfoUpdateTriggerTest method should_not_update_on_non_relevant_event.

@Test
public void should_not_update_on_non_relevant_event() {
    // when some non-registered event is emitted
    this.events.next(new InstanceInfoChangedEvent(this.instance.getId(), this.instance.getVersion(), Info.empty()));
    // then should not update
    verify(this.updater, never()).updateInfo(this.instance.getId());
}
Also used : InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Test(org.junit.jupiter.api.Test)

Example 2 with InstanceInfoChangedEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent in project spring-boot-admin by codecentric.

the class InstanceInfoChangedEventMixinTest method verifyDeserializeWithEmptyInfo.

@Test
public void verifyDeserializeWithEmptyInfo() throws JSONException, JsonProcessingException {
    String json = new JSONObject().put("instance", "test123").put("version", 12345678L).put("timestamp", 1587751031.000000000).put("type", "INFO_CHANGED").put("info", new JSONObject()).toString();
    InstanceInfoChangedEvent event = objectMapper.readValue(json, InstanceInfoChangedEvent.class);
    assertThat(event).isNotNull();
    assertThat(event.getInstance()).isEqualTo(InstanceId.of("test123"));
    assertThat(event.getVersion()).isEqualTo(12345678L);
    assertThat(event.getTimestamp()).isEqualTo(Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS));
    Info info = event.getInfo();
    assertThat(info).isNotNull();
    assertThat(info.getValues()).isEmpty();
}
Also used : JSONObject(org.json.JSONObject) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Info(de.codecentric.boot.admin.server.domain.values.Info) Test(org.junit.jupiter.api.Test)

Example 3 with InstanceInfoChangedEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent in project spring-boot-admin by codecentric.

the class InstanceInfoChangedEventMixinTest method verifySerialize.

@Test
public void verifySerialize() throws IOException {
    InstanceId id = InstanceId.of("test123");
    Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
    Map<String, Object> data = new HashMap<>();
    data.put("build", Collections.singletonMap("version", "1.0.0"));
    data.put("foo", "bar");
    InstanceInfoChangedEvent event = new InstanceInfoChangedEvent(id, 12345678L, timestamp, Info.from(data));
    JsonContent<InstanceInfoChangedEvent> jsonContent = jsonTester.write(event);
    assertThat(jsonContent).extractingJsonPathStringValue("$.instance").isEqualTo("test123");
    assertThat(jsonContent).extractingJsonPathNumberValue("$.version").isEqualTo(12345678);
    assertThat(jsonContent).extractingJsonPathNumberValue("$.timestamp").isEqualTo(1587751031.000000000);
    assertThat(jsonContent).extractingJsonPathStringValue("$.type").isEqualTo("INFO_CHANGED");
    assertThat(jsonContent).extractingJsonPathMapValue("$.info").containsOnlyKeys("build", "foo");
    assertThat(jsonContent).extractingJsonPathStringValue("$.info['build'].['version']").isEqualTo("1.0.0");
    assertThat(jsonContent).extractingJsonPathStringValue("$.info['foo']").isEqualTo("bar");
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) HashMap(java.util.HashMap) Instant(java.time.Instant) JSONObject(org.json.JSONObject) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with InstanceInfoChangedEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent in project spring-boot-admin by codecentric.

the class Instance method apply.

private Instance apply(InstanceEvent event, boolean isNewEvent) {
    Assert.notNull(event, "'event' must not be null");
    Assert.isTrue(this.id.equals(event.getInstance()), "'event' must refer the same instance");
    Assert.isTrue(event.getVersion() >= this.nextVersion(), () -> "Event " + event.getVersion() + " must be greater or equal to " + this.nextVersion());
    List<InstanceEvent> unsavedEvents = appendToEvents(event, isNewEvent);
    if (event instanceof InstanceRegisteredEvent) {
        Registration registration = ((InstanceRegisteredEvent) event).getRegistration();
        return new Instance(this.id, event.getVersion(), registration, true, StatusInfo.ofUnknown(), event.getTimestamp(), Info.empty(), Endpoints.empty(), updateBuildVersion(registration.getMetadata()), updateTags(registration.getMetadata()), unsavedEvents);
    } else if (event instanceof InstanceRegistrationUpdatedEvent) {
        Registration registration = ((InstanceRegistrationUpdatedEvent) event).getRegistration();
        return new Instance(this.id, event.getVersion(), registration, this.registered, this.statusInfo, this.statusTimestamp, this.info, this.endpoints, updateBuildVersion(registration.getMetadata(), this.info.getValues()), updateTags(registration.getMetadata(), this.info.getValues()), unsavedEvents);
    } else if (event instanceof InstanceStatusChangedEvent) {
        StatusInfo statusInfo = ((InstanceStatusChangedEvent) event).getStatusInfo();
        return new Instance(this.id, event.getVersion(), this.registration, this.registered, statusInfo, event.getTimestamp(), this.info, this.endpoints, this.buildVersion, this.tags, unsavedEvents);
    } else if (event instanceof InstanceEndpointsDetectedEvent) {
        Endpoints endpoints = ((InstanceEndpointsDetectedEvent) event).getEndpoints();
        return new Instance(this.id, event.getVersion(), this.registration, this.registered, this.statusInfo, this.statusTimestamp, this.info, endpoints, this.buildVersion, this.tags, unsavedEvents);
    } else if (event instanceof InstanceInfoChangedEvent) {
        Info info = ((InstanceInfoChangedEvent) event).getInfo();
        Map<String, ?> metaData = (this.registration != null) ? this.registration.getMetadata() : emptyMap();
        return new Instance(this.id, event.getVersion(), this.registration, this.registered, this.statusInfo, this.statusTimestamp, info, this.endpoints, updateBuildVersion(metaData, info.getValues()), updateTags(metaData, info.getValues()), unsavedEvents);
    } else if (event instanceof InstanceDeregisteredEvent) {
        return new Instance(this.id, event.getVersion(), this.registration, false, StatusInfo.ofUnknown(), event.getTimestamp(), Info.empty(), Endpoints.empty(), null, Tags.empty(), unsavedEvents);
    }
    return this;
}
Also used : InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) InstanceEndpointsDetectedEvent(de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent) Info(de.codecentric.boot.admin.server.domain.values.Info) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) InstanceRegistrationUpdatedEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Registration(de.codecentric.boot.admin.server.domain.values.Registration) InstanceDeregisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)

Example 5 with InstanceInfoChangedEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent in project spring-boot-admin by codecentric.

the class StatusUpdateTriggerTest method should_not_update_on_non_relevant_event.

@Test
public void should_not_update_on_non_relevant_event() {
    // when some non-registered event is emitted
    this.events.next(new InstanceInfoChangedEvent(this.instance.getId(), this.instance.getVersion(), Info.empty()));
    // then should not update
    verify(this.updater, never()).updateStatus(this.instance.getId());
}
Also used : InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceInfoChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent)9 Test (org.junit.jupiter.api.Test)8 JSONObject (org.json.JSONObject)4 Info (de.codecentric.boot.admin.server.domain.values.Info)3 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)3 Instant (java.time.Instant)3 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)1 InstanceEndpointsDetectedEvent (de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent)1 InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)1 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)1 InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)1 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)1 Endpoints (de.codecentric.boot.admin.server.domain.values.Endpoints)1 Registration (de.codecentric.boot.admin.server.domain.values.Registration)1 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)1 HashMap (java.util.HashMap)1