use of org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse in project incubator-servicecomb-java-chassis by apache.
the class TestServiceRegistryClientImpl method syncHandler_failed.
@Test
public void syncHandler_failed(@Mocked RequestContext requestContext, @Mocked HttpClientResponse response) {
CountDownLatch countDownLatch = new CountDownLatch(1);
Class<GetExistenceResponse> cls = GetExistenceResponse.class;
Holder<GetExistenceResponse> holder = new Holder<>();
Handler<RestResponse> handler = oClient.syncHandler(countDownLatch, cls, holder);
Holder<Handler<Buffer>> bodyHandlerHolder = new Holder<>();
new MockUp<HttpClientResponse>(response) {
@Mock
HttpClientResponse bodyHandler(Handler<Buffer> bodyHandler) {
bodyHandlerHolder.value = bodyHandler;
return null;
}
};
new Expectations() {
{
response.statusCode();
result = 400;
response.statusMessage();
result = Status.BAD_REQUEST.getReasonPhrase();
}
};
RestResponse event = new RestResponse(requestContext, response);
handler.handle(event);
Buffer bodyBuffer = Buffer.buffer("{}");
bodyHandlerHolder.value.handle(bodyBuffer);
Assert.assertNull(holder.value);
}
use of org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse in project incubator-servicecomb-java-chassis by apache.
the class ServiceRegistryClientImpl method isSchemaExist.
@Override
public boolean isSchemaExist(String microserviceId, String schemaId) {
Holder<GetExistenceResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.get(ipPort, Const.REGISTRY_API.MICROSERVICE_EXISTENCE, new RequestParam().addQueryParam("type", "schema").addQueryParam("serviceId", microserviceId).addQueryParam("schemaId", schemaId), syncHandler(countDownLatch, GetExistenceResponse.class, holder));
try {
countDownLatch.await();
} catch (Exception e) {
LOGGER.error("query schema exist {}/{} fail", microserviceId, schemaId, e);
}
return holder.value != null && schemaId.equals(holder.value.getSchemaId());
}
use of org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse in project incubator-servicecomb-java-chassis by apache.
the class ServiceRegistryClientImpl method getMicroserviceId.
@Override
public String getMicroserviceId(String appId, String microserviceName, String versionRule) {
Holder<GetExistenceResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.get(ipPort, Const.REGISTRY_API.MICROSERVICE_EXISTENCE, new RequestParam().addQueryParam("type", "microservice").addQueryParam("appId", appId).addQueryParam("serviceName", microserviceName).addQueryParam("version", versionRule), syncHandler(countDownLatch, GetExistenceResponse.class, holder));
try {
countDownLatch.await();
if (holder.value != null) {
return holder.value.getServiceId();
}
} catch (Exception e) {
LOGGER.error("query microservice id {}/{}/{} fail", appId, microserviceName, versionRule, e);
}
return null;
}
Aggregations