Search in sources :

Example 1 with OperationProtobuf

use of org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf in project incubator-servicecomb-java-chassis by apache.

the class HighwayClient method send.

public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
    HighwayClientConnectionPool tcpClientPool = clientMgr.findClientPool(invocation.isSync());
    OperationMeta operationMeta = invocation.getOperationMeta();
    OperationProtobuf operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
    HighwayClientConnection tcpClient = tcpClientPool.findOrCreateClient(invocation.getEndpoint().getEndpoint());
    HighwayClientPackage clientPackage = new HighwayClientPackage(invocation, operationProtobuf, tcpClient);
    LOGGER.debug("Sending request by highway, qualifiedName={}, endpoint={}.", invocation.getMicroserviceQualifiedName(), invocation.getEndpoint().getEndpoint());
    tcpClient.send(clientPackage, ar -> {
        // 此时是在网络线程中,转换线程
        invocation.getResponseExecutor().execute(() -> {
            if (ar.failed()) {
                // 只会是本地异常
                asyncResp.consumerFail(ar.cause());
                return;
            }
            // 处理应答
            try {
                Response response = HighwayCodec.decodeResponse(invocation, operationProtobuf, ar.result(), tcpClient.getProtobufFeature());
                asyncResp.complete(response);
            } catch (Throwable e) {
                asyncResp.consumerFail(e);
            }
        });
    });
}
Also used : AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) Response(org.apache.servicecomb.swagger.invocation.Response) OperationProtobuf(org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta)

Example 2 with OperationProtobuf

use of org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf in project incubator-servicecomb-java-chassis by apache.

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(org.apache.servicecomb.core.Endpoint) OperationProtobuf(org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Example 3 with OperationProtobuf

use of org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayClient method doTestSend.

private Object doTestSend(Vertx vertx, HighwayClientConnectionPool pool, HighwayClientConnection tcpClient, Object decodedResponse) throws Exception {
    new MockUp<VertxUtils>() {

        @Mock
        <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx, Class<VERTICLE> cls, DeploymentOptions options) throws InterruptedException {
            return true;
        }
    };
    new MockUp<ClientPoolManager<HighwayClientConnectionPool>>() {

        @Mock
        public HighwayClientConnectionPool findClientPool(boolean sync) {
            return pool;
        }
    };
    new MockUp<ProtobufManager>() {

        @Mock
        public OperationProtobuf getOrCreateOperation(OperationMeta operationMeta) throws Exception {
            return operationProtobuf;
        }
    };
    new MockUp<HighwayClientConnectionPool>() {

        @Mock
        HighwayClientConnection findOrCreateClient(String endpoint) {
            return tcpClient;
        }
    };
    new MockUp<HighwayCodec>() {

        @Mock
        public Buffer encodeRequest(Invocation invocation, OperationProtobuf operationProtobuf, long msgId) throws Exception {
            return null;
        }

        @Mock
        Response decodeResponse(Invocation invocation, OperationProtobuf operationProtobuf, TcpData tcpData, ProtobufFeature protobufFeature) throws Throwable {
            if (Response.class.isInstance(decodedResponse)) {
                return (Response) decodedResponse;
            }
            throw (Throwable) decodedResponse;
        }
    };
    client.init(vertx);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    Mockito.when(invocation.getEndpoint()).thenReturn(endpoint);
    Mockito.when(invocation.getEndpoint().getEndpoint()).thenReturn("endpoint");
    Mockito.when(invocation.getResponseExecutor()).thenReturn(new ReactiveExecutor());
    Holder<Object> result = new Holder<>();
    client.send(invocation, ar -> {
        result.value = ar.getResult();
    });
    return result.value;
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Holder(javax.xml.ws.Holder) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) MockUp(mockit.MockUp) Vertx(io.vertx.core.Vertx) AbstractVerticle(io.vertx.core.AbstractVerticle) TcpData(org.apache.servicecomb.foundation.vertx.client.tcp.TcpData) ProtobufFeature(io.protostuff.runtime.ProtobufFeature) Response(org.apache.servicecomb.swagger.invocation.Response) DeploymentOptions(io.vertx.core.DeploymentOptions) OperationProtobuf(org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf) BeforeClass(org.junit.BeforeClass) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta)

Example 4 with OperationProtobuf

use of org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayCodec method setUp.

@Before
public void setUp() throws Exception {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    RegistryUtils.setServiceRegistry(serviceRegistry);
    header = Mockito.mock(RequestHeader.class);
    operationProtobuf = Mockito.mock(OperationProtobuf.class);
    bodyBuffer = Mockito.mock(Buffer.class);
    schema = Mockito.mock(WrapSchema.class);
    schemaMeta = Mockito.mock(SchemaMeta.class);
    operationMeta = Mockito.mock(OperationMeta.class);
    lByteBuf = Mockito.mock(ByteBuf.class);
    nioBuffer = Mockito.mock(ByteBuffer.class);
    invocation = Mockito.mock(Invocation.class);
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(io.vertx.core.buffer.Buffer) Invocation(org.apache.servicecomb.core.Invocation) OperationProtobuf(org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) RequestHeader(org.apache.servicecomb.transport.highway.message.RequestHeader) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) NotWrapSchema(org.apache.servicecomb.codec.protobuf.utils.schema.NotWrapSchema) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) ByteBuf(io.netty.buffer.ByteBuf) ByteBuffer(java.nio.ByteBuffer) Before(org.junit.Before)

Aggregations

OperationProtobuf (org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf)4 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)4 WrapSchema (org.apache.servicecomb.codec.protobuf.utils.WrapSchema)2 Invocation (org.apache.servicecomb.core.Invocation)2 Response (org.apache.servicecomb.swagger.invocation.Response)2 ByteBuf (io.netty.buffer.ByteBuf)1 ProtobufFeature (io.protostuff.runtime.ProtobufFeature)1 AbstractVerticle (io.vertx.core.AbstractVerticle)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 Vertx (io.vertx.core.Vertx)1 Buffer (io.vertx.core.buffer.Buffer)1 ByteBuffer (java.nio.ByteBuffer)1 Holder (javax.xml.ws.Holder)1 MockUp (mockit.MockUp)1 NotWrapSchema (org.apache.servicecomb.codec.protobuf.utils.schema.NotWrapSchema)1 Endpoint (org.apache.servicecomb.core.Endpoint)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 ReactiveExecutor (org.apache.servicecomb.core.executor.ReactiveExecutor)1 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)1 TcpData (org.apache.servicecomb.foundation.vertx.client.tcp.TcpData)1