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);
}
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();
}
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();
}
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();
}
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);
}
Aggregations