public void testBlockingConnect() throws Exception {
   setupConnection();
   AbstractNBSocket socket = udpSelectorProvider.openSocketChannel().socket();
   socket.connect(new InetSocketAddress("127.0.0.1", PORT_1));
   assertTrue(socket.isConnected());
   socket.close();
   Thread.sleep(500);
   assertFalse(socket.isConnected());
 }
 public void testNonBlockingConnect() throws Exception {
   setupConnection();
   AbstractNBSocket socket = udpSelectorProvider.openSocketChannel().socket();
   StubConnectObserver observer = new StubConnectObserver();
   socket.connect(new InetSocketAddress("127.0.0.1", PORT_1), 5000, observer);
   observer.waitForResponse(5500);
   assertTrue(socket.isConnected());
   assertSame(socket, observer.getSocket());
   assertFalse(observer.isShutdown());
   assertNull(observer.getIoException());
   socket.close();
   Thread.sleep(500);
   assertFalse(observer.isShutdown()); // doesn't get both connect & shutdown
   assertFalse(socket.isConnected());
 }
 public void testBlockingConnectFailing() throws Exception {
   AbstractNBSocket socket = udpSelectorProvider.openSocketChannel().socket();
   try {
     socket.connect(new InetSocketAddress("127.0.0.1", 9999));
     fail("shouldn't have connected");
   } catch (ConnectException iox) {
     assertFalse(socket.isConnected());
   }
 }
 public void testNonBlockingConnectTimesOut() throws Exception {
   AbstractNBSocket socket = udpSelectorProvider.openSocketChannel().socket();
   StubConnectObserver observer = new StubConnectObserver();
   socket.connect(new InetSocketAddress("127.0.0.1", PORT_1), 1000, observer);
   observer.waitForResponse(1500);
   assertTrue(observer.isShutdown());
   assertNull(observer.getSocket());
   assertNull(observer.getIoException()); // NIOSocket swallows the IOX.
   assertFalse(socket.isConnected());
 }
  public void testNonBlockingConnectFailing() throws Exception {
    AbstractNBSocket socket = udpSelectorProvider.openSocketChannel().socket();
    StubConnectObserver observer = new StubConnectObserver();

    // UDPConnectionProcessor has a default connect timeout of 20 seconds,
    // so we set our timeout at 40 seconds to ensure it doesn't fail because
    // of the timeout.
    socket.connect(new InetSocketAddress("127.0.0.1", PORT_1), 40000, observer);
    observer.waitForResponse(30000);

    assertTrue(observer.isShutdown());
    assertNull(observer.getSocket());
    assertNull(observer.getIoException()); // NIOSocket swallows the IOX.
    assertFalse(socket.isConnected());
  }