Search in sources :

Example 6 with MicroserviceDefinition

use of org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition in project incubator-servicecomb-java-chassis by apache.

the class TestServiceRegistryFactory method testGetRemoteRegistryClient.

@Test
public void testGetRemoteRegistryClient() {
    EventBus eventBus = new EventBus();
    ServiceRegistryConfig serviceRegistryConfig = ServiceRegistryConfig.INSTANCE;
    MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(Collections.emptyList());
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.create(eventBus, serviceRegistryConfig, microserviceDefinition);
    serviceRegistry.init();
    ServiceRegistryClient client = serviceRegistry.getServiceRegistryClient();
    Assert.assertTrue(client instanceof ServiceRegistryClientImpl);
    serviceRegistry = ServiceRegistryFactory.getOrCreate(eventBus, serviceRegistryConfig, microserviceDefinition);
    Assert.assertTrue(serviceRegistry instanceof RemoteServiceRegistry);
    Assert.assertEquals(serviceRegistry, ServiceRegistryFactory.getServiceRegistry());
    Deencapsulation.setField(ServiceRegistryFactory.class, "serviceRegistry", null);
    System.setProperty("local.registry.file", "/tmp/test.yaml");
    serviceRegistry = ServiceRegistryFactory.create(eventBus, serviceRegistryConfig, microserviceDefinition);
    serviceRegistry.init();
    client = serviceRegistry.getServiceRegistryClient();
    Assert.assertTrue(client instanceof LocalServiceRegistryClientImpl);
    Assert.assertTrue(ServiceRegistryFactory.getOrCreate(eventBus, serviceRegistryConfig, microserviceDefinition) instanceof LocalServiceRegistry);
    System.clearProperty("local.registry.file");
}
Also used : ServiceRegistryConfig(org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig) LocalServiceRegistryClientImpl(org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl) MicroserviceDefinition(org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition) ServiceRegistryClient(org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient) EventBus(com.google.common.eventbus.EventBus) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) LocalServiceRegistryClientImpl(org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl) ServiceRegistryClientImpl(org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl) Test(org.junit.Test)

Aggregations

MicroserviceDefinition (org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition)6 Test (org.junit.Test)4 MicroserviceConfigLoader (org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader)3 EventBus (com.google.common.eventbus.EventBus)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConfigModel (org.apache.servicecomb.config.archaius.sources.ConfigModel)2 ServiceRegistryConfig (org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig)2 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)1 LocalServiceRegistryClientImpl (org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl)1 ServiceRegistryClient (org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient)1 ServiceRegistryClientImpl (org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl)1