use of com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler in project dubbo by alibaba.
the class HeaderExchangeHandlerTest method test_received_request_event_other_discard.
@Test
public void test_received_request_event_other_discard() throws RemotingException {
final Request request = new Request();
request.setTwoWay(true);
request.setEvent("my event");
final Channel mchannel = new MockedChannel() {
@Override
public void send(Object message) throws RemotingException {
Assert.fail();
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler() {
@Override
public Object reply(ExchangeChannel channel, Object request) throws RemotingException {
Assert.fail();
throw new RemotingException(channel, "");
}
@Override
public void received(Channel channel, Object message) throws RemotingException {
Assert.fail();
throw new RemotingException(channel, "");
}
});
hexhandler.received(mchannel, request);
}
use of com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler in project dubbo by alibaba.
the class HeaderExchangeHandlerTest method test_received_request_event_readonly.
@Test
public void test_received_request_event_readonly() throws RemotingException {
final Request request = new Request();
request.setTwoWay(true);
request.setEvent(Request.READONLY_EVENT);
final Channel mchannel = new MockedChannel();
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler());
hexhandler.received(mchannel, request);
Assert.assertTrue(mchannel.hasAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY));
}
use of com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler in project dubbo by alibaba.
the class HeaderExchangeHandlerTest method test_received_request_twoway_error_reqeustBroken.
@Test
public void test_received_request_twoway_error_reqeustBroken() throws RemotingException {
final Request request = new Request();
request.setTwoWay(true);
request.setData(new BizException());
request.setBroken(true);
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.BAD_REQUEST, res.getStatus());
Assert.assertNull(res.getResult());
Assert.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
count.incrementAndGet();
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler());
hexhandler.received(mchannel, request);
Assert.assertEquals(1, count.get());
}
use of com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler 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.support.header.HeaderExchangeHandler 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());
}
Aggregations