Search in sources :

Example 11 with InstanceEvent

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

the class AbstractEventStoreTest method concurrent_read_writes.

@Test
public void concurrent_read_writes() {
    InstanceId id = InstanceId.of("a");
    InstanceEventStore store = createStore(500);
    Function<Integer, InstanceEvent> eventFactory = (i) -> new InstanceDeregisteredEvent(id, i);
    Flux<Void> eventgenerator = Flux.range(0, 500).map(eventFactory).buffer(2).flatMap((events) -> store.append(events).onErrorResume(OptimisticLockingException.class, (ex) -> {
        log.info("skipped {}", ex.getMessage());
        return Mono.empty();
    }).delayElement(Duration.ofMillis(5L)));
    StepVerifier.create(eventgenerator.subscribeOn(Schedulers.newSingle("a")).mergeWith(eventgenerator.subscribeOn(Schedulers.newSingle("a"))).mergeWith(eventgenerator.subscribeOn(Schedulers.newSingle("a"))).mergeWith(eventgenerator.subscribeOn(Schedulers.newSingle("a"))).then()).verifyComplete();
    List<Long> versions = store.find(id).map(InstanceEvent::getVersion).collectList().block();
    List<Long> expected = LongStream.range(0, 500).boxed().collect(toList());
    assertThat(versions).containsExactlyElementsOf(expected);
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) LongStream(java.util.stream.LongStream) Logger(org.slf4j.Logger) StepVerifier(reactor.test.StepVerifier) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) InstanceDeregisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) Function(java.util.function.Function) Collections.singletonList(java.util.Collections.singletonList) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Schedulers(reactor.core.scheduler.Schedulers) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) InstanceDeregisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)11 Test (org.junit.jupiter.api.Test)8 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)5 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)5 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)5 Registration (de.codecentric.boot.admin.server.domain.values.Registration)3 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)3 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)2 Info (de.codecentric.boot.admin.server.domain.values.Info)2 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)2 Instant (java.time.Instant)2 List (java.util.List)2 Function (java.util.function.Function)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Flux (reactor.core.publisher.Flux)2 Mono (reactor.core.publisher.Mono)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