use of de.codecentric.boot.admin.server.domain.events.InstanceEvent in project spring-boot-admin by codecentric.
the class Instance method apply.
Instance apply(Collection<InstanceEvent> events) {
Assert.notNull(events, "'events' must not be null");
Instance instance = this;
for (InstanceEvent event : events) {
instance = instance.apply(event);
}
return instance;
}
use of de.codecentric.boot.admin.server.domain.events.InstanceEvent 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.events.InstanceEvent in project spring-boot-admin by codecentric.
the class FilteringNotifierTest method test_filter.
@Test
public void test_filter() {
TestNotifier delegate = new TestNotifier();
FilteringNotifier notifier = new FilteringNotifier(delegate, repository);
AbstractNotificationFilter trueFilter = new AbstractNotificationFilter() {
@Override
public boolean filter(InstanceEvent event, Instance instance) {
return true;
}
};
notifier.addFilter(trueFilter);
StepVerifier.create(notifier.notify(event)).verifyComplete();
assertThat(delegate.getEvents()).doesNotContain(event);
notifier.removeFilter(trueFilter.getId());
StepVerifier.create(notifier.notify(event)).verifyComplete();
assertThat(delegate.getEvents()).contains(event);
}
use of de.codecentric.boot.admin.server.domain.events.InstanceEvent 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.InstanceEvent in project spring-boot-admin by codecentric.
the class MailNotifierTest method should_not_propagate_error.
@Test
public void should_not_propagate_error() {
Notifier notifier = new AbstractStatusChangeNotifier(repository) {
@Override
protected Mono<Void> doNotify(InstanceEvent event, Instance application) {
return Mono.error(new IllegalStateException("test"));
}
};
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofUp()))).verifyComplete();
}
Aggregations