use of com.alibaba.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ExchangeCodecTest method test_Decode_Return_Request_Object.
@Test
public void test_Decode_Return_Request_Object() throws IOException {
// |10011111|20-stats=ok|id=0|length=0
byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, (byte) 0xe2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Request obj = (Request) decode(request);
Assert.assertEquals(person, obj.getData());
Assert.assertEquals(true, obj.isTwoWay());
Assert.assertEquals(false, obj.isHeartbeat());
Assert.assertEquals("2.0.0", obj.getVersion());
System.out.println(obj);
}
use of com.alibaba.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ExchangeCodecTest method test_Decode_Return_Request_Event_Object.
@Test
public void test_Decode_Return_Request_Event_Object() throws IOException {
// |10011111|20-stats=ok|id=0|length=0
byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, (byte) 0xe2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Request obj = (Request) decode(request);
Assert.assertEquals(person, obj.getData());
Assert.assertEquals(true, obj.isTwoWay());
Assert.assertEquals(true, obj.isEvent());
Assert.assertEquals("2.0.0", obj.getVersion());
System.out.println(obj);
}
use of com.alibaba.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ExchangeCodecTest method testMessageLengthGreaterThanMessageActualLength.
// http://code.alibabatech.com/jira/browse/DUBBO-392
@Test
public void testMessageLengthGreaterThanMessageActualLength() throws Exception {
Channel channel = getCliendSideChannel(url);
Request request = new Request(1L);
request.setVersion("2.0.0");
Date date = new Date();
request.setData(date);
ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(1024);
codec.encode(channel, encodeBuffer, request);
byte[] bytes = new byte[encodeBuffer.writerIndex()];
encodeBuffer.readBytes(bytes);
int len = Bytes.bytes2int(bytes, 12);
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
out.write(bytes, 0, 12);
/*
* The fill length can not be less than 256, because by default, hessian reads 256 bytes from the stream each time.
* Refer Hessian2Input.readBuffer for more details
*/
int padding = 512;
out.write(Bytes.int2bytes(len + padding));
out.write(bytes, 16, bytes.length - 16);
for (int i = 0; i < padding; i++) {
out.write(1);
}
out.write(bytes);
/* request|1111...|request */
ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(out.toByteArray());
Request decodedRequest = (Request) codec.decode(channel, decodeBuffer);
Assert.assertTrue(date.equals(decodedRequest.getData()));
Assert.assertEquals(bytes.length + padding, decodeBuffer.readerIndex());
decodedRequest = (Request) codec.decode(channel, decodeBuffer);
Assert.assertTrue(date.equals(decodedRequest.getData()));
}
use of com.alibaba.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ExchangeCodecTest method test_Decode_Return_Request_Heartbeat_Object.
@Test
public void test_Decode_Return_Request_Heartbeat_Object() throws IOException {
// |10011111|20-stats=ok|id=0|length=0
byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, (byte) 0xe2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
byte[] request = getRequestBytes(null, header);
Request obj = (Request) decode(request);
Assert.assertEquals(null, obj.getData());
Assert.assertEquals(true, obj.isTwoWay());
Assert.assertEquals(true, obj.isHeartbeat());
Assert.assertEquals("2.0.0", obj.getVersion());
System.out.println(obj);
}
use of com.alibaba.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ConnectChannelHandlerTest method test_Received_Event_invoke_direct.
/**
* Events do not pass through the thread pool and execute directly on the IO
*/
@SuppressWarnings("deprecation")
@Ignore("Heartbeat is processed in HeartbeatHandler not WrappedChannelHandler.")
@Test
public void test_Received_Event_invoke_direct() throws RemotingException {
handler = new ConnectionOrderedChannelHandler(new BizChannelHander(false), url);
ThreadPoolExecutor executor = (ThreadPoolExecutor) getField(handler, "SHARED_EXECUTOR", 1);
executor.shutdown();
executor = (ThreadPoolExecutor) getField(handler, "executor", 1);
executor.shutdown();
Request req = new Request();
req.setHeartbeat(true);
final AtomicInteger count = new AtomicInteger(0);
handler.received(new MockedChannel() {
@Override
public void send(Object message) throws RemotingException {
Assert.assertEquals("response.heartbeat", true, ((Response) message).isHeartbeat());
count.incrementAndGet();
}
}, req);
Assert.assertEquals("channel.send must be invoke", 1, count.get());
}
Aggregations