use of org.apache.dubbo.remoting.Channel 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;
Assertions.assertEquals(request.getId(), res.getId());
Assertions.assertEquals(request.getVersion(), res.getVersion());
Assertions.assertEquals(Response.SERVICE_ERROR, res.getStatus());
Assertions.assertNull(res.getResult());
Assertions.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
count.incrementAndGet();
}
};
ExchangeHandler exhandler = new MockedExchangeHandler() {
@Override
public CompletableFuture<Object> reply(ExchangeChannel channel, Object request) throws RemotingException {
throw new BizException();
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
hexhandler.received(mchannel, request);
Assertions.assertEquals(1, count.get());
}
use of org.apache.dubbo.remoting.Channel 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 {
Assertions.fail();
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler() {
@Override
public CompletableFuture<Object> reply(ExchangeChannel channel, Object request) throws RemotingException {
Assertions.fail();
throw new RemotingException(channel, "");
}
@Override
public void received(Channel channel, Object message) throws RemotingException {
Assertions.fail();
throw new RemotingException(channel, "");
}
});
hexhandler.received(mchannel, request);
}
use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.
the class StatusTelnetHandlerTest method test.
@Test
public void test() {
Channel channel = Mockito.mock(Channel.class);
Mockito.when(channel.getUrl()).thenReturn(URL.valueOf("dubbo://127.0.0.1:12345"));
StatusTelnetHandler statusTelnetHandler = new StatusTelnetHandler();
Assertions.assertNotNull(statusTelnetHandler.telnet(channel, ""));
Assertions.assertNotNull(statusTelnetHandler.telnet(channel, "-l"));
String errorPrompt = "Unsupported parameter ";
Assertions.assertTrue(statusTelnetHandler.telnet(channel, "other").contains(errorPrompt));
Mockito.when(channel.getUrl()).thenReturn(URL.valueOf("dubbo://127.0.0.1:12345?status=load,memory"));
Assertions.assertNotNull(statusTelnetHandler.telnet(channel, ""));
Assertions.assertNotNull(statusTelnetHandler.telnet(channel, "-l"));
}
use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.
the class AbstractCodecTest method test_checkPayload_default8M.
public void test_checkPayload_default8M() throws Exception {
Channel channel = mock(Channel.class);
given(channel.getUrl()).willReturn(URL.valueOf("dubbo://1.1.1.1"));
AbstractCodec.checkPayload(channel, 1 * 1024 * 1024);
try {
AbstractCodec.checkPayload(channel, 15 * 1024 * 1024);
} catch (IOException expected) {
assertThat(expected.getMessage(), allOf(CoreMatchers.containsString("Data length too large: "), CoreMatchers.containsString("max payload: " + 8 * 1024 * 1024)));
}
verify(channel, VerificationModeFactory.atLeastOnce()).getUrl();
}
use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.
the class MinaServer method getChannels.
@Override
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;
}
Aggregations