HHH-13459 - Unit test lock up when they run on PostgreSQL

(cherry picked from commit cb343567e6)
This commit is contained in:
Andrea Boriero 2019-06-25 16:42:47 +01:00 committed by Gail Badner
parent c451219cff
commit c7e86e9237
1 changed files with 64 additions and 44 deletions

View File

@ -44,10 +44,11 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest
@Test @Test
public void testDynamicFetchScroll() { public void testDynamicFetchScroll() {
ScrollableResults scrollableResults = null;
final StatelessSession statelessSession = sessionFactory().openStatelessSession(); final StatelessSession statelessSession = sessionFactory().openStatelessSession();
try {
final Query query = statelessSession.createQuery( "from Task t join fetch t.resource join fetch t.user" ); final Query query = statelessSession.createQuery( "from Task t join fetch t.resource join fetch t.user" );
final ScrollableResults scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY); scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY );
while ( scrollableResults.next() ) { while ( scrollableResults.next() ) {
Task taskRef = (Task) scrollableResults.get( 0 ); Task taskRef = (Task) scrollableResults.get( 0 );
assertTrue( Hibernate.isInitialized( taskRef ) ); assertTrue( Hibernate.isInitialized( taskRef ) );
@ -56,14 +57,23 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest
assertFalse( Hibernate.isInitialized( taskRef.getResource().getOwner() ) ); assertFalse( Hibernate.isInitialized( taskRef.getResource().getOwner() ) );
} }
} }
finally {
if ( scrollableResults != null ) {
scrollableResults.close();
}
statelessSession.close();
}
}
@Test @Test
public void testDynamicFetchCollectionScroll() { public void testDynamicFetchCollectionScroll() {
ScrollableResults scrollableResults = null;
StatelessSession statelessSession = sessionFactory().openStatelessSession(); StatelessSession statelessSession = sessionFactory().openStatelessSession();
statelessSession.beginTransaction(); statelessSession.beginTransaction();
try {
final Query query = statelessSession.createQuery( "select p from Producer p join fetch p.products" ); final Query query = statelessSession.createQuery( "select p from Producer p join fetch p.products" );
final ScrollableResults scrollableResults = query.scroll(ScrollMode.FORWARD_ONLY); scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY );
while ( scrollableResults.next() ) { while ( scrollableResults.next() ) {
Producer producer = (Producer) scrollableResults.get( 0 ); Producer producer = (Producer) scrollableResults.get( 0 );
assertTrue( Hibernate.isInitialized( producer ) ); assertTrue( Hibernate.isInitialized( producer ) );
@ -75,10 +85,14 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest
assertFalse( Hibernate.isInitialized( product.getVendor() ) ); assertFalse( Hibernate.isInitialized( product.getVendor() ) );
} }
} }
}
finally {
if ( scrollableResults != null ) {
scrollableResults.close();
}
statelessSession.getTransaction().commit(); statelessSession.getTransaction().commit();
statelessSession.close(); statelessSession.close();
}
} }
@ -410,7 +424,13 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest
this( user, description, resource, dueDate, null, null ); this( user, description, resource, dueDate, null, null );
} }
public Task(User user, String description, Resource resource, Date dueDate, Date startDate, Date completionDate) { public Task(
User user,
String description,
Resource resource,
Date dueDate,
Date startDate,
Date completionDate) {
this.user = user; this.user = user;
this.resource = resource; this.resource = resource;
this.description = description; this.description = description;