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