use of org.apache.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class TestClientHttp method testRequestContext.
@Test
public void testRequestContext() {
RequestContext oContext = new RequestContext();
oContext.setUri("//test");
oContext.setMethod(io.vertx.core.http.HttpMethod.POST);
oContext.setIpPort(new IpPort("145.0.0.1", 8080));
oContext.setParams(null);
Assert.assertEquals("//test", oContext.getUri());
Assert.assertEquals(io.vertx.core.http.HttpMethod.POST, oContext.getMethod());
Assert.assertEquals(8080, oContext.getIpPort().getPort());
Assert.assertNull(oContext.getParams());
RestResponse oResponse = new RestResponse(null, null);
oResponse.setRequestContext(oContext);
Assert.assertEquals(oContext, oResponse.getRequestContext());
Assert.assertNull(oResponse.getResponse());
}
use of org.apache.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class TestClientHttp method testIpPortManager.
@Test
public void testIpPortManager() {
IpPortManager oManager = new IpPortManager(ServiceRegistryConfig.INSTANCE);
IpPort oIPPort = oManager.getAvailableAddress();
Assert.assertEquals(oIPPort.getHostOrIp(), oManager.getAvailableAddress().getHostOrIp());
}
use of org.apache.servicecomb.foundation.common.net.IpPort 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.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method registerMicroservice.
@Override
public String registerMicroservice(Microservice microservice) {
Holder<CreateServiceResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
try {
CreateServiceRequest request = new CreateServiceRequest();
request.setService(microservice);
byte[] body = JsonUtils.writeValueAsBytes(request);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("register microservice: {}", new String(body, Charset.defaultCharset()));
}
CountDownLatch countDownLatch = new CountDownLatch(1);
restClientUtil.post(ipPort, Const.REGISTRY_API.MICROSERVICE_OPERATION_ALL, new RequestParam().setBody(body), syncHandler(countDownLatch, CreateServiceResponse.class, holder));
countDownLatch.await();
if (holder.value != null) {
return holder.value.getServiceId();
}
} catch (Exception e) {
LOGGER.error("register microservice {}/{}/{} failed", microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), e);
}
return null;
}
use of org.apache.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method getServiceCenterInfo.
@Override
public ServiceCenterInfo getServiceCenterInfo() {
Holder<ServiceCenterInfo> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
CountDownLatch countDownLatch = new CountDownLatch(1);
restClientUtil.get(ipPort, Const.REGISTRY_API.SERVICECENTER_VERSION, new RequestParam(), syncHandler(countDownLatch, ServiceCenterInfo.class, holder));
try {
countDownLatch.await();
if (holder.value != null) {
return holder.value;
}
} catch (Exception e) {
LOGGER.error("query servicecenter version info failed.", e);
}
return null;
}
Aggregations