use of com.alibaba.dubbo.remoting.exchange.Response in project dubbo by alibaba.
the class ExchangeCodecTest method test_Header_Response_Heartbeat.
@Test
public void test_Header_Response_Heartbeat() throws IOException {
// 00000010-response/oneway/hearbeat=true |20-stats=ok|id=0|length=0
byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, 0x02, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Response obj = (Response) decode(request);
Assert.assertEquals(20, obj.getStatus());
Assert.assertEquals(person, obj.getResult());
System.out.println(obj);
}
use of com.alibaba.dubbo.remoting.exchange.Response 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);
Assert.assertEquals(response.getId(), obj.getId());
Assert.assertEquals(response.getStatus(), obj.getStatus());
Assert.assertEquals(response.isHeartbeat(), obj.isHeartbeat());
Assert.assertEquals(person, obj.getResult());
// encode response verson ??
// Assert.assertEquals(response.getVersion(), obj.getVersion());
}
use of com.alibaba.dubbo.remoting.exchange.Response in project dubbo by alibaba.
the class ExchangeCodecTest method test_Header_Response_NoSerializationFlag.
@Test
public void test_Header_Response_NoSerializationFlag() throws IOException {
// 00000010-response/oneway/hearbeat=false/noset |20-stats=ok|id=0|length=0
byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, (byte) 0x02, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Response obj = (Response) decode(request);
Assert.assertEquals(20, obj.getStatus());
Assert.assertEquals(person, obj.getResult());
System.out.println(obj);
}
use of com.alibaba.dubbo.remoting.exchange.Response in project dubbo by alibaba.
the class ExchangeCodecTest method test_Decode_Return_Response_Person.
@Test
public void test_Decode_Return_Response_Person() throws IOException {
// 00000010-response/oneway/hearbeat=false/hessian |20-stats=ok|id=0|length=0
byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, 2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Response obj = (Response) decode(request);
Assert.assertEquals(20, obj.getStatus());
Assert.assertEquals(person, obj.getResult());
System.out.println(obj);
}
use of com.alibaba.dubbo.remoting.exchange.Response in project dubbo by alibaba.
the class ExchangeCodecTest method test_Decode_Error_Length.
@Test
public void test_Decode_Error_Length() throws IOException {
byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, 0x02, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Channel channel = getServerSideChannel(url);
byte[] baddata = new byte[] { 1, 2 };
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(join(request, baddata));
Response obj = (Response) codec.decode(channel, buffer);
Assert.assertEquals(person, obj.getResult());
// only decode necessary bytes
Assert.assertEquals(request.length, buffer.readerIndex());
}
Aggregations