use of org.apache.dubbo.remoting.Channel 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(READONLY_EVENT);
final Channel mchannel = new MockedChannel();
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler());
hexhandler.received(mchannel, request);
Assertions.assertTrue(mchannel.hasAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY));
}
use of org.apache.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;
Assertions.assertEquals(request.getId(), res.getId());
Assertions.assertEquals(request.getVersion(), res.getVersion());
Assertions.assertEquals(Response.OK, res.getStatus());
Assertions.assertEquals(requestdata, res.getResult());
Assertions.assertNull(res.getErrorMessage());
count.incrementAndGet();
}
};
ExchangeHandler exhandler = new MockedExchangeHandler() {
@Override
public CompletableFuture<Object> reply(ExchangeChannel channel, Object request) throws RemotingException {
return CompletableFuture.completedFuture(request);
}
@Override
public void received(Channel channel, Object message) throws RemotingException {
Assertions.fail();
}
};
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 ExitTelnetHandlerTest method test.
@Test
public void test() {
Channel channel = Mockito.mock(Channel.class);
ExitTelnetHandler exitTelnetHandler = new ExitTelnetHandler();
exitTelnetHandler.telnet(channel, null);
verify(channel, times(1)).close();
}
use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.
the class AbstractCodecTest method test_checkPayload_minusPayloadNoLimit.
public void test_checkPayload_minusPayloadNoLimit() throws Exception {
Channel channel = mock(Channel.class);
given(channel.getUrl()).willReturn(URL.valueOf("dubbo://1.1.1.1?payload=-1"));
AbstractCodec.checkPayload(channel, 15 * 1024 * 1024);
verify(channel, VerificationModeFactory.atLeastOnce()).getUrl();
}
use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.
the class TelnetHandlerAdapterTest method testTelnet.
@Test
public void testTelnet() throws RemotingException {
Channel channel = Mockito.mock(Channel.class);
Map<String, String> param = new HashMap<>();
param.put("telnet", "status");
URL url = new URL("p1", "1.2.3.4", 1010, "path1", param);
Mockito.when(channel.getUrl()).thenReturn(url);
TelnetHandlerAdapter telnetHandlerAdapter = new TelnetHandlerAdapter();
String message = "--no-prompt status ";
String expectedResult = "OK\r\n";
Assertions.assertEquals(expectedResult, telnetHandlerAdapter.telnet(channel, message));
message = "--no-prompt status test";
expectedResult = "Unsupported parameter test for status.\r\n";
Assertions.assertEquals(expectedResult, telnetHandlerAdapter.telnet(channel, message));
message = "--no-prompt test";
expectedResult = "Unsupported command: test\r\n";
Assertions.assertEquals(expectedResult, telnetHandlerAdapter.telnet(channel, message));
message = "--no-prompt help";
expectedResult = "Command: help disabled for security reasons, please enable support by listing the commands through 'telnet'\r\n";
Assertions.assertEquals(expectedResult, telnetHandlerAdapter.telnet(channel, message));
message = "--no-prompt";
expectedResult = StringUtils.EMPTY_STRING;
Assertions.assertEquals(expectedResult, telnetHandlerAdapter.telnet(channel, message));
message = "help";
expectedResult = "Command: help disabled for security reasons, please enable support by listing the commands through 'telnet'\r\ndubbo>";
Assertions.assertEquals(expectedResult, telnetHandlerAdapter.telnet(channel, message));
}
Aggregations