Search in sources :

Example 6 with WrapSchema

use of io.servicecomb.codec.protobuf.utils.WrapSchema 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 7 with WrapSchema

use of io.servicecomb.codec.protobuf.utils.WrapSchema 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)

Example 8 with WrapSchema

use of io.servicecomb.codec.protobuf.utils.WrapSchema in project java-chassis by ServiceComb.

the class TestOperationProtobuf method testOperationProtobuf.

@Test
public void testOperationProtobuf() throws Exception {
    UnitTestMeta meta = new UnitTestMeta();
    SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(Impl.class);
    OperationMeta operationMeta = schemaMeta.findOperation("test");
    OperationProtobuf operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
    Assert.assertEquals(operationMeta, operationProtobuf.getOperationMeta());
    Assert.assertEquals(ArgsNotWrapSchema.class, operationProtobuf.getRequestSchema().getClass());
    Assert.assertEquals(NormalWrapSchema.class, operationProtobuf.getResponseSchema().getClass());
    WrapSchema responseSchema = operationProtobuf.findResponseSchema(200);
    Assert.assertEquals(operationProtobuf.getResponseSchema(), responseSchema);
    responseSchema = operationProtobuf.findResponseSchema(300);
    Assert.assertNotNull(responseSchema);
    Assert.assertNotEquals(operationProtobuf.getResponseSchema(), responseSchema);
}
Also used : UnitTestMeta(io.servicecomb.core.unittest.UnitTestMeta) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) ArgsNotWrapSchema(io.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) NormalWrapSchema(io.servicecomb.codec.protobuf.utils.schema.NormalWrapSchema) Test(org.junit.Test)

Example 9 with WrapSchema

use of io.servicecomb.codec.protobuf.utils.WrapSchema in project java-chassis by ServiceComb.

the class HighwayCodec method decodeRequest.

public static Invocation decodeRequest(RequestHeader header, OperationProtobuf operationProtobuf, Buffer bodyBuffer) throws Exception {
    WrapSchema schema = operationProtobuf.getRequestSchema();
    Object[] args = schema.readObject(bodyBuffer);
    Invocation invocation = InvocationFactory.forProvider(highwayTransport.getEndpoint(), operationProtobuf.getOperationMeta(), args);
    invocation.setContext(header.getContext());
    return invocation;
}
Also used : Invocation(io.servicecomb.core.Invocation) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema)

Example 10 with WrapSchema

use of io.servicecomb.codec.protobuf.utils.WrapSchema in project java-chassis by ServiceComb.

the class TestGrpcCodec method testEncodeResponse.

@Test
public void testEncodeResponse() {
    boolean status = false;
    try {
        OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
        WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
        Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
        HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
        Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
        Invocation invocation = Mockito.mock(Invocation.class);
        Response response = Mockito.mock(Response.class);
        Mockito.when(response.getResult()).thenReturn("test");
        Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
        GrpcCodec.encodeResponse(invocation, response, operationProtobuf);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : HttpClientResponse(io.vertx.core.http.HttpClientResponse) Response(io.servicecomb.core.Response) Invocation(io.servicecomb.core.Invocation) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpServerRequest(io.vertx.core.http.HttpServerRequest) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Aggregations

WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)11 Test (org.junit.Test)7 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)6 OperationMeta (io.servicecomb.core.definition.OperationMeta)6 Invocation (io.servicecomb.core.Invocation)5 Buffer (io.vertx.core.buffer.Buffer)4 HttpServerRequest (io.vertx.core.http.HttpServerRequest)4 Response (io.servicecomb.core.Response)3 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)3 HttpClientResponse (io.vertx.core.http.HttpClientResponse)3 Endpoint (io.servicecomb.core.Endpoint)2 ResponseHeader (io.servicecomb.transport.highway.message.ResponseHeader)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 ArgsNotWrapSchema (io.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema)1 NormalWrapSchema (io.servicecomb.codec.protobuf.utils.schema.NormalWrapSchema)1 NotWrapSchema (io.servicecomb.codec.protobuf.utils.schema.NotWrapSchema)1 AsyncResponse (io.servicecomb.core.AsyncResponse)1 InvocationException (io.servicecomb.core.exception.InvocationException)1 UnitTestMeta (io.servicecomb.core.unittest.UnitTestMeta)1 IpPort (io.servicecomb.foundation.common.net.IpPort)1