Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void close()
delegate.close();
}

private final class CachedConnection
final class CachedConnection
Comment thread
wendigo marked this conversation as resolved.
Outdated
extends ForwardingConnection
{
private final String queryId;
Expand Down Expand Up @@ -176,7 +176,7 @@ public void close()
if (dirty) {
delegate.close();
}
else {
else if (!delegate.isClosed()) {
connections.put(queryId, delegate);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,28 @@ public void testConnectionIsNotReusedWhenSetToReadOnly()
}
}

@Test
public void testConnectionIsNotReusedWhenDelegateIsClosed()
Comment thread
wendigo marked this conversation as resolved.
Outdated
throws Exception
{
MockConnectionFactory mockConnectionFactory = new MockConnectionFactory();
ReusableConnectionFactory connectionFactory = new ReusableConnectionFactory(mockConnectionFactory, FOREVER, HUGE_SIZE);
Connection connection = connectionFactory.openConnection(ALICE);

Connection delegate = ((ReusableConnectionFactory.CachedConnection) connection).delegate();
delegate.close();
connection.close();

Connection secondConnection = connectionFactory.openConnection(ALICE);
Connection secondDelegate = ((ReusableConnectionFactory.CachedConnection) secondConnection).delegate();

assertThat(delegate).isNotEqualTo(secondDelegate);
Comment thread
wendigo marked this conversation as resolved.
secondConnection.close();

assertThat(mockConnectionFactory.openedConnections).isEqualTo(2);
assertThat(mockConnectionFactory.closedConnections).isEqualTo(1);
}

@Test
public void testConnectionIsNotReusedWhenAutoCommitDisabled()
throws Exception
Expand Down Expand Up @@ -190,6 +212,12 @@ protected Connection delegate()
throw new UnsupportedOperationException();
}

@Override
public boolean isClosed()
{
return closed;
}

@Override
public void setAutoCommit(boolean autoCommit) {}

Expand Down