use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project java-chassis by ServiceComb.
the class TestMicroserviceFactory method testInit.
@Test
public void testInit() {
MicroserviceFactory factory = new MicroserviceFactory();
Microservice microservice = factory.create(ConfigUtil.createLocalConfig());
String microserviceName = "default";
Assert.assertEquals(microserviceName, microservice.getServiceName());
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project java-chassis by ServiceComb.
the class TestMicroserviceFactory method testSetDescriptionOnEmptyDescription.
@Test
public void testSetDescriptionOnEmptyDescription() {
Configuration configuration = ConfigUtil.createLocalConfig();
configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION, new String[] { "", "" });
MicroserviceFactory factory = new MicroserviceFactory();
Microservice microservice = factory.create(configuration);
Assert.assertEquals(",", microservice.getDescription());
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project java-chassis by ServiceComb.
the class TestClientHttp method testServiceRegistryClientImpl.
@SuppressWarnings("unchecked")
@Test
public void testServiceRegistryClientImpl(@Mocked IpPortManager manager) {
Configuration configuration = ConfigUtil.createLocalConfig();
configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_APPLICATION, "app");
configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_NAME, "ms");
IpPort ipPort = new IpPort("127.0.0.1", 8853);
new Expectations() {
{
manager.getAvailableAddress();
result = ipPort;
}
};
new MockUp<RegistryUtils>() {
@Mock
Microservice getMicroservice() {
return microservice;
}
};
new MockUp<CountDownLatch>() {
@Mock
public void await() throws InterruptedException {
}
};
new MockUp<RestClientUtil>() {
@Mock
void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
}
};
new MockUp<WebsocketClientUtil>() {
@Mock
void open(IpPort ipPort, String url, Handler<Void> onOpen, Handler<Void> onClose, Handler<Buffer> onMessage, Handler<Throwable> onException, Handler<Throwable> onConnectFailed) {
}
};
// mock up this two client pool, since this UT case doesn't require the client pool actually boot up.
new MockUp<HttpClientPool>() {
@Mock
void create() {
}
};
new MockUp<WebsocketClientPool>() {
@Mock
void create() {
}
};
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
Microservice microservice = microserviceFactory.create(configuration);
ServiceRegistryClientImpl oClient = new ServiceRegistryClientImpl(ServiceRegistryConfig.INSTANCE);
oClient.init();
oClient.registerMicroservice(microservice);
oClient.registerMicroserviceInstance(microservice.getInstance());
Assert.assertNull(oClient.getMicroservice(microservice.getServiceId()));
Assert.assertNull(oClient.getMicroserviceInstance("testConsumerID", "testproviderID"));
Assert.assertNull(oClient.findServiceInstance(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
Assert.assertNull(oClient.findServiceInstances(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), "0"));
Assert.assertNull(oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), microservice.getEnvironment()));
Assert.assertNull(oClient.heartbeat(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
oClient.watch("", Mockito.mock(AsyncResultCallback.class));
Assert.assertFalse(oClient.unregisterMicroserviceInstance(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project incubator-servicecomb-java-chassis by apache.
the class TestServiceRegistryClientImpl method testPrivateMethodCreateHttpClientOptions.
@Test
public void testPrivateMethodCreateHttpClientOptions() {
ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_APPLICATION, "app");
ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_NAME, "ms");
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
Microservice microservice = microserviceFactory.create();
oClient.registerMicroservice(microservice);
oClient.registerMicroserviceInstance(microservice.getInstance());
try {
oClient.init();
HttpClientOptions httpClientOptions = Deencapsulation.invoke(oClient, "createHttpClientOptions");
Assert.assertNotNull(httpClientOptions);
Assert.assertEquals(80, httpClientOptions.getDefaultPort());
} catch (Exception e) {
Assert.assertNotNull(e);
}
ArchaiusUtils.resetConfig();
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project incubator-servicecomb-java-chassis by apache.
the class TestServiceRegistryClientImpl method testException.
@Test
public void testException() {
ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_APPLICATION, "app");
ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_NAME, "ms");
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
Microservice microservice = microserviceFactory.create();
Assert.assertNull(oClient.registerMicroservice(microservice));
Assert.assertNull(oClient.registerMicroserviceInstance(microservice.getInstance()));
oClient.init();
Assert.assertNull(oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), microservice.getEnvironment()));
Assert.assertThat(oClient.getAllMicroservices().isEmpty(), is(true));
Assert.assertNull(oClient.registerMicroservice(microservice));
Assert.assertNull(oClient.getMicroservice("microserviceId"));
Assert.assertNull(oClient.getMicroserviceInstance("consumerId", "providerId"));
Assert.assertFalse(oClient.unregisterMicroserviceInstance("microserviceId", "microserviceInstanceId"));
Assert.assertNull(oClient.heartbeat("microserviceId", "microserviceInstanceId"));
Assert.assertNull(oClient.findServiceInstance("selfMicroserviceId", "appId", "serviceName", "versionRule"));
Assert.assertNull(oClient.findServiceInstances("selfMicroserviceId", "appId", "serviceName", "versionRule", "0"));
Assert.assertEquals("a", new ClientException("a").getMessage());
ArchaiusUtils.resetConfig();
}
Aggregations