Search in sources :

Example 1 with GetExistenceResponse

use of org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse in project java-chassis by ServiceComb.

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);
    restClientUtil.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());
}
Also used : IpPort(org.apache.servicecomb.foundation.common.net.IpPort) CountDownLatch(java.util.concurrent.CountDownLatch) GetExistenceResponse(org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with GetExistenceResponse

use of org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse in project java-chassis by ServiceComb.

the class ServiceRegistryClientImpl method getMicroserviceId.

@Override
public String getMicroserviceId(String appId, String microserviceName, String versionRule, String environment) {
    Holder<GetExistenceResponse> holder = new Holder<>();
    IpPort ipPort = ipPortManager.getAvailableAddress();
    CountDownLatch countDownLatch = new CountDownLatch(1);
    restClientUtil.get(ipPort, Const.REGISTRY_API.MICROSERVICE_EXISTENCE, new RequestParam().addQueryParam("type", "microservice").addQueryParam("appId", appId).addQueryParam("serviceName", microserviceName).addQueryParam("version", versionRule).addQueryParam("env", environment), 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;
}
Also used : IpPort(org.apache.servicecomb.foundation.common.net.IpPort) CountDownLatch(java.util.concurrent.CountDownLatch) GetExistenceResponse(org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with GetExistenceResponse

use of org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse in project java-chassis by ServiceComb.

the class TestServiceRegistryClientImpl method isSchemaExist.

@Test
public void isSchemaExist() {
    String microserviceId = "msId";
    String schemaId = "schemaId";
    new MockUp<RestClientUtil>() {

        @Mock
        void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
            Holder<GetExistenceResponse> holder = Deencapsulation.getField(responseHandler, "arg$4");
            holder.value = new GetExistenceResponse();
        }
    };
    Assert.assertFalse(oClient.isSchemaExist(microserviceId, schemaId));
}
Also used : Handler(io.vertx.core.Handler) MockUp(mockit.MockUp) GetExistenceResponse(org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse) Test(org.junit.Test)

Example 4 with GetExistenceResponse

use of org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse in project java-chassis by ServiceComb.

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);
}
Also used : Expectations(mockit.Expectations) Buffer(io.vertx.core.buffer.Buffer) Handler(io.vertx.core.Handler) MockUp(mockit.MockUp) CountDownLatch(java.util.concurrent.CountDownLatch) GetExistenceResponse(org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse) Test(org.junit.Test)

Example 5 with GetExistenceResponse

use of org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse in project incubator-servicecomb-java-chassis by apache.

the class TestServiceRegistryClientImpl method isSchemaExist.

@Test
public void isSchemaExist() {
    String microserviceId = "msId";
    String schemaId = "schemaId";
    new MockUp<RestUtils>() {

        @Mock
        void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
            Holder<GetExistenceResponse> holder = Deencapsulation.getField(responseHandler, "arg$4");
            holder.value = new GetExistenceResponse();
        }
    };
    Assert.assertFalse(oClient.isSchemaExist(microserviceId, schemaId));
}
Also used : Handler(io.vertx.core.Handler) MockUp(mockit.MockUp) GetExistenceResponse(org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse) Test(org.junit.Test)

Aggregations

GetExistenceResponse (org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse)8 CountDownLatch (java.util.concurrent.CountDownLatch)6 Handler (io.vertx.core.Handler)4 MockUp (mockit.MockUp)4 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)4 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)4 Test (org.junit.Test)4 Holder (javax.xml.ws.Holder)3 Buffer (io.vertx.core.buffer.Buffer)2 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Expectations (mockit.Expectations)2