BoneCP implements Serializable, Closeable { protected void postDestroyConnection(ConnectionHandle handle){ ConnectionPartition partition = handle.getOriginatingPartition(); if (this.finalizableRefQueue != null && handle.getInternalConnection() != null){ this.finalizableRefs.remove(handle.getInternalConnection()); } partition.updateCreatedConnections(-1); partition.setUnableToCreateMoreTransactions(false); if (handle.getConnectionHook() != null){ handle.getConnectionHook().onDestroy(handle); } } 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 testPostDestroyConnection(){ Connection mockRealConnection = EasyMock.createNiceMock(Connection.class); reset(mockConnection); expect(mockConnection.getOriginatingPartition()).andReturn(mockPartition).anyTimes(); mockPartition.updateCreatedConnections(-1); expectLastCall().once(); mockPartition.setUnableToCreateMoreTransactions(false); expectLastCall().once(); ConnectionHook mockConnectionHook = EasyMock.createNiceMock(ConnectionHook.class); expect(mockConnection.getConnectionHook()).andReturn(mockConnectionHook).anyTimes(); expect(mockConnection.getInternalConnection()).andReturn(mockRealConnection).anyTimes(); mockConnectionHook.onDestroy(mockConnection); expectLastCall().once(); replay(mockRealConnection, mockConnectionHook, mockConnection); testClass.postDestroyConnection(mockConnection); verify(mockConnectionHook, mockConnection); }