Search in sources :

Example 6 with ChannelHandlerAdapter

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

the class FileNetworkerTest method testJoin.

@Test
public void testJoin(@TempDir Path folder) throws RemotingException, InterruptedException {
    final String groupURL = "file:///" + folder.getFileName().toAbsolutePath();
    FileNetworker networker = new FileNetworker();
    Group group = networker.lookup(URL.valueOf(groupURL));
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    Peer peer1 = group.join(URL.valueOf("exchange://0.0.0.0:" + NetUtils.getAvailablePort() + "?exchanger=header"), new ChannelHandlerAdapter() {

        @Override
        public void received(Channel channel, Object message) {
            countDownLatch.countDown();
        }
    });
    Peer peer2 = group.join(URL.valueOf("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(0, false);
            channel.send("hello world!");
        }
        TimeUnit.MILLISECONDS.sleep(50);
    }
    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)

Example 7 with ChannelHandlerAdapter

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

the class NettyTransporterTest method shouldAbleToBindNetty4.

@Test
public void shouldAbleToBindNetty4() throws Exception {
    int port = NetUtils.getAvailablePort();
    URL url = new URL("telnet", "localhost", port, new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) });
    RemotingServer server = new NettyTransporter().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)

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