use of com.alibaba.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ExchangeCodecTest method testMessageLengthExceedPayloadLimitWhenEncode.
@Test
public void testMessageLengthExceedPayloadLimitWhenEncode() throws Exception {
Request request = new Request(1L);
request.setData("hello");
ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(512);
AbstractMockChannel channel = getCliendSideChannel(url.addParameter(Constants.PAYLOAD_KEY, 4));
try {
codec.encode(channel, encodeBuffer, request);
Assert.fail();
} catch (IOException e) {
Assert.assertTrue(e.getMessage().startsWith("Data length too large: " + 6));
}
Response response = new Response(1L);
response.setResult("hello");
encodeBuffer = ChannelBuffers.dynamicBuffer(512);
channel = getServerSideChannel(url.addParameter(Constants.PAYLOAD_KEY, 4));
codec.encode(channel, encodeBuffer, response);
Assert.assertTrue(channel.getReceivedMessage() instanceof Response);
Response receiveMessage = (Response) channel.getReceivedMessage();
Assert.assertEquals(Response.BAD_RESPONSE, receiveMessage.getStatus());
Assert.assertTrue(receiveMessage.getErrorMessage().contains("Data length too large: "));
}
use of com.alibaba.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ExchangeCodecTest method test_Decode_Error_Request_Object.
@Test
public void test_Decode_Error_Request_Object() throws IOException {
// 00000010-response/oneway/hearbeat=true |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);
// bad object
byte[] badbytes = new byte[] { -1, -2, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4 };
System.arraycopy(badbytes, 0, request, 21, badbytes.length);
Request obj = (Request) decode(request);
Assert.assertEquals(true, obj.isBroken());
Assert.assertEquals(true, obj.getData() instanceof Throwable);
}
use of com.alibaba.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class HeartBeatTaskTest method testHeartBeat.
@Test
public void testHeartBeat() throws Exception {
url = url.addParameter(Constants.DUBBO_VERSION_KEY, "2.1.1");
channel.setAttribute(HeaderExchangeHandler.KEY_READ_TIMESTAMP, System.currentTimeMillis());
channel.setAttribute(HeaderExchangeHandler.KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
Thread.sleep(2000L);
task.run();
List<Object> objects = channel.getSentObjects();
Assert.assertTrue(objects.size() > 0);
Object obj = objects.get(0);
Assert.assertTrue(obj instanceof Request);
Request request = (Request) obj;
Assert.assertTrue(request.isHeartbeat());
}
use of com.alibaba.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class HeaderExchangeHandlerTest method test_received_request_twoway_error_reply.
@Test
public void test_received_request_twoway_error_reply() throws RemotingException {
final Person requestdata = new Person("charles");
final Request request = new Request();
request.setTwoWay(true);
request.setData(requestdata);
final AtomicInteger count = new AtomicInteger(0);
final Channel mchannel = new MockedChannel() {
@Override
public void send(Object message) throws RemotingException {
Response res = (Response) message;
Assert.assertEquals(request.getId(), res.getId());
Assert.assertEquals(request.getVersion(), res.getVersion());
Assert.assertEquals(Response.SERVICE_ERROR, res.getStatus());
Assert.assertNull(res.getResult());
Assert.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
count.incrementAndGet();
}
};
ExchangeHandler exhandler = new MockedExchangeHandler() {
@Override
public Object reply(ExchangeChannel channel, Object request) throws RemotingException {
throw new BizException();
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
hexhandler.received(mchannel, request);
Assert.assertEquals(1, count.get());
}
use of com.alibaba.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class HeaderExchangeHandlerTest method test_received_request_oneway.
@Test
public void test_received_request_oneway() throws RemotingException {
final Channel mchannel = new MockedChannel();
final Person requestdata = new Person("charles");
Request request = new Request();
request.setTwoWay(false);
request.setData(requestdata);
ExchangeHandler exhandler = new MockedExchangeHandler() {
public void received(Channel channel, Object message) throws RemotingException {
Assert.assertEquals(requestdata, message);
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
hexhandler.received(mchannel, request);
}
Aggregations