private void testCloseOnTimeoutGuts(AbstractClientConnectionFactory cf) throws Exception {
   TestingUtilities.waitListening(serverCf, null);
   cf.setSoTimeout(100);
   CachingClientConnectionFactory cccf = new CachingClientConnectionFactory(cf, 1);
   cccf.start();
   TcpConnection connection = cccf.getConnection();
   int n = 0;
   while (n++ < 100 && connection.isOpen()) {
     Thread.sleep(100);
   }
   assertFalse(connection.isOpen());
   cccf.stop();
 }
 /**
  * @throws IOException
  * @throws SocketException
  * @throws Exception
  */
 @Override
 protected TcpConnection obtainConnection() throws Exception {
   TcpConnection theConnection = this.getTheConnection();
   if (theConnection != null && theConnection.isOpen()) {
     return theConnection;
   }
   if (logger.isDebugEnabled()) {
     logger.debug("Opening new socket connection to " + this.getHost() + ":" + this.getPort());
   }
   Socket socket = createSocket(this.getHost(), this.getPort());
   setSocketAttributes(socket);
   TcpConnection connection = new TcpNetConnection(socket, false, this.isLookupHost());
   connection = wrapConnection(connection);
   initializeConnection(connection, socket);
   this.getTaskExecutor().execute(connection);
   this.harvestClosedConnections();
   return connection;
 }