use of com.alibaba.dubbo.remoting.exchange.ExchangeHandler in project dubbo by alibaba.
the class HeaderExchangeHandlerTest method test_received_request_twoway.
@Test
public void test_received_request_twoway() 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.OK, res.getStatus());
Assert.assertEquals(requestdata, res.getResult());
Assert.assertEquals(null, res.getErrorMessage());
count.incrementAndGet();
}
};
ExchangeHandler exhandler = new MockedExchangeHandler() {
@Override
public Object reply(ExchangeChannel channel, Object request) throws RemotingException {
return request;
}
public void received(Channel channel, Object message) throws RemotingException {
Assert.fail();
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
hexhandler.received(mchannel, request);
Assert.assertEquals(1, count.get());
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeHandler 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.ExchangeHandler 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