@Test public void testMakeObject() throws Exception { ConnectionSpec spec = ConnectionSpecFactory.create(credentials); Connection mockConnection = mock(Connection.class); when(mockConnectionFactory.getConnection(host, spec)).thenReturn(mockConnection); Connection c = (Connection) poolableConnectionFactory.makeObject(PoolKeyUtils.getKey(host, credentials)); verify(mockConnectionFactory).getConnection(host, spec); assertThat(c, sameInstance(mockConnection)); ArgumentCaptor<ConnectionPoolEvent> eventCaptor = ArgumentCaptor.forClass(ConnectionPoolEvent.class); verify(mockListener).connectionCreated(eventCaptor.capture()); assertThat(eventCaptor.getValue().getConnection(), sameInstance(c)); }
@Override public Connection makeObject(String key) throws Exception { ConnectionSpec auth = null; try { RpcHost host = RpcUriUtils.extractHost(PoolKeyUtils.keyToUriString(key)); auth = PoolKeyUtils.keyToConnectionSpec(key); Connection connection = connectionFactory.getConnection(host, auth); fireConnectionCreated(connection); return connection; } finally { LOG.debug("Connection pool: created {}", RpcUriUtils.sanitize(PoolKeyUtils.keyToUriString(key), auth)); } }
PoolableConnectionFactory implements KeyedPoolableObjectFactory<String, Connection> { @Override public Connection makeObject(String key) throws Exception { ConnectionSpec auth = null; try { RpcHost host = RpcUriUtils.extractHost(PoolKeyUtils.keyToUriString(key)); auth = PoolKeyUtils.keyToConnectionSpec(key); Connection connection = connectionFactory.getConnection(host, auth); fireConnectionCreated(connection); return connection; } finally { LOG.debug("Connection pool: created {}", RpcUriUtils.sanitize(PoolKeyUtils.keyToUriString(key), auth)); } } }
PoolableConnectionFactory implements KeyedPoolableObjectFactory<String, Connection> { @Override public Connection makeObject(String key) throws Exception { ConnectionSpec auth = null; try { RpcHost host = RpcUriUtils.extractHost(PoolKeyUtils.keyToUriString(key)); auth = PoolKeyUtils.keyToConnectionSpec(key); Connection connection = connectionFactory.getConnection(host, auth); fireConnectionCreated(connection); return connection; } finally { LOG.debug("Connection pool: created {}", RpcUriUtils.sanitize(PoolKeyUtils.keyToUriString(key), auth)); } } PoolableConnectionFactory(ConnectionFactory connectionFactory);  PoolableConnectionFactory(ConnectionFactory connectionFactory, ConnectionPoolListener listener); }
PoolableConnectionFactory implements KeyedPoolableObjectFactory<String, Connection> { @Override public Connection makeObject(String key) throws Exception { ConnectionSpec auth = null; try { RpcHost host = RpcUriUtils.extractHost(PoolKeyUtils.keyToUriString(key)); auth = PoolKeyUtils.keyToConnectionSpec(key); Connection connection = connectionFactory.getConnection(host, auth); fireConnectionCreated(connection); return connection; } finally { LOG.debug("Connection pool: created {}", RpcUriUtils.sanitize(PoolKeyUtils.keyToUriString(key), auth)); } } PoolableConnectionFactory(ConnectionFactory connectionFactory);  PoolableConnectionFactory(ConnectionFactory connectionFactory, ConnectionPoolListener listener); void addConnectionListener(final ConnectionPoolListener listener); void removeConnectionListener(final ConnectionPoolListener listener); @Override Connection makeObject(String key); @Override void destroyObject(String key, Connection connection); @Override boolean validateObject(String key, Connection connection); @Override void activateObject(String key, Connection connection); @Override void passivateObject(String key, Connection connection); }
PoolableConnectionFactory implements KeyedPoolableObjectFactory<String, Connection> { @Override public Connection makeObject(String key) throws Exception { ConnectionSpec auth = null; try { RpcHost host = RpcUriUtils.extractHost(PoolKeyUtils.keyToUriString(key)); auth = PoolKeyUtils.keyToConnectionSpec(key); Connection connection = connectionFactory.getConnection(host, auth); fireConnectionCreated(connection); return connection; } finally { LOG.debug("Connection pool: created {}", RpcUriUtils.sanitize(PoolKeyUtils.keyToUriString(key), auth)); } } PoolableConnectionFactory(ConnectionFactory connectionFactory);  PoolableConnectionFactory(ConnectionFactory connectionFactory, ConnectionPoolListener listener); void addConnectionListener(final ConnectionPoolListener listener); void removeConnectionListener(final ConnectionPoolListener listener); @Override Connection makeObject(String key); @Override void destroyObject(String key, Connection connection); @Override boolean validateObject(String key, Connection connection); @Override void activateObject(String key, Connection connection); @Override void passivateObject(String key, Connection connection);  }