Search in sources :

Example 1 with ServiceRegistryConfig

use of org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig in project java-chassis by ServiceComb.

the class LocalServiceRegistryFactory method createLocal.

public static ServiceRegistry createLocal(String localFile) {
    EventBus eventBus = new SimpleEventBus();
    ServiceRegistryConfig serviceRegistryConfig = ServiceRegistryConfig.INSTANCE;
    return new LocalServiceRegistry(eventBus, serviceRegistryConfig, ConfigUtil.createLocalConfig()).localFile(localFile);
}
Also used : ServiceRegistryConfig(org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig) SimpleEventBus(org.apache.servicecomb.foundation.common.event.SimpleEventBus) EventBus(com.google.common.eventbus.EventBus) SimpleEventBus(org.apache.servicecomb.foundation.common.event.SimpleEventBus)

Example 2 with ServiceRegistryConfig

use of org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig in project incubator-servicecomb-java-chassis by apache.

the class ServiceRegistryFactory method createLocal.

public static ServiceRegistry createLocal() {
    EventBus eventBus = new EventBus();
    ServiceRegistryConfig serviceRegistryConfig = ServiceRegistryConfig.INSTANCE;
    MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
    loader.loadAndSort();
    MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(loader.getConfigModels());
    return new LocalServiceRegistry(eventBus, serviceRegistryConfig, microserviceDefinition);
}
Also used : ServiceRegistryConfig(org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig) MicroserviceConfigLoader(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader) MicroserviceDefinition(org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition) EventBus(com.google.common.eventbus.EventBus)

Example 3 with ServiceRegistryConfig

use of org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig 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)

Example 4 with ServiceRegistryConfig

use of org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig in project java-chassis by ServiceComb.

the class TestServiceRegistryFactory method testGetRemoteRegistryClient.

@Test
public // because what changed is class ServiceRegistryClientImpl
void testGetRemoteRegistryClient(@Mocked ServiceRegistryClientImpl registryClient) {
    Configuration configuration = ConfigUtil.createLocalConfig();
    EventBus eventBus = new EventBus();
    ServiceRegistryConfig serviceRegistryConfig = ServiceRegistryConfig.INSTANCE;
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.create(eventBus, serviceRegistryConfig, configuration);
    serviceRegistry.init();
    ServiceRegistryClient client = serviceRegistry.getServiceRegistryClient();
    Assert.assertTrue(client instanceof ServiceRegistryClientImpl);
    serviceRegistry = ServiceRegistryFactory.create(eventBus, serviceRegistryConfig, configuration);
    Assert.assertTrue(serviceRegistry instanceof RemoteServiceRegistry);
    serviceRegistry = LocalServiceRegistryFactory.createLocal(eventBus, serviceRegistryConfig, configuration);
    serviceRegistry.init();
    client = serviceRegistry.getServiceRegistryClient();
    Assert.assertTrue(client instanceof LocalServiceRegistryClientImpl);
    Assert.assertTrue(LocalServiceRegistryFactory.createLocal(eventBus, serviceRegistryConfig, configuration) instanceof LocalServiceRegistry);
}
Also used : ServiceRegistryConfig(org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig) Configuration(org.apache.commons.configuration.Configuration) LocalServiceRegistryClientImpl(org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl) 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

EventBus (com.google.common.eventbus.EventBus)4 ServiceRegistryConfig (org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig)4 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)2 LocalServiceRegistryClientImpl (org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl)2 ServiceRegistryClient (org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient)2 ServiceRegistryClientImpl (org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl)2 MicroserviceDefinition (org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition)2 Test (org.junit.Test)2 Configuration (org.apache.commons.configuration.Configuration)1 MicroserviceConfigLoader (org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader)1 SimpleEventBus (org.apache.servicecomb.foundation.common.event.SimpleEventBus)1