Search in sources :

Example 21 with ChannelBuffer

use of org.apache.dubbo.remoting.buffer.ChannelBuffer in project dubbo by alibaba.

the class ExchangeCodecTest method test_Encode_Response.

@Test
public void test_Encode_Response() throws IOException {
    ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(1024);
    Channel channel = getCliendSideChannel(url);
    Response response = new Response();
    response.setHeartbeat(true);
    response.setId(1001L);
    response.setStatus((byte) 20);
    response.setVersion("11");
    Person person = new Person();
    response.setResult(person);
    codec.encode(channel, encodeBuffer, response);
    byte[] data = new byte[encodeBuffer.writerIndex()];
    encodeBuffer.readBytes(data);
    // encode resault check need decode
    ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(data);
    Response obj = (Response) codec.decode(channel, decodeBuffer);
    Assertions.assertEquals(response.getId(), obj.getId());
    Assertions.assertEquals(response.getStatus(), obj.getStatus());
    Assertions.assertEquals(response.isHeartbeat(), obj.isHeartbeat());
    Assertions.assertEquals(person, obj.getResult());
// encode response verson ??
// Assertions.assertEquals(response.getProtocolVersion(), obj.getVersion());
}
Also used : Response(org.apache.dubbo.remoting.exchange.Response) Channel(org.apache.dubbo.remoting.Channel) ChannelBuffer(org.apache.dubbo.remoting.buffer.ChannelBuffer) Test(org.junit.jupiter.api.Test)

Example 22 with ChannelBuffer

use of org.apache.dubbo.remoting.buffer.ChannelBuffer in project dubbo by alibaba.

the class ExchangeCodecTest method test_Encode_Request.

@Test
public void test_Encode_Request() throws IOException {
    ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(2014);
    Channel channel = getCliendSideChannel(url);
    Request request = new Request();
    Person person = new Person();
    request.setData(person);
    codec.encode(channel, encodeBuffer, request);
    // encode resault check need decode
    byte[] data = new byte[encodeBuffer.writerIndex()];
    encodeBuffer.readBytes(data);
    ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(data);
    Request obj = (Request) codec.decode(channel, decodeBuffer);
    Assertions.assertEquals(request.isBroken(), obj.isBroken());
    Assertions.assertEquals(request.isHeartbeat(), obj.isHeartbeat());
    Assertions.assertEquals(request.isTwoWay(), obj.isTwoWay());
    Assertions.assertEquals(person, obj.getData());
}
Also used : Channel(org.apache.dubbo.remoting.Channel) Request(org.apache.dubbo.remoting.exchange.Request) ChannelBuffer(org.apache.dubbo.remoting.buffer.ChannelBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

ChannelBuffer (org.apache.dubbo.remoting.buffer.ChannelBuffer)22 Channel (org.apache.dubbo.remoting.Channel)16 Test (org.junit.jupiter.api.Test)13 Request (org.apache.dubbo.remoting.exchange.Request)9 Response (org.apache.dubbo.remoting.exchange.Response)9 Demo (org.apache.dubbo.rpc.gen.thrift.Demo)5 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)5 TMessage (org.apache.thrift.protocol.TMessage)5 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)5 URL (org.apache.dubbo.common.URL)4 AppResponse (org.apache.dubbo.rpc.AppResponse)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 TTransport (org.apache.thrift.transport.TTransport)3 DynamicChannelBuffer (org.apache.dubbo.remoting.buffer.DynamicChannelBuffer)2 DefaultFuture (org.apache.dubbo.remoting.exchange.support.DefaultFuture)2 RandomAccessByteArrayOutputStream (org.apache.dubbo.rpc.protocol.thrift.io.RandomAccessByteArrayOutputStream)2 TApplicationException (org.apache.thrift.TApplicationException)2 Buffer (org.glassfish.grizzly.Buffer)2 ByteBuf (io.netty.buffer.ByteBuf)1