Search in sources :

Example 1 with GetSchemasResponse

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

the class ServiceRegistryClientImpl method getSchemas.

private Holder<List<GetSchemaResponse>> getSchemas(String microserviceId, boolean withSchema, boolean global) {
    Holder<GetSchemasResponse> holder = new Holder<>();
    IpPort ipPort = ipPortManager.getAvailableAddress();
    Holder<List<GetSchemaResponse>> resultHolder = new Holder<>();
    CountDownLatch countDownLatch = new CountDownLatch(1);
    String url = Const.REGISTRY_API.MICROSERVICE_ALL_SCHEMAs;
    RequestParam requestParam = new RequestParam();
    if (withSchema) {
        url = Const.REGISTRY_API.MICROSERVICE_ALL_SCHEMAs + "?withSchema=1";
    }
    if (global) {
        requestParam.addQueryParam("global", "true");
    }
    restClientUtil.get(ipPort, String.format(url, microserviceId), requestParam, syncHandler(countDownLatch, GetSchemasResponse.class, holder));
    try {
        countDownLatch.await();
    } catch (Exception e) {
        LOGGER.error("query all schemas {} failed", microserviceId, e);
    }
    resultHolder.setStatusCode(holder.getStatusCode()).setThrowable(holder.getThrowable());
    if (holder.value != null) {
        return resultHolder.setValue(holder.value.getSchema() != null ? holder.value.getSchema() : holder.value.getSchemas());
    }
    return resultHolder;
}
Also used : GetSchemasResponse(org.apache.servicecomb.serviceregistry.api.response.GetSchemasResponse) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with GetSchemasResponse

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

the class TestServiceRegistryClientImpl method getSchemas.

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

        @Mock
        void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
            Holder<GetSchemasResponse> holder = Deencapsulation.getField(responseHandler, "arg$4");
            GetSchemasResponse schemasResp = Json.decodeValue("{\"schema\":[{\"schemaId\":\"metricsEndpoint\",\"summary\":\"c1188d709631a9038874f9efc6eb894f\"},{\"schemaId\":\"comment\",\"summary\":\"bfa81d625cfbd3a57f38745323e16824\"}," + "{\"schemaId\":\"healthEndpoint\",\"summary\":\"96a0aaaaa454cfa0c716e70c0017fe27\"}]}", GetSchemasResponse.class);
            holder.statusCode = 200;
            holder.value = schemasResp;
        }
    };
    Holder<List<GetSchemaResponse>> schemasHolder = oClient.getSchemas(microserviceId);
    List<GetSchemaResponse> schemaResponses = schemasHolder.getValue();
    Assert.assertEquals(200, schemasHolder.getStatusCode());
    Assert.assertEquals(3, schemaResponses.size());
    Assert.assertEquals("bfa81d625cfbd3a57f38745323e16824", schemaResponses.get(1).getSummary());
}
Also used : GetSchemasResponse(org.apache.servicecomb.serviceregistry.api.response.GetSchemasResponse) Handler(io.vertx.core.Handler) MockUp(mockit.MockUp) ArrayList(java.util.ArrayList) List(java.util.List) GetSchemaResponse(org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse) Test(org.junit.Test)

Example 3 with GetSchemasResponse

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

the class TestServiceRegistryClientImpl method getSchemasForNew.

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

        @Mock
        void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
            Holder<GetSchemasResponse> holder = Deencapsulation.getField(responseHandler, "arg$4");
            GetSchemasResponse schemasResp = Json.decodeValue("{\"schemas\":[{\"schemaId\":\"metricsEndpoint\",\"summary\":\"c1188d709631a9038874f9efc6eb894f\"},{\"schemaId\":\"comment\",\"summary\":\"bfa81d625cfbd3a57f38745323e16824\"}," + "{\"schemaId\":\"healthEndpoint\",\"summary\":\"96a0aaaaa454cfa0c716e70c0017fe27\"}]}", GetSchemasResponse.class);
            holder.statusCode = 200;
            holder.value = schemasResp;
        }
    };
    Holder<List<GetSchemaResponse>> schemasHolder = oClient.getSchemas(microserviceId);
    List<GetSchemaResponse> schemas = schemasHolder.getValue();
    Assert.assertEquals(200, schemasHolder.getStatusCode());
    Assert.assertEquals(3, schemas.size());
    Assert.assertEquals("bfa81d625cfbd3a57f38745323e16824", schemas.get(1).getSummary());
}
Also used : GetSchemasResponse(org.apache.servicecomb.serviceregistry.api.response.GetSchemasResponse) Handler(io.vertx.core.Handler) MockUp(mockit.MockUp) ArrayList(java.util.ArrayList) List(java.util.List) GetSchemaResponse(org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 GetSchemasResponse (org.apache.servicecomb.serviceregistry.api.response.GetSchemasResponse)3 Handler (io.vertx.core.Handler)2 MockUp (mockit.MockUp)2 GetSchemaResponse (org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Collections.emptyList (java.util.Collections.emptyList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)1 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)1