use of org.apache.servicecomb.registry.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) {
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 TestMicroserviceFactory method testSetDescriptionOnNullDescription.
@Test
public void testSetDescriptionOnNullDescription() {
Configuration configuration = ConfigUtil.createLocalConfig();
configuration.clearProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION);
MicroserviceFactory factory = new MicroserviceFactory();
Microservice microservice = factory.create(configuration);
Assert.assertNull(microservice.getDescription());
configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION, new String[] {});
microservice = factory.create(configuration);
Assert.assertNull(microservice.getDescription());
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project incubator-servicecomb-java-chassis by apache.
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 incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceFactory method testCreateMicroserviceFromDefinitionWithInvalidVersion.
@Test
public void testCreateMicroserviceFromDefinitionWithInvalidVersion() {
Configuration configuration = ConfigUtil.createLocalConfig();
configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_VERSION, "x.y.x.1");
expectedException.equals(IllegalStateException.class);
expectedException.expectMessage("Invalid major \"x\", version \"x.y.x.1\".");
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
microserviceFactory.create(configuration);
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceFactory method testSetDescription.
@Test
public void testSetDescription() {
MicroserviceFactory factory = new MicroserviceFactory();
Configuration configuration = ConfigUtil.createLocalConfig();
configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION, new String[] { "test1", "test2" });
Microservice microservice = factory.create(configuration);
Assert.assertEquals("test1,test2", microservice.getDescription());
}
Aggregations