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);
}
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());
}
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);
}
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));
}
Aggregations