Search in sources :

Example 16 with InstanceId

use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.

the class InstanceRegistry method register.

/**
 * Register instance.
 * @param registration instance to be registered.
 * @return the id of the registered instance.
 */
public Mono<InstanceId> register(Registration registration) {
    Assert.notNull(registration, "'registration' must not be null");
    InstanceId id = generator.generateId(registration);
    Assert.notNull(id, "'id' must not be null");
    return repository.compute(id, (key, instance) -> {
        if (instance == null) {
            instance = Instance.create(key);
        }
        return Mono.just(instance.register(registration));
    }).map(Instance::getId);
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Flux(reactor.core.publisher.Flux) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Mono(reactor.core.publisher.Mono) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) Assert(org.springframework.util.Assert) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Instance(de.codecentric.boot.admin.server.domain.entities.Instance)

Example 17 with InstanceId

use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.

the class InstanceRegistryTest method register.

@Test
public void register() {
    Registration registration = Registration.create("abc", "http://localhost:8080/health").build();
    InstanceId id = registry.register(registration).block();
    StepVerifier.create(registry.getInstance(id)).assertNext((app) -> {
        assertThat(app.getRegistration()).isEqualTo(registration);
        assertThat(app.getId()).isNotNull();
    }).verifyComplete();
    StepVerifier.create(registry.getInstances()).assertNext((app) -> {
        assertThat(app.getRegistration()).isEqualTo(registration);
        assertThat(app.getId()).isNotNull();
    }).verifyComplete();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Info(de.codecentric.boot.admin.server.domain.values.Info) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Collections.singletonMap(java.util.Collections.singletonMap) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 18 with InstanceId

use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.

the class InstanceRegistryTest method findByName.

@Test
public void findByName() {
    InstanceId id1 = registry.register(Registration.create("abc", "http://localhost:8080/health").build()).block();
    InstanceId id2 = registry.register(Registration.create("abc", "http://localhost:8081/health").build()).block();
    InstanceId id3 = registry.register(Registration.create("zzz", "http://localhost:9999/health").build()).block();
    StepVerifier.create(registry.getInstances("abc")).recordWith(ArrayList::new).thenConsumeWhile((a) -> true).consumeRecordedWith((applications) -> assertThat(applications.stream().map(Instance::getId)).doesNotContain(id3).containsExactlyInAnyOrder(id1, id2)).verifyComplete();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Info(de.codecentric.boot.admin.server.domain.values.Info) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Collections.singletonMap(java.util.Collections.singletonMap) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Test(org.junit.jupiter.api.Test)

Example 19 with InstanceId

use of de.codecentric.boot.admin.server.domain.values.InstanceId in project spring-boot-admin by codecentric.

the class AbstractInstanceRepositoryTest method should_not_compute_if_not_present.

@Test
public void should_not_compute_if_not_present() {
    // given
    InstanceId instanceId = InstanceId.of("not-existent");
    // when
    StepVerifier.create(this.repository.computeIfPresent(instanceId, (key, application) -> Mono.error(new AssertionFailedError("Should not call any computation")))).verifyComplete();
    // then
    StepVerifier.create(this.repository.find(instanceId)).verifyComplete();
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) AssertionFailedError(org.opentest4j.AssertionFailedError) Test(org.junit.jupiter.api.Test)

Example 20 with InstanceId

use of de.codecentric.boot.admin.server.domain.values.InstanceId 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

InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)32 Test (org.junit.jupiter.api.Test)28 Instant (java.time.Instant)18 Registration (de.codecentric.boot.admin.server.domain.values.Registration)13 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 StepVerifier (reactor.test.StepVerifier)7 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)6 ArrayList (java.util.ArrayList)6 Mono (reactor.core.publisher.Mono)6 InstanceRepository (de.codecentric.boot.admin.server.domain.entities.InstanceRepository)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Flux (reactor.core.publisher.Flux)5 EventsourcingInstanceRepository (de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository)4 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)4 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)4 Info (de.codecentric.boot.admin.server.domain.values.Info)4 InMemoryEventStore (de.codecentric.boot.admin.server.eventstore.InMemoryEventStore)4 Collections.singletonMap (java.util.Collections.singletonMap)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)4