Search in sources :

Example 26 with Channel

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());
}
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 27 with Channel

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

Example 28 with Channel

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

Example 29 with Channel

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

Example 30 with Channel

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;
}
Also used : Channel(org.apache.dubbo.remoting.Channel) IoSession(org.apache.mina.common.IoSession) HashSet(java.util.HashSet)

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