Search in sources :

Example 31 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class LocalServiceRegistryClientImplTest method findServiceInstance_twoSelectOne.

@Test
public void findServiceInstance_twoSelectOne() {
    Microservice v1 = mockRegisterMicroservice(appId, microserviceName, "1.0.0");
    mockRegisterMicroservice(appId, microserviceName, "2.0.0");
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setServiceId(v1.getServiceId());
    registryClient.registerMicroserviceInstance(instance);
    List<MicroserviceInstance> result = registryClient.findServiceInstance("self", appId, microserviceName, "1.0.0");
    Assert.assertThat(result, Matchers.contains(instance));
    MicroserviceInstances microserviceInstances = registryClient.findServiceInstances("self", appId, microserviceName, "1.0.0", "0");
    List<MicroserviceInstance> results = microserviceInstances.getInstancesResponse().getInstances();
    Assert.assertThat(results, Matchers.contains(instance));
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) MicroserviceInstances(org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 32 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class LocalServiceRegistryClientImplTest method getMicroserviceId_fixVersion.

@Test
public void getMicroserviceId_fixVersion() {
    Microservice v1 = mockRegisterMicroservice(appId, microserviceName, "1.0.0");
    mockRegisterMicroservice(appId, microserviceName, "2.0.0");
    String serviceId = registryClient.getMicroserviceId(appId, microserviceName, "1.0.0");
    Assert.assertEquals(v1.getServiceId(), serviceId);
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Test(org.junit.Test)

Example 33 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class LocalServiceRegistryClientImplTest method mockRegisterMicroservice.

private Microservice mockRegisterMicroservice(String appId, String name, String version) {
    Microservice microservice = new Microservice();
    microservice.setAppId(appId);
    microservice.setServiceName(name);
    microservice.setVersion(version);
    String serviceId = registryClient.registerMicroservice(microservice);
    microservice.setServiceId(serviceId);
    return microservice;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice)

Example 34 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class LocalServiceRegistryClientImplTest method testFindServiceInstance.

@Test
public void testFindServiceInstance() {
    Microservice microservice = mockRegisterMicroservice(appId, microserviceName, "1.0.0");
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setServiceId(microservice.getServiceId());
    String instanceId = registryClient.registerMicroserviceInstance(instance);
    Assert.assertNotNull(registryClient.findServiceInstance(microservice.getServiceId(), instanceId));
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 35 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class MicroserviceRegisterTask method checkSchemaIdSet.

private boolean checkSchemaIdSet() {
    Microservice existMicroservice = srClient.getMicroservice(microservice.getServiceId());
    if (existMicroservice == null) {
        LOGGER.error("Error to get microservice from service center when check schema set");
        return false;
    }
    Set<String> existSchemas = new HashSet<>(existMicroservice.getSchemas());
    Set<String> localSchemas = new HashSet<>(microservice.getSchemas());
    schemaIdSetMatch = existSchemas.equals(localSchemas);
    if (!schemaIdSetMatch) {
        LOGGER.error("SchemaIds is different between local and service center. Please change microservice version. " + "id={} appId={}, name={}, version={}, local schemaIds={}, service center schemaIds={}", microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), localSchemas, existSchemas);
        return true;
    }
    LOGGER.info("SchemaIds is equals to service center. id={} appId={}, name={}, version={}, schemaIds={}", microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), localSchemas);
    return true;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) HashSet(java.util.HashSet)

Aggregations

Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)47 Test (org.junit.Test)24 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)15 Expectations (mockit.Expectations)11 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 EventBus (com.google.common.eventbus.EventBus)4 Before (org.junit.Before)4 Subscribe (com.google.common.eventbus.Subscribe)3 MockUp (mockit.MockUp)3 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)3 MicroserviceFactory (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory)3 MicroserviceInstances (org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances)3 Endpoint (org.apache.servicecomb.core.Endpoint)2 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)2 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)2 Version (org.apache.servicecomb.serviceregistry.version.Version)2 VersionRule (org.apache.servicecomb.serviceregistry.version.VersionRule)2 Handler (io.vertx.core.Handler)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1