Search in sources :

Example 16 with ServiceRegistry

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

the class TestInvocationFactory method setUp.

@BeforeClass
public static void setUp() {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    RegistryUtils.setServiceRegistry(serviceRegistry);
}
Also used : ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) BeforeClass(org.junit.BeforeClass)

Example 17 with ServiceRegistry

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

the class TestLocalServiceRegistry method registerMicroservice.

@Test
public void registerMicroservice() {
    ServiceRegistry serviceRegistry = LocalServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    serviceRegistry.run();
    Microservice microservice = new Microservice();
    microservice.setAppId("appId");
    microservice.setServiceName("msName");
    String serviceId = serviceRegistry.getServiceRegistryClient().registerMicroservice(microservice);
    Microservice remoteMicroservice = serviceRegistry.getRemoteMicroservice(serviceId);
    Assert.assertEquals(serviceId, remoteMicroservice.getServiceId());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) Test(org.junit.Test)

Example 18 with ServiceRegistry

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

Example 19 with ServiceRegistry

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

the class AggregateMicroserviceCacheTest method refresh.

@Test
public void refresh() {
    MicroserviceCacheKey microserviceCacheKey = MicroserviceCacheKey.builder().serviceName("svc").appId("app").env("production").build();
    MockMicroserviceCache mockMicroserviceCache0 = new MockMicroserviceCache(microserviceCacheKey, MicroserviceCacheStatus.NO_CHANGE);
    MockMicroserviceCache mockMicroserviceCache2 = new MockMicroserviceCache(microserviceCacheKey, MicroserviceCacheStatus.REFRESHED);
    mockMicroserviceCache2.instances = Arrays.asList(new MicroserviceInstance(), new MicroserviceInstance());
    MockMicroserviceCache mockMicroserviceCache3 = new MockMicroserviceCache(microserviceCacheKey, MicroserviceCacheStatus.SERVICE_NOT_FOUND);
    MockServiceRegistry mockServiceRegistry0 = new MockServiceRegistry().setName("s0").addCache(mockMicroserviceCache0).addCache(new MockMicroserviceCache(MicroserviceCacheKey.builder().serviceName("svc2").appId("app").env("production").build(), MicroserviceCacheStatus.REFRESHED));
    MockServiceRegistry mockServiceRegistry1 = new MockServiceRegistry().setName("s1");
    MockServiceRegistry mockServiceRegistry2 = new MockServiceRegistry().setName("s2").addCache(mockMicroserviceCache2);
    MockServiceRegistry mockServiceRegistry3 = new MockServiceRegistry().setName("s3").addCache(mockMicroserviceCache3);
    List<ServiceRegistry> serviceRegistries = Arrays.asList(mockServiceRegistry0, mockServiceRegistry1, mockServiceRegistry2, mockServiceRegistry3);
    AggregateMicroserviceCache compositeMicroserviceCache = new AggregateMicroserviceCache(microserviceCacheKey, serviceRegistries);
    // Test initialization
    // key
    Assert.assertSame(microserviceCacheKey, compositeMicroserviceCache.getKey());
    // status
    Assert.assertEquals(MicroserviceCacheStatus.REFRESHED, compositeMicroserviceCache.getStatus());
    // revision
    Assert.assertEquals("1", compositeMicroserviceCache.getRevisionId());
    Assert.assertEquals(1L, compositeMicroserviceCache.revisionCounter.get());
    // MicroserviceCache map
    Assert.assertEquals(2, compositeMicroserviceCache.caches.size());
    Assert.assertSame(mockMicroserviceCache0, compositeMicroserviceCache.caches.get("s0"));
    Assert.assertSame(mockMicroserviceCache2, compositeMicroserviceCache.caches.get("s2"));
    // ServiceRegistry collection
    Assert.assertEquals(serviceRegistries.size(), compositeMicroserviceCache.serviceRegistries.size());
    Iterator<ServiceRegistry> serviceRegistryIterator = compositeMicroserviceCache.serviceRegistries.iterator();
    Assert.assertSame(serviceRegistries.get(0), serviceRegistryIterator.next());
    Assert.assertSame(serviceRegistries.get(1), serviceRegistryIterator.next());
    Assert.assertSame(serviceRegistries.get(2), serviceRegistryIterator.next());
    Assert.assertSame(serviceRegistries.get(3), serviceRegistryIterator.next());
    // cached instances
    Assert.assertEquals(2, compositeMicroserviceCache.getInstances().size());
    Assert.assertSame(mockMicroserviceCache2.instances.get(0), compositeMicroserviceCache.getInstances().get(0));
    Assert.assertSame(mockMicroserviceCache2.instances.get(1), compositeMicroserviceCache.getInstances().get(1));
    // Test refresh()
    mockMicroserviceCache0.instances = Collections.singletonList(new MicroserviceInstance());
    mockMicroserviceCache2.instances = Collections.singletonList(new MicroserviceInstance());
    compositeMicroserviceCache.refresh();
    // status
    Assert.assertEquals(MicroserviceCacheStatus.REFRESHED, compositeMicroserviceCache.getStatus());
    // revision
    Assert.assertEquals("2", compositeMicroserviceCache.getRevisionId());
    Assert.assertEquals(2L, compositeMicroserviceCache.revisionCounter.get());
    // cached instances
    Assert.assertEquals(2, compositeMicroserviceCache.getInstances().size());
    Assert.assertSame(mockMicroserviceCache0.instances.get(0), compositeMicroserviceCache.getInstances().get(0));
    Assert.assertSame(mockMicroserviceCache2.instances.get(0), compositeMicroserviceCache.getInstances().get(1));
    // Test refresh()
    // microservice deleted and registered
    mockMicroserviceCache0.status = MicroserviceCacheStatus.SERVICE_NOT_FOUND;
    mockMicroserviceCache3.status = MicroserviceCacheStatus.REFRESHED;
    compositeMicroserviceCache.refresh();
    // status
    Assert.assertEquals(MicroserviceCacheStatus.REFRESHED, compositeMicroserviceCache.getStatus());
    // revision
    Assert.assertEquals("3", compositeMicroserviceCache.getRevisionId());
    Assert.assertEquals(3L, compositeMicroserviceCache.revisionCounter.get());
    // ServiceRegistries
    Assert.assertNotNull(compositeMicroserviceCache.caches.get("s2"));
    Assert.assertNotNull(compositeMicroserviceCache.caches.get("s3"));
    // cached instances
    Assert.assertEquals(1, compositeMicroserviceCache.getInstances().size());
    Assert.assertSame(mockMicroserviceCache2.instances.get(0), compositeMicroserviceCache.getInstances().get(0));
}
Also used : MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) EmptyMockServiceRegistry(org.apache.servicecomb.serviceregistry.registry.EmptyMockServiceRegistry) EmptyMockServiceRegistry(org.apache.servicecomb.serviceregistry.registry.EmptyMockServiceRegistry) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) Test(org.junit.Test)

Aggregations

ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)19 Test (org.junit.Test)14 EventBus (com.google.common.eventbus.EventBus)4 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)4 BeforeClass (org.junit.BeforeClass)4 Invocation (org.apache.servicecomb.core.Invocation)3 UnitTestMeta (org.apache.servicecomb.core.unittest.UnitTestMeta)3 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)3 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Holder (javax.xml.ws.Holder)2 Expectations (mockit.Expectations)2 Mock (mockit.Mock)2 MicroserviceMetaManager (org.apache.servicecomb.core.definition.MicroserviceMetaManager)2 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)2 SchemaLoader (org.apache.servicecomb.core.definition.loader.SchemaLoader)2 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)2 LocalServiceRegistryClientImpl (org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl)2 ServiceRegistryClient (org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient)2