Example usage for io.netty.channel.socket DatagramChannel isConnected

List of usage examples for io.netty.channel.socket DatagramChannel isConnected

Introduction

In this page you can find the example usage for io.netty.channel.socket DatagramChannel isConnected.

Prototype

boolean isConnected();

Source Link

Document

Return true if the DatagramChannel is connected to the remote peer.

Usage

From source file:org.restcomm.media.network.deprecated.netty.UdpNetworkManagerTest.java

License:Open Source License

@Test
public void testBindChannel() throws InterruptedException {
    // given/*from   w  w w  .  j  a v a2s  . c  o  m*/
    final String address = "127.0.0.1";
    final int port = 60000;
    final ChannelHandler handler = mock(ChannelHandler.class);
    this.manager = new UdpNetworkManager();

    // when - activate manager and bind channel
    manager.activate();

    final ChannelFuture future = manager.bindDatagramChannel(address, port, handler);
    final DatagramChannel channel = (DatagramChannel) future.sync().channel();

    // then
    assertTrue(manager.isActive());
    assertTrue(future.isSuccess());
    assertNotNull(channel);
    assertTrue(channel.isOpen());
    assertTrue(channel.isActive());
    assertFalse(channel.isConnected());
    assertEquals(new InetSocketAddress(address, port), channel.localAddress());

    // when - deactivate manager
    manager.deactivate();
    Thread.sleep(UdpNetworkManager.SHUTDOWN_TIME * 1000);

    // then
    assertFalse(manager.isActive());
    assertFalse(channel.isOpen());
    assertFalse(channel.isActive());
}