HHH-14557 Test JDBC resources are released on each commit

Not just on session closing.
This commit is contained in:
Yoann Rodière 2021-04-13 14:09:43 +02:00
parent 3825a671a7
commit e03beca97f
1 changed files with 15 additions and 13 deletions

View File

@ -110,11 +110,11 @@ public class BeforeCompletionReleaseTest extends BaseEntityManagerFunctionalTest
@Test
@TestForIssue(jiraKey = {"HHH-13976", "HHH-14326"})
public void testResourcesReleasedThenConnectionClosedThenCommit() throws SQLException, XAException {
XAResource transactionSpy = mock( XAResource.class );
Connection[] connectionSpies = new Connection[1];
Statement statementMock = Mockito.mock( Statement.class );
try (SessionImplementor s = (SessionImplementor) openSession()) {
XAResource transactionSpy = mock( XAResource.class );
Connection[] connectionSpies = new Connection[1];
Statement statementMock = Mockito.mock( Statement.class );
TransactionUtil2.inTransaction( s, session -> {
spyOnTransaction( transactionSpy );
@ -126,16 +126,18 @@ public class BeforeCompletionReleaseTest extends BaseEntityManagerFunctionalTest
logicalConnection.getResourceRegistry().register( statementMock, true );
connectionSpies[0] = logicalConnection.getPhysicalConnection();
} );
// Note: all this must happen BEFORE the session is closed;
// it's particularly important when reusing the session.
Connection connectionSpy = connectionSpies[0];
// Must close the resources, then the connection, then commit
InOrder inOrder = inOrder( statementMock, connectionSpy, transactionSpy );
inOrder.verify( statementMock ).close();
inOrder.verify( connectionSpy ).close();
inOrder.verify( transactionSpy ).commit( any(), anyBoolean() );
}
Connection connectionSpy = connectionSpies[0];
// Must close the resources, then the connection, then commit
InOrder inOrder = inOrder( statementMock, connectionSpy, transactionSpy );
inOrder.verify( statementMock ).close();
inOrder.verify( connectionSpy ).close();
inOrder.verify( transactionSpy ).commit( any(), anyBoolean() );
Mockito.reset( connectionSpy );
}
private void spyOnTransaction(XAResource xaResource) {