@Test @Features({"issues/219"}) public void testConnectWithDelayThreadSleeps() throws Exception { ConnectionsRegistry.INSTANCE.setSocketAddressStatus("localhost", 123, 1000); AtomicReference<Exception> exceptionReference = new AtomicReference<>(); Thread thread = new Thread(() -> { try { sniffySocket.connect("localhost", 123); } catch (IOException e) { exceptionReference.set(e); } }); assertNull(exceptionReference.get()); thread.start(); Thread.sleep(500); assertEquals(Thread.State.TIMED_WAITING, thread.getState()); thread.join(1000); verifyPrivate(delegate).invoke("connect", "localhost", 123); verifyNoMoreInteractions(delegate); }
@Override protected void connect(String host, int port) throws IOException { copyToDelegate(); long start = System.currentTimeMillis(); try { checkConnectionAllowed(this.address = new InetSocketAddress(host, port)); method("connect", String.class, int.class).invoke(delegate, host, port); } catch (Exception e) { ExceptionUtil.processException(e); } finally { logSocket(System.currentTimeMillis() - start); copyFromDelegate(); } }
SnifferSocketImpl extends SocketImpl implements SniffySocket { @Override protected void connect(String host, int port) throws IOException { copyToDelegate(); long start = System.currentTimeMillis(); try { checkConnectionAllowed(this.address = new InetSocketAddress(host, port)); method("connect", String.class, int.class).invoke(delegate, host, port); } catch (Exception e) { ExceptionUtil.processException(e); } finally { logSocket(System.currentTimeMillis() - start); copyFromDelegate(); } } }
SnifferSocketImpl extends SocketImpl implements SniffySocket { @Override protected void connect(String host, int port) throws IOException { copyToDelegate(); long start = System.currentTimeMillis(); try { checkConnectionAllowed(this.address = new InetSocketAddress(host, port)); method("connect", String.class, int.class).invoke(delegate, host, port); } catch (Exception e) { ExceptionUtil.processException(e); } finally { logSocket(System.currentTimeMillis() - start); copyFromDelegate(); } } protected  SnifferSocketImpl(SocketImpl delegate); }
SnifferSocketImpl extends SocketImpl implements SniffySocket { @Override protected void connect(String host, int port) throws IOException { copyToDelegate(); long start = System.currentTimeMillis(); try { checkConnectionAllowed(this.address = new InetSocketAddress(host, port)); method("connect", String.class, int.class).invoke(delegate, host, port); } catch (Exception e) { ExceptionUtil.processException(e); } finally { logSocket(System.currentTimeMillis() - start); copyFromDelegate(); } } protected  SnifferSocketImpl(SocketImpl delegate); @Override void setConnectionStatus(Integer connectionStatus); @Override String toString(); @Override void setOption(int optID, Object value); @Override Object getOption(int optID); @Override InetSocketAddress getInetSocketAddress(); }
SnifferSocketImpl extends SocketImpl implements SniffySocket { @Override protected void connect(String host, int port) throws IOException { copyToDelegate(); long start = System.currentTimeMillis(); try { checkConnectionAllowed(this.address = new InetSocketAddress(host, port)); method("connect", String.class, int.class).invoke(delegate, host, port); } catch (Exception e) { ExceptionUtil.processException(e); } finally { logSocket(System.currentTimeMillis() - start); copyFromDelegate(); } } protected  SnifferSocketImpl(SocketImpl delegate); @Override void setConnectionStatus(Integer connectionStatus); @Override String toString(); @Override void setOption(int optID, Object value); @Override Object getOption(int optID); @Override InetSocketAddress getInetSocketAddress();  }