use of com.alibaba.dubbo.remoting.Channel 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.Channel 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.Channel in project dubbo by alibaba.
the class AbstractCodecTest method test_checkPayload_default8M.
public void test_checkPayload_default8M() throws Exception {
Channel channel = createMock(Channel.class);
expect(channel.getUrl()).andReturn(URL.valueOf("dubbo://1.1.1.1")).anyTimes();
replay(channel);
AbstractCodec.checkPayload(channel, 1 * 1024 * 1024);
try {
AbstractCodec.checkPayload(channel, 15 * 1024 * 1024);
} catch (IOException expected) {
assertThat(expected.getMessage(), allOf(containsString("Data length too large: "), containsString("max payload: " + 8 * 1024 * 1024)));
}
verify(channel);
}
use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class MinaServer method getChannels.
public Collection<Channel> getChannels() {
Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress());
Collection<Channel> channels = new HashSet<Channel>();
for (IoSession session : sessions) {
if (session.isConnected()) {
channels.add(MinaChannel.getOrAddChannel(session, getUrl(), this));
}
}
return channels;
}
use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class AbstractClient method send.
public void send(Object message, boolean sent) throws RemotingException {
if (send_reconnect && !isConnected()) {
connect();
}
Channel channel = getChannel();
//TODO getChannel返回的状态是否包含null需要改进
if (channel == null || !channel.isConnected()) {
throw new RemotingException(this, "message can not send, because channel is closed . url:" + getUrl());
}
channel.send(message, sent);
}
Aggregations