Search in sources :

Example 1 with TcpData

use of io.servicecomb.foundation.vertx.client.tcp.TcpData in project java-chassis by ServiceComb.

the class TestTcp method testTcpData.

@Test
public void testTcpData() {
    Buffer hBuffer = Mockito.mock(Buffer.class);
    Buffer bBuffer = Mockito.mock(Buffer.class);
    TcpData tcpData = new TcpData(hBuffer, bBuffer);
    tcpData.getBodyBuffer();
    tcpData.setBodyBuffer(bBuffer);
    tcpData.getHeaderBuffer();
    tcpData.setBodyBuffer(hBuffer);
    Assert.assertNotNull(tcpData.getBodyBuffer());
    Assert.assertNotNull(tcpData.getHeaderBuffer());
}
Also used : Buffer(io.vertx.core.buffer.Buffer) TcpData(io.servicecomb.foundation.vertx.client.tcp.TcpData) Test(org.junit.Test)

Example 2 with TcpData

use of io.servicecomb.foundation.vertx.client.tcp.TcpData in project java-chassis by ServiceComb.

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<String, String>());
    header.getContext().put("a", "10");
    Buffer responseBuf = HighwayCodec.encodeResponse(0, header, null, null);
    TcpData tcp = new TcpData(responseBuf.slice(23, responseBuf.length()), null);
    Response response = HighwayCodec.decodeResponse(invocation, operationProtobuf, tcp);
    Assert.assertEquals("10", invocation.getContext().get("a"));
    Assert.assertEquals(200, response.getStatusCode());
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(io.vertx.core.buffer.Buffer) Response(io.servicecomb.core.Response) ResponseHeader(io.servicecomb.transport.highway.message.ResponseHeader) Invocation(io.servicecomb.core.Invocation) HashMap(java.util.HashMap) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) NotWrapSchema(io.servicecomb.codec.protobuf.utils.schema.NotWrapSchema) TcpData(io.servicecomb.foundation.vertx.client.tcp.TcpData) Test(org.junit.Test)

Aggregations

TcpData (io.servicecomb.foundation.vertx.client.tcp.TcpData)2 Buffer (io.vertx.core.buffer.Buffer)2 Test (org.junit.Test)2 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)1 NotWrapSchema (io.servicecomb.codec.protobuf.utils.schema.NotWrapSchema)1 Invocation (io.servicecomb.core.Invocation)1 Response (io.servicecomb.core.Response)1 ResponseHeader (io.servicecomb.transport.highway.message.ResponseHeader)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1