use of org.apache.servicecomb.registry.lightweight.store.InstanceStore in project incubator-servicecomb-java-chassis by apache.
the class StoreService method addInstance.
private CompletableFuture<InstanceStore> addInstance(RegisterRequest request) {
Endpoint endpoint = request.selectFirstEndpoint();
if (endpoint == null) {
return AsyncUtils.completeExceptionally(new RegisterException("can not select endpoint"));
}
MicroserviceStore microserviceStore = this.store.findMicroserviceStore(request.getServiceId());
if (microserviceStore == null) {
return addMicroserviceAndInstance(endpoint, request);
}
return checkSchemaSummary(request, microserviceStore).thenCompose(v -> discoveryClient.getInstanceAsync(endpoint, request.getServiceId())).thenApply(instance -> addInstance(microserviceStore, instance));
}
use of org.apache.servicecomb.registry.lightweight.store.InstanceStore in project incubator-servicecomb-java-chassis by apache.
the class StoreServiceTest method should_register_and_notify_when_schema_changed_and_has_not_existing_instance.
@Test
void should_register_and_notify_when_schema_changed_and_has_not_existing_instance() {
should_register_microservice_and_instance_when_both_not_exist();
MicroserviceStore microserviceStore = store.findMicroserviceStore(self.getServiceId());
assertThat(microserviceStore.hasInstance()).isTrue();
store.deleteInstance(self.getServiceId(), self.getInstanceId());
assertThat(microserviceStore.hasInstance()).isFalse();
eventBus.register(this);
RegisterRequest request = self.buildRegisterRequest().setSchemasSummary("new summary");
InstanceStore instanceStore = service.register(request);
assertThat(microserviceStore.isSchemaChanged("new summary")).isFalse();
assertThat(instanceStore.getInstance()).isSameAs(self.getInstance());
assertThat(schemaChangedEvent.getMicroservice()).isSameAs(self.getMicroservice());
}
use of org.apache.servicecomb.registry.lightweight.store.InstanceStore in project incubator-servicecomb-java-chassis by apache.
the class StoreServiceTest method should_register_instance_when_microservice_exist.
@Test
void should_register_instance_when_microservice_exist() {
Microservice microservice = Json.decodeValue(Json.encode(self.getMicroservice()), Microservice.class);
store.addMicroservice(microservice, self.getSchemasSummary());
RegisterRequest request = self.buildRegisterRequest();
InstanceStore instanceStore = service.register(request);
assertThat(microservice).isNotSameAs(self.getMicroservice());
assertThat(store.findMicroserviceStore(self.getServiceId()).getMicroservice()).isSameAs(microservice);
assertThat(instanceStore.getInstance()).isSameAs(self.getInstance());
}
use of org.apache.servicecomb.registry.lightweight.store.InstanceStore in project java-chassis by ServiceComb.
the class StoreServiceTest method should_allow_update_instance_status.
@Test
void should_allow_update_instance_status() {
should_register_microservice_and_instance_when_both_not_exist();
RegisterRequest request = self.buildRegisterRequest().setStatus(MicroserviceInstanceStatus.TESTING);
ticker.setValues(1L);
InstanceStore instanceStore = service.register(request);
assertThat(self.getInstance().getStatus()).isEqualTo(MicroserviceInstanceStatus.TESTING);
assertThat(instanceStore.getLastHeartBeat()).isEqualTo(1);
}
use of org.apache.servicecomb.registry.lightweight.store.InstanceStore in project java-chassis by ServiceComb.
the class StoreServiceTest method should_register_microservice_and_instance_when_both_not_exist.
@Test
void should_register_microservice_and_instance_when_both_not_exist() {
RegisterRequest request = self.buildRegisterRequest();
InstanceStore instanceStore = service.register(request);
assertThat(store.findMicroserviceStore(self.getServiceId()).getMicroservice()).isSameAs(self.getMicroservice());
assertThat(instanceStore.getInstance()).isSameAs(self.getInstance());
assertThat(self.getInstance().getStatus()).isEqualTo(MicroserviceInstanceStatus.UP);
}
Aggregations