BoneCP implements Serializable, Closeable { protected void putConnectionBackInPartition(ConnectionHandle connectionHandle) throws SQLException { if (this.cachedPoolStrategy && ((CachedConnectionStrategy)this.connectionStrategy).tlConnections.dumbGet().getValue()){ connectionHandle.logicallyClosed.set(true); ((CachedConnectionStrategy)this.connectionStrategy).tlConnections.set(new AbstractMap.SimpleEntry<ConnectionHandle, Boolean>(connectionHandle, false)); } else { BlockingQueue<ConnectionHandle> queue = connectionHandle.getOriginatingPartition().getFreeConnections(); if (!queue.offer(connectionHandle)){ connectionHandle.internalClose(); } } } BoneCP(BoneCPConfig config); synchronized void shutdown(); void close(); Connection getConnection(); ListenableFuture<Connection> getAsyncConnection(); boolean isConnectionHandleAlive(ConnectionHandle connection); int getTotalLeased(); int getTotalFree(); int getTotalCreatedConnections(); BoneCPConfig getConfig(); Statistics getStatistics(); AtomicBoolean getDbIsDown(); static final String MBEAN_CONFIG; static final String MBEAN_BONECP; }
@Test public void testPutConnectionBackInPartition() throws InterruptedException, SQLException { expect(mockPartition.getFreeConnections()).andReturn(mockConnectionHandles).anyTimes(); expect(mockPartition.getAvailableConnections()).andReturn(1).anyTimes(); Connection mockRealConnection = EasyMock.createNiceMock(Connection.class); expect(mockConnection.getInternalConnection()).andReturn(mockRealConnection).anyTimes(); expect(mockConnection.getOriginatingPartition()).andReturn(mockPartition).anyTimes(); expect(mockConnectionHandles.offer(mockConnection)).andReturn(true).once(); replay(mockRealConnection, mockPartition, mockConnectionHandles, mockConnection); testClass.putConnectionBackInPartition(mockConnection); verify(mockPartition, mockConnectionHandles); }
@Test public void testPutConnectionBackInPartitionWithResetConnectionOnClose() throws InterruptedException, SQLException { expect(mockPartition.getFreeConnections()).andReturn(mockConnectionHandles).anyTimes(); expect(mockPartition.getAvailableConnections()).andReturn(1).anyTimes(); expect(mockConnection.getOriginatingPartition()).andReturn(mockPartition).anyTimes(); expect(mockConnectionHandles.offer(mockConnection)).andReturn(true).once(); expect(mockConnection.isTxResolved()).andReturn(false).once(); Connection mockInternalConnection = EasyMock.createNiceMock(Connection.class); expect(mockInternalConnection.getAutoCommit()).andReturn(false).once(); expect(mockConnection.getInternalConnection()).andReturn(mockInternalConnection).anyTimes(); mockInternalConnection.rollback(); mockInternalConnection.setAutoCommit(true); replay(mockInternalConnection, mockPartition, mockConnectionHandles, mockConnection); testClass.resetConnectionOnClose = true; testClass.putConnectionBackInPartition(mockConnection); verify(mockPartition, mockConnectionHandles); }