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);
}
});
});
}
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);
}
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;
}
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);
}
Aggregations