Search in sources :

Example 11 with OperationMeta

use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.

the class TestGrpcCodec method testDecodeResponse.

@Test
public void testDecodeResponse() {
    boolean status = false;
    try {
        RoutingContext routingContext = Mockito.mock(RoutingContext.class);
        OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
        OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
        WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
        Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
        Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
        Buffer bodyBuffer = Mockito.mock(Buffer.class);
        Mockito.when(routingContext.getBody()).thenReturn(bodyBuffer);
        HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
        Mockito.when(routingContext.request()).thenReturn(request);
        Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
        Invocation invocation = Mockito.mock(Invocation.class);
        Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
        HttpClientResponse httpResponse = Mockito.mock(HttpClientResponse.class);
        Buffer buffer = Mockito.mock(Buffer.class);
        GrpcCodec.decodeResponse(invocation, operationProtobuf, httpResponse, buffer);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) RoutingContext(io.vertx.ext.web.RoutingContext) Invocation(io.servicecomb.core.Invocation) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpServerRequest(io.vertx.core.http.HttpServerRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Example 12 with OperationMeta

use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.

the class TestGrpcCodec method testDecodeRequest.

@Test
public void testDecodeRequest() {
    boolean status = false;
    try {
        RoutingContext routingContext = Mockito.mock(RoutingContext.class);
        OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
        OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
        WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
        Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
        Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
        Buffer bodyBuffer = Mockito.mock(Buffer.class);
        Mockito.when(routingContext.getBody()).thenReturn(bodyBuffer);
        HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
        Mockito.when(routingContext.request()).thenReturn(request);
        SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class);
        Mockito.when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta);
        Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
        GrpcCodec.setGrpcTransport(new GrpcTransport());
        GrpcCodec.decodeRequest(routingContext, operationMeta);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) RoutingContext(io.vertx.ext.web.RoutingContext) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpServerRequest(io.vertx.core.http.HttpServerRequest) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Example 13 with OperationMeta

use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.

the class TestGrpcTransport method testSend.

@Test
public void testSend() {
    boolean status = false;
    Invocation invocation = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
    Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
    Endpoint lEndpoint = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
    WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
    Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
    IpPort ipPort = Mockito.mock(IpPort.class);
    Mockito.when(lEndpoint.getAddress()).thenReturn(ipPort);
    Mockito.when(ipPort.getHostOrIp()).thenReturn("127.0.0.1");
    Mockito.when(ipPort.getPort()).thenReturn(80);
    new MockUp<ClientPoolManager<HttpClientWithContext>>() {

        @Mock
        public HttpClientWithContext findThreadBindClientPool() {
            return Mockito.mock(HttpClientWithContext.class);
        }
    };
    try {
        transport.send(invocation, asyncResp);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : Invocation(io.servicecomb.core.Invocation) Endpoint(io.servicecomb.core.Endpoint) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpClientWithContext(io.servicecomb.foundation.vertx.client.http.HttpClientWithContext) IpPort(io.servicecomb.foundation.common.net.IpPort) MockUp(mockit.MockUp) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 14 with OperationMeta

use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.

the class VertxHttpMethod method doMethod.

public void doMethod(HttpClientWithContext httpClientWithContext, Invocation invocation, AsyncResponse asyncResp) throws Exception {
    OperationMeta operationMeta = invocation.getOperationMeta();
    RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    String path = this.createRequestPath(invocation, swaggerRestOperation);
    IpPort ipPort = (IpPort) invocation.getEndpoint().getAddress();
    HttpClientRequest clientRequest = this.createRequest(httpClientWithContext.getHttpClient(), invocation, ipPort, path, swaggerRestOperation, asyncResp);
    RestClientRequestImpl restClientRequest = new RestClientRequestImpl(clientRequest);
    RestCodec.argsToRest(invocation.getArgs(), swaggerRestOperation, restClientRequest);
    clientRequest.exceptionHandler(e -> {
        LOGGER.error(e.toString());
        asyncResp.fail(invocation.getInvocationType(), e);
    });
    // 从业务线程转移到网络线程中去发送
    httpClientWithContext.runOnContext(httpClient -> {
        this.setCseContext(invocation, clientRequest);
        clientRequest.setTimeout(AbstractTransport.getRequestTimeout());
        try {
            restClientRequest.end();
        } catch (Exception e) {
            LOGGER.error("send http reqeust failed,", e);
            asyncResp.fail(invocation.getInvocationType(), e);
        }
    });
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) RestClientRequestImpl(io.servicecomb.common.rest.codec.param.RestClientRequestImpl) IpPort(io.servicecomb.foundation.common.net.IpPort) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta)

Example 15 with OperationMeta

use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.

the class TestHighwayTransport method commonHighwayMock.

private void commonHighwayMock(Invocation invocation) {
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
    Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
    Endpoint lEndpoint = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
    WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
    Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
    URIEndpointObject ep = Mockito.mock(URIEndpointObject.class);
    Mockito.when(lEndpoint.getAddress()).thenReturn(ep);
    Mockito.when(ep.getHostOrIp()).thenReturn("127.0.0.1");
    Mockito.when(ep.getPort()).thenReturn(80);
}
Also used : Endpoint(io.servicecomb.core.Endpoint) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject)

Aggregations

OperationMeta (io.servicecomb.core.definition.OperationMeta)36 Test (org.junit.Test)18 Invocation (io.servicecomb.core.Invocation)15 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)12 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)8 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)8 MockUp (mockit.MockUp)7 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)6 AsyncResponse (io.servicecomb.core.AsyncResponse)6 Endpoint (io.servicecomb.core.Endpoint)6 Response (io.servicecomb.core.Response)5 InvocationException (io.servicecomb.core.exception.InvocationException)5 HttpClientResponse (io.vertx.core.http.HttpClientResponse)5 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)4 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)4 HttpClientWithContext (io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)4 Buffer (io.vertx.core.buffer.Buffer)4 ConsumerOperationMeta (io.servicecomb.core.provider.consumer.ConsumerOperationMeta)3 IpPort (io.servicecomb.foundation.common.net.IpPort)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)3