use of org.apache.servicecomb.foundation.vertx.client.tcp.TcpData in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayCodec method testDecodeResponse.
@Test
public void testDecodeResponse() throws Exception {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(operationProtobuf.findResponseSchema(200)).thenReturn(Mockito.mock(WrapSchema.class));
Map<String, String> context = new HashMap<>();
Mockito.when(invocation.getContext()).thenReturn(context);
TcpData tcpData = Mockito.mock(TcpData.class);
Mockito.when(tcpData.getHeaderBuffer()).thenReturn(bodyBuffer);
commonMock();
ResponseHeader header = new ResponseHeader();
header.setStatusCode(200);
header.setContext(new HashMap<>());
header.getContext().put("a", "10");
Buffer responseBuf = HighwayCodec.encodeResponse(0, header, null, null, new ProtobufFeature());
TcpData tcp = new TcpData(responseBuf.slice(23, responseBuf.length()), null);
Response response = HighwayCodec.decodeResponse(invocation, operationProtobuf, tcp, null);
Assert.assertEquals("10", invocation.getContext().get("a"));
Assert.assertEquals(200, response.getStatusCode());
}
use of org.apache.servicecomb.foundation.vertx.client.tcp.TcpData 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;
}
Aggregations