use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.
the class ConcurrentMapEventStore method doAppend.
protected boolean doAppend(List<InstanceEvent> events) {
if (events.isEmpty()) {
return true;
}
InstanceId id = events.get(0).getInstance();
if (!events.stream().allMatch((event) -> event.getInstance().equals(id))) {
throw new IllegalArgumentException("'events' must only refer to the same instance.");
}
List<InstanceEvent> oldEvents = eventLog.computeIfAbsent(id, (key) -> new ArrayList<>(maxLogSizePerAggregate + 1));
long lastVersion = getLastVersion(oldEvents);
if (lastVersion >= events.get(0).getVersion()) {
throw createOptimisticLockException(events.get(0), lastVersion);
}
List<InstanceEvent> newEvents = new ArrayList<>(oldEvents);
newEvents.addAll(events);
if (newEvents.size() > maxLogSizePerAggregate) {
log.debug("Threshold for {} reached. Compacting events", id);
compact(newEvents);
}
if (eventLog.replace(id, oldEvents, newEvents)) {
log.debug("Events appended to log {}", events);
return true;
}
log.debug("Unsuccessful attempt append the events {} ", events);
return false;
}
use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.
the class InstanceEndpointsDetectedEventMixinTest method verifySerializeWithEmptyEndpoints.
@Test
public void verifySerializeWithEmptyEndpoints() throws IOException {
InstanceId id = InstanceId.of("test123");
Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
InstanceEndpointsDetectedEvent event = new InstanceEndpointsDetectedEvent(id, 0L, timestamp, Endpoints.empty());
JsonContent<InstanceEndpointsDetectedEvent> jsonContent = jsonTester.write(event);
assertThat(jsonContent).extractingJsonPathStringValue("$.instance").isEqualTo("test123");
assertThat(jsonContent).extractingJsonPathNumberValue("$.version").isEqualTo(0);
assertThat(jsonContent).extractingJsonPathNumberValue("$.timestamp").isEqualTo(1587751031.000000000);
assertThat(jsonContent).extractingJsonPathStringValue("$.type").isEqualTo("ENDPOINTS_DETECTED");
assertThat(jsonContent).extractingJsonPathArrayValue("$.endpoints").isEmpty();
}
use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.
the class InstanceIdMixinTest method verifyDeserialize.
@Test
public void verifyDeserialize() throws JSONException, JsonProcessingException {
InstanceId id = objectMapper.readValue("\"abc\"", InstanceId.class);
assertThat(id).isEqualTo(InstanceId.of("abc"));
}
use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.
the class InstanceIdMixinTest method verifySerialize.
@Test
public void verifySerialize() throws IOException {
InstanceId id = InstanceId.of("abc");
String result = objectMapper.writeValueAsString(id);
assertThat(result).isEqualTo("\"abc\"");
}
use of de.codecentric.boot.admin.server.domain.values.InstanceId 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");
}
Aggregations