Search in sources :

Example 1 with ChannelHandlerAdapter

use of org.apache.dubbo.remoting.transport.ChannelHandlerAdapter in project dubbo by alibaba.

the class ExchangersTest method testBind.

@Test
public void testBind() throws RemotingException {
    String url = "dubbo://127.0.0.1:12345?exchanger=mockExchanger";
    Exchangers.bind(url, Mockito.mock(Replier.class));
    Exchangers.bind(url, new ChannelHandlerAdapter(), Mockito.mock(Replier.class));
    Exchangers.bind(url, new ExchangeHandlerDispatcher());
    Assertions.assertThrows(RuntimeException.class, () -> Exchangers.bind((URL) null, new ExchangeHandlerDispatcher()));
    Assertions.assertThrows(RuntimeException.class, () -> Exchangers.bind(url, (ExchangeHandlerDispatcher) null));
}
Also used : ChannelHandlerAdapter(org.apache.dubbo.remoting.transport.ChannelHandlerAdapter) Replier(org.apache.dubbo.remoting.exchange.support.Replier) ExchangeHandlerDispatcher(org.apache.dubbo.remoting.exchange.support.ExchangeHandlerDispatcher) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 2 with ChannelHandlerAdapter

use of org.apache.dubbo.remoting.transport.ChannelHandlerAdapter in project dubbo by alibaba.

the class ExchangersTest method testConnect.

@Test
public void testConnect() throws RemotingException {
    String url = "dubbo://127.0.0.1:12345?exchanger=mockExchanger";
    Exchangers.connect(url);
    Exchangers.connect(url, Mockito.mock(Replier.class));
    Exchangers.connect(URL.valueOf(url), Mockito.mock(Replier.class));
    Exchangers.connect(url, new ChannelHandlerAdapter(), Mockito.mock(Replier.class));
    Exchangers.connect(url, new ExchangeHandlerDispatcher());
    Assertions.assertThrows(RuntimeException.class, () -> Exchangers.connect((URL) null, new ExchangeHandlerDispatcher()));
    Assertions.assertThrows(RuntimeException.class, () -> Exchangers.connect(url, (ExchangeHandlerDispatcher) null));
}
Also used : ChannelHandlerAdapter(org.apache.dubbo.remoting.transport.ChannelHandlerAdapter) Replier(org.apache.dubbo.remoting.exchange.support.Replier) ExchangeHandlerDispatcher(org.apache.dubbo.remoting.exchange.support.ExchangeHandlerDispatcher) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 3 with ChannelHandlerAdapter

use of org.apache.dubbo.remoting.transport.ChannelHandlerAdapter in project dubbo by alibaba.

the class GrizzlyTransporterTest method shouldAbleToBindGrizzly.

@Test
public void shouldAbleToBindGrizzly() throws Exception {
    int port = NetUtils.getAvailablePort();
    URL url = new URL("telnet", "localhost", port, new String[] { BIND_PORT_KEY, String.valueOf(port) });
    RemotingServer server = new GrizzlyTransporter().bind(url, new ChannelHandlerAdapter());
    assertThat(server.isBound(), is(true));
}
Also used : ChannelHandlerAdapter(org.apache.dubbo.remoting.transport.ChannelHandlerAdapter) RemotingServer(org.apache.dubbo.remoting.RemotingServer) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 4 with ChannelHandlerAdapter

use of org.apache.dubbo.remoting.transport.ChannelHandlerAdapter in project dubbo by alibaba.

the class NettyTransporterTest method shouldConnectToNetty4Server.

@Test
public void shouldConnectToNetty4Server() throws Exception {
    final CountDownLatch lock = new CountDownLatch(1);
    int port = NetUtils.getAvailablePort();
    URL url = new URL("telnet", "localhost", port, new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) });
    new NettyTransporter().bind(url, new ChannelHandlerAdapter() {

        @Override
        public void connected(Channel channel) {
            lock.countDown();
        }
    });
    new NettyTransporter().connect(url, new ChannelHandlerAdapter() {

        @Override
        public void sent(Channel channel, Object message) throws RemotingException {
            channel.send(message);
            channel.close();
        }
    });
    lock.await();
}
Also used : ChannelHandlerAdapter(org.apache.dubbo.remoting.transport.ChannelHandlerAdapter) Channel(org.apache.dubbo.remoting.Channel) RemotingException(org.apache.dubbo.remoting.RemotingException) CountDownLatch(java.util.concurrent.CountDownLatch) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 5 with ChannelHandlerAdapter

use of org.apache.dubbo.remoting.transport.ChannelHandlerAdapter in project dubbo by alibaba.

the class MulticastNetworkerTest method testJoin.

@Test
public void testJoin() throws RemotingException, InterruptedException {
    final String groupURL = "multicast://224.5.6.7:1234";
    final String peerURL = "exchange://0.0.0.0:" + NetUtils.getAvailablePort() + "?exchanger=header";
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    Peer peer1 = Networkers.join(groupURL, peerURL, new ChannelHandlerAdapter() {

        @Override
        public void received(Channel channel, Object message) {
            countDownLatch.countDown();
        }
    });
    Peer peer2 = Networkers.join(groupURL, "exchange://0.0.0.0:" + NetUtils.getAvailablePort() + "?exchanger=header", mock(ChannelHandlerAdapter.class));
    while (true) {
        long count = countDownLatch.getCount();
        if (count > 0) {
            break;
        }
        for (Channel channel : peer1.getChannels()) {
            channel.send("hello world!");
        }
        TimeUnit.MILLISECONDS.sleep(50);
    }
    Group lookup = Networkers.lookup(groupURL);
    assertThat(lookup, not(nullValue()));
    peer2.close();
    peer1.close();
}
Also used : ChannelHandlerAdapter(org.apache.dubbo.remoting.transport.ChannelHandlerAdapter) Group(org.apache.dubbo.remoting.p2p.Group) Peer(org.apache.dubbo.remoting.p2p.Peer) Channel(org.apache.dubbo.remoting.Channel) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

ChannelHandlerAdapter (org.apache.dubbo.remoting.transport.ChannelHandlerAdapter)7 Test (org.junit.jupiter.api.Test)7 URL (org.apache.dubbo.common.URL)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 Channel (org.apache.dubbo.remoting.Channel)3 RemotingServer (org.apache.dubbo.remoting.RemotingServer)2 ExchangeHandlerDispatcher (org.apache.dubbo.remoting.exchange.support.ExchangeHandlerDispatcher)2 Replier (org.apache.dubbo.remoting.exchange.support.Replier)2 Group (org.apache.dubbo.remoting.p2p.Group)2 Peer (org.apache.dubbo.remoting.p2p.Peer)2 RemotingException (org.apache.dubbo.remoting.RemotingException)1