Skip to content

Commit

Permalink
Merge pull request #8 from ggerritsen/master
Browse files Browse the repository at this point in the history
  • Loading branch information
wwadge committed Aug 6, 2012
2 parents 28aa127 + 37a6a13 commit 5694ef5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions bonecp/src/main/java/com/jolbox/bonecp/BoneCP.java
Expand Up @@ -626,6 +626,10 @@ protected void internalReleaseConnection(ConnectionHandle connectionHandle) thro
if (connectionHandle.isExpired() || (!this.poolShuttingDown && connectionHandle.isPossiblyBroken()
&& !isConnectionHandleAlive(connectionHandle))){

if (connectionHandle.isExpired()) {
connectionHandle.internalClose();
}

ConnectionPartition connectionPartition = connectionHandle.getOriginatingPartition();
postDestroyConnection(connectionHandle);

Expand Down
33 changes: 29 additions & 4 deletions bonecp/src/test/java/com/jolbox/bonecp/TestBoneCP.java
Expand Up @@ -821,8 +821,6 @@ public void testInternalReleaseConnection() throws InterruptedException, SQLExce
*/
@Test
public void testInternalReleaseConnectionWhereConnectionIsBroken() throws InterruptedException, SQLException {


// Test case where connection is broken
reset(mockConnection,mockPartition, mockConnectionHandles);
expect(mockConnection.isPossiblyBroken()).andReturn(true).once();
Expand All @@ -844,10 +842,37 @@ public void testInternalReleaseConnectionWhereConnectionIsBroken() throws Interr
replay(mockPartition, mockConnection);
testClass.internalReleaseConnection(mockConnection);
verify(mockPartition, mockConnection);

}

/**
/**
* Test method for {@link com.jolbox.bonecp.BoneCP#internalReleaseConnection(ConnectionHandle)}.
*
* @throws InterruptedException
* @throws SQLException
*/
@Test
public void testInternalReleaseConnectionWhereConnectionIsExpired() throws InterruptedException, SQLException {
// Test case where connection is expired
reset(mockConnection, mockPartition, mockConnectionHandles);

Connection mockRealConnection = createNiceMock(Connection.class);
expect(mockConnection.getInternalConnection()).andReturn(mockRealConnection).anyTimes();

// return a partition
expect(mockConnection.getOriginatingPartition()).andReturn(mockPartition).anyTimes();
// break out from this method, we're not interested in it
expect(mockPartition.isUnableToCreateMoreTransactions()).andReturn(true).once();

expect(mockConnection.isExpired()).andReturn(true).anyTimes();
mockConnection.internalClose();
expectLastCall();

replay(mockPartition, mockConnection, mockRealConnection);
testClass.internalReleaseConnection(mockConnection);
verify(mockPartition, mockConnection, mockRealConnection);
}

/**
* Test method for {@link com.jolbox.bonecp.BoneCP#putConnectionBackInPartition(com.jolbox.bonecp.ConnectionHandle)}.
* @throws InterruptedException
* @throws SQLException
Expand Down

0 comments on commit 5694ef5

Please sign in to comment.