Search in sources :

Example 6 with InstanceStore

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));
}
Also used : EventBus(com.google.common.eventbus.EventBus) MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore) Component(org.springframework.stereotype.Component) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Logger(org.slf4j.Logger) Store(org.apache.servicecomb.registry.lightweight.store.Store) AsyncUtils(org.apache.servicecomb.foundation.common.utils.AsyncUtils) Duration(java.time.Duration) InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Endpoint(org.apache.servicecomb.core.Endpoint) Endpoint(org.apache.servicecomb.core.Endpoint) MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore)

Example 7 with InstanceStore

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());
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore) Test(org.junit.jupiter.api.Test)

Example 8 with InstanceStore

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());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) Test(org.junit.jupiter.api.Test)

Example 9 with InstanceStore

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);
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) Test(org.junit.jupiter.api.Test)

Example 10 with InstanceStore

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);
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceStore (org.apache.servicecomb.registry.lightweight.store.InstanceStore)18 Test (org.junit.jupiter.api.Test)10 MicroserviceStore (org.apache.servicecomb.registry.lightweight.store.MicroserviceStore)6 EventBus (com.google.common.eventbus.EventBus)2 Duration (java.time.Duration)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Endpoint (org.apache.servicecomb.core.Endpoint)2 AsyncUtils (org.apache.servicecomb.foundation.common.utils.AsyncUtils)2 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)2 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)2 Store (org.apache.servicecomb.registry.lightweight.store.Store)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Component (org.springframework.stereotype.Component)2