Search in sources :

Example 6 with Channel

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));
}
Also used : ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel) Channel(org.apache.dubbo.remoting.Channel) HeaderExchangeHandler(org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) Request(org.apache.dubbo.remoting.exchange.Request) Test(org.junit.jupiter.api.Test)

Example 7 with Channel

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());
}
Also used : Response(org.apache.dubbo.remoting.exchange.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel) Channel(org.apache.dubbo.remoting.Channel) HeaderExchangeHandler(org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) Request(org.apache.dubbo.remoting.exchange.Request) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel) HeaderExchangeHandler(org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) ExchangeHandler(org.apache.dubbo.remoting.exchange.ExchangeHandler) Test(org.junit.jupiter.api.Test)

Example 8 with Channel

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();
}
Also used : Channel(org.apache.dubbo.remoting.Channel) ExitTelnetHandler(org.apache.dubbo.remoting.telnet.support.command.ExitTelnetHandler) Test(org.junit.jupiter.api.Test)

Example 9 with Channel

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();
}
Also used : Channel(org.apache.dubbo.remoting.Channel)

Example 10 with Channel

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));
}
Also used : HashMap(java.util.HashMap) Channel(org.apache.dubbo.remoting.Channel) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Aggregations

Channel (org.apache.dubbo.remoting.Channel)53 Test (org.junit.jupiter.api.Test)32 Request (org.apache.dubbo.remoting.exchange.Request)18 ChannelBuffer (org.apache.dubbo.remoting.buffer.ChannelBuffer)16 Response (org.apache.dubbo.remoting.exchange.Response)12 ExchangeChannel (org.apache.dubbo.remoting.exchange.ExchangeChannel)9 URL (org.apache.dubbo.common.URL)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 HeaderExchangeHandler (org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler)6 RemotingException (org.apache.dubbo.remoting.RemotingException)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ExchangeHandler (org.apache.dubbo.remoting.exchange.ExchangeHandler)4 MockedChannel (org.apache.dubbo.remoting.handler.MockedChannel)4 AppResponse (org.apache.dubbo.rpc.AppResponse)4 Demo (org.apache.dubbo.rpc.gen.thrift.Demo)4 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)4 TMessage (org.apache.thrift.protocol.TMessage)4 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)4 IOException (java.io.IOException)3