use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory in project incubator-servicecomb-java-chassis by apache.
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.getAvailableAddress();
result = ipPort;
}
};
new MockUp<CountDownLatch>() {
@Mock
public void await() throws InterruptedException {
}
};
new MockUp<RestUtils>() {
@Mock
void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
}
};
new MockUp<WebsocketUtils>() {
@Mock
void open(IpPort ipPort, String url, Handler<Void> onOpen, Handler<Void> onClose, Handler<Buffer> onMessage, Handler<Throwable> onException, Handler<Throwable> onConnectFailed) {
}
};
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
Microservice microservice = microserviceFactory.create("app", "ms");
ServiceRegistryClientImpl oClient = new ServiceRegistryClientImpl(manager);
oClient.init();
oClient.registerMicroservice(microservice);
oClient.registerMicroserviceInstance(microservice.getInstance());
Assert.assertEquals(null, oClient.getMicroservice(microservice.getServiceId()));
Assert.assertEquals(null, oClient.getMicroserviceInstance("testConsumerID", "testproviderID"));
Assert.assertEquals(null, oClient.findServiceInstance(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
Assert.assertEquals(null, oClient.findServiceInstances(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), "0"));
Assert.assertEquals(null, oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
Assert.assertEquals(null, oClient.heartbeat(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
oClient.watch("", Mockito.mock(AsyncResultCallback.class));
Assert.assertEquals(false, oClient.unregisterMicroserviceInstance(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory in project incubator-servicecomb-java-chassis by apache.
the class TestServiceRegistryClientImpl method testException.
@Test
public void testException() {
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
Microservice microservice = microserviceFactory.create("app", "ms");
Assert.assertEquals(null, oClient.registerMicroservice(microservice));
Assert.assertEquals(null, oClient.registerMicroserviceInstance(microservice.getInstance()));
oClient.init();
Assert.assertEquals(null, oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
Assert.assertThat(oClient.getAllMicroservices().isEmpty(), is(true));
Assert.assertEquals(null, oClient.registerMicroservice(microservice));
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"));
Assert.assertEquals(null, oClient.findServiceInstances("selfMicroserviceId", "appId", "serviceName", "versionRule", "0"));
Assert.assertEquals("a", new ClientException("a").getMessage());
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory in project incubator-servicecomb-java-chassis by apache.
the class TestServiceRegistryClientImpl method testPrivateMethodCreateHttpClientOptions.
@Test
public void testPrivateMethodCreateHttpClientOptions() {
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
Microservice microservice = microserviceFactory.create("app", "ms");
oClient.registerMicroservice(microservice);
oClient.registerMicroserviceInstance(microservice.getInstance());
new MockUp<ServiceRegistryConfig>() {
@Mock
public HttpVersion getHttpVersion() {
return HttpVersion.HTTP_2;
}
@Mock
public boolean isSsl() {
return true;
}
};
try {
oClient.init();
HttpClientOptions httpClientOptions = Deencapsulation.invoke(oClient, "createHttpClientOptions");
Assert.assertNotNull(httpClientOptions);
Assert.assertEquals(80, httpClientOptions.getDefaultPort());
} catch (Exception e) {
Assert.assertNotNull(e);
}
}
Aggregations