use of io.servicecomb.serviceregistry.RegistryThread in project java-chassis by ServiceComb.
the class TestClienthttp method testServiceRegistryClientImpl.
@SuppressWarnings("unchecked")
@Test
public void testServiceRegistryClientImpl(@Mocked IpPortManager manager) {
IpPort ipPort = new IpPort("127.0.0.1", 8853);
new Expectations() {
{
manager.get();
result = ipPort;
manager.next();
result = null;
}
};
Microservice oInstance = RegistryUtils.getMicroservice();
RegistryThread oThread = new RegistryThread();
oThread.start();
ServiceRegistryClientImpl oClient = (ServiceRegistryClientImpl) RegistryClientFactory.getRegistryClient();
oClient.registerMicroservice(oInstance);
oClient.registerMicroserviceInstance(RegistryUtils.getMicroserviceInstance());
try {
oClient.init();
} catch (Exception e) {
Assert.assertEquals(null, e.getMessage());
}
Assert.assertEquals(null, oClient.getMicroservice(RegistryUtils.getMicroservice().getServiceId()));
Assert.assertEquals(null, oClient.getMicroserviceInstance("testConsumerID", "testproviderID"));
Assert.assertEquals(null, oClient.findServiceInstance(RegistryUtils.getMicroservice().getServiceId(), RegistryUtils.getMicroservice().getAppId(), RegistryUtils.getMicroservice().getServiceName(), RegistryUtils.getMicroservice().getVersion()));
Assert.assertEquals(null, oClient.getMicroserviceId(RegistryUtils.getMicroservice().getAppId(), RegistryUtils.getMicroservice().getServiceName(), RegistryUtils.getMicroservice().getVersion()));
Assert.assertEquals(null, oClient.heartbeat(RegistryUtils.getMicroservice().getServiceId(), RegistryUtils.getMicroserviceInstance().getInstanceId()));
oClient.watch("", Mockito.mock(AsyncResultCallback.class));
Assert.assertEquals(false, oClient.unregisterMicroserviceInstance(RegistryUtils.getMicroservice().getServiceId(), RegistryUtils.getMicroserviceInstance().getInstanceId()));
}
use of io.servicecomb.serviceregistry.RegistryThread in project java-chassis by ServiceComb.
the class TestServiceRegistryClientImpl method testException.
@Test
public void testException() {
Microservice oInstance = RegistryUtils.getMicroservice();
RegistryThread oThread = new RegistryThread();
oThread.start();
oClient.registerMicroservice(oInstance);
oClient.registerMicroserviceInstance(RegistryUtils.getMicroserviceInstance());
try {
oClient.init();
} catch (Exception e) {
Assert.assertEquals(null, e.getMessage());
}
new MockUp<CountDownLatch>() {
@Mock
public void await() throws InterruptedException {
throw new InterruptedException();
}
};
Assert.assertEquals(null, oClient.getMicroserviceId(RegistryUtils.getMicroservice().getAppId(), RegistryUtils.getMicroservice().getServiceName(), RegistryUtils.getMicroservice().getVersion()));
Assert.assertEquals(null, oClient.getAllMicroservices());
Assert.assertEquals(null, oClient.registerMicroservice(RegistryUtils.getMicroservice()));
Assert.assertEquals(null, oClient.getMicroservice("microserviceId"));
Assert.assertEquals(null, oClient.getMicroserviceInstance("consumerId", "providerId"));
Assert.assertEquals(false, oClient.unregisterMicroserviceInstance("microserviceId", "microserviceInstanceId"));
Assert.assertEquals(null, oClient.heartbeat("microserviceId", "microserviceInstanceId"));
Assert.assertEquals(null, oClient.findServiceInstance("selfMicroserviceId", "appId", "serviceName", "versionRule"));
MicroserviceInstance microInstance = Mockito.mock(MicroserviceInstance.class);
Assert.assertEquals(null, oClient.registerMicroserviceInstance(microInstance));
Assert.assertEquals("a", new ClientException("a").getMessage());
}
Aggregations