Search in sources :

Example 11 with InstanceStore

use of org.apache.servicecomb.registry.lightweight.store.InstanceStore in project java-chassis by ServiceComb.

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 12 with InstanceStore

use of org.apache.servicecomb.registry.lightweight.store.InstanceStore in project java-chassis by ServiceComb.

the class StoreServiceTest method should_process_as_heartbeat_when_nothing_changed.

@Test
void should_process_as_heartbeat_when_nothing_changed() {
    should_register_microservice_and_instance_when_both_not_exist();
    InstanceStore instanceStore = store.findInstanceStore(self.getInstanceId());
    assertThat(instanceStore.getLastHeartBeat()).isEqualTo(0);
    ticker.setValues(1L);
    should_register_microservice_and_instance_when_both_not_exist();
    assertThat(instanceStore.getLastHeartBeat()).isEqualTo(1);
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) Test(org.junit.jupiter.api.Test)

Example 13 with InstanceStore

use of org.apache.servicecomb.registry.lightweight.store.InstanceStore in project incubator-servicecomb-java-chassis by apache.

the class StoreService method addMicroserviceAndInstance.

private CompletableFuture<InstanceStore> addMicroserviceAndInstance(Endpoint endpoint, RegisterRequest request) {
    return discoveryClient.getInfoAsync(endpoint, request.getServiceId()).thenApply(info -> {
        info.getMicroservice().getSchemaMap().putAll(info.getSchemasById());
        MicroserviceStore microserviceStore = store.addMicroservice(info.getMicroservice(), request.getSchemasSummary());
        InstanceStore instanceStore = doAddInstance(microserviceStore, info.getInstance());
        LOGGER.info("add microservice and instance, serviceId={}, instanceId={}, endpoints={}", request.getServiceId(), request.getInstanceId(), request.getEndpoints());
        return instanceStore;
    });
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore)

Example 14 with InstanceStore

use of org.apache.servicecomb.registry.lightweight.store.InstanceStore in project incubator-servicecomb-java-chassis by apache.

the class StoreService method deleteInstance.

public void deleteInstance(String action, String serviceId, String instanceId) {
    InstanceStore instanceStore = store.deleteInstance(serviceId, instanceId);
    if (instanceStore == null) {
        return;
    }
    LOGGER.info("{} instance, serviceId={}, instanceId={}, endpoints={}", action, instanceStore.getServiceId(), instanceStore.getInstanceId(), instanceStore.getEndpoints());
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore)

Example 15 with InstanceStore

use of org.apache.servicecomb.registry.lightweight.store.InstanceStore in project incubator-servicecomb-java-chassis by apache.

the class StoreService method doAddInstance.

private InstanceStore doAddInstance(MicroserviceStore microserviceStore, MicroserviceInstance instance) {
    InstanceStore instanceStore = store.addInstance(microserviceStore, instance);
    eventBus.post(new RegisterInstanceEvent(microserviceStore.getMicroservice(), instance));
    return instanceStore;
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore)

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