HHH-13459 - Unit test lock up when they run on PostgreSQL
(cherry picked from commit cb343567e6
)
This commit is contained in:
parent
c451219cff
commit
c7e86e9237
|
@ -39,46 +39,60 @@ import static org.junit.Assert.assertTrue;
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@RunWith( BytecodeEnhancerRunner.class )
|
@RunWith(BytecodeEnhancerRunner.class)
|
||||||
public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTestCase {
|
public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
|
|
||||||
@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 ) );
|
||||||
assertTrue( Hibernate.isInitialized( taskRef.getUser() ) );
|
assertTrue( Hibernate.isInitialized( taskRef.getUser() ) );
|
||||||
assertTrue( Hibernate.isInitialized( taskRef.getResource() ) );
|
assertTrue( Hibernate.isInitialized( taskRef.getResource() ) );
|
||||||
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();
|
||||||
|
|
||||||
final Query query = statelessSession.createQuery( "select p from Producer p join fetch p.products" );
|
try {
|
||||||
final ScrollableResults scrollableResults = query.scroll(ScrollMode.FORWARD_ONLY);
|
final Query query = statelessSession.createQuery( "select p from Producer p join fetch p.products" );
|
||||||
while ( scrollableResults.next() ) {
|
scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY );
|
||||||
Producer producer = (Producer) scrollableResults.get( 0 );
|
while ( scrollableResults.next() ) {
|
||||||
assertTrue( Hibernate.isInitialized( producer ) );
|
Producer producer = (Producer) scrollableResults.get( 0 );
|
||||||
assertTrue( Hibernate.isPropertyInitialized( producer, "products" ) );
|
assertTrue( Hibernate.isInitialized( producer ) );
|
||||||
assertTrue( Hibernate.isInitialized( producer.getProducts() ) );
|
assertTrue( Hibernate.isPropertyInitialized( producer, "products" ) );
|
||||||
|
assertTrue( Hibernate.isInitialized( producer.getProducts() ) );
|
||||||
|
|
||||||
for (Product product : producer.getProducts()) {
|
for ( Product product : producer.getProducts() ) {
|
||||||
assertTrue( Hibernate.isInitialized( product ) );
|
assertTrue( Hibernate.isInitialized( product ) );
|
||||||
assertFalse( Hibernate.isInitialized( product.getVendor() ) );
|
assertFalse( Hibernate.isInitialized( product.getVendor() ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
statelessSession.getTransaction().commit();
|
if ( scrollableResults != null ) {
|
||||||
statelessSession.close();
|
scrollableResults.close();
|
||||||
|
}
|
||||||
|
statelessSession.getTransaction().commit();
|
||||||
|
statelessSession.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,9 +137,9 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest
|
||||||
session.save( v1 );
|
session.save( v1 );
|
||||||
session.save( v2 );
|
session.save( v2 );
|
||||||
|
|
||||||
final Product product1 = new Product(1, "123", v1, p1);
|
final Product product1 = new Product( 1, "123", v1, p1 );
|
||||||
final Product product2 = new Product(2, "456", v1, p1);
|
final Product product2 = new Product( 2, "456", v1, p1 );
|
||||||
final Product product3 = new Product(3, "789", v1, p2);
|
final Product product3 = new Product( 3, "789", v1, p2 );
|
||||||
|
|
||||||
session.save( product1 );
|
session.save( product1 );
|
||||||
session.save( product2 );
|
session.save( product2 );
|
||||||
|
@ -170,14 +184,14 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// Collection fetch scrolling
|
// Collection fetch scrolling
|
||||||
|
|
||||||
@Entity( name = "Producer" )
|
@Entity(name = "Producer")
|
||||||
public static class Producer {
|
public static class Producer {
|
||||||
@Id
|
@Id
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@OneToMany( mappedBy = "producer", fetch = FetchType.LAZY )
|
@OneToMany(mappedBy = "producer", fetch = FetchType.LAZY)
|
||||||
private Set<Product> products = new HashSet<>();
|
private Set<Product> products = new HashSet<>();
|
||||||
|
|
||||||
public Producer() {
|
public Producer() {
|
||||||
|
@ -213,16 +227,16 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity( name = "Product" )
|
@Entity(name = "Product")
|
||||||
public static class Product {
|
public static class Product {
|
||||||
@Id
|
@Id
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private String sku;
|
private String sku;
|
||||||
|
|
||||||
@ManyToOne( fetch = FetchType.LAZY )
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
private Vendor vendor;
|
private Vendor vendor;
|
||||||
|
|
||||||
@ManyToOne( fetch = FetchType.LAZY )
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
private Producer producer;
|
private Producer producer;
|
||||||
|
|
||||||
public Product() {
|
public Product() {
|
||||||
|
@ -268,13 +282,13 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity( name = "Vendor" )
|
@Entity(name = "Vendor")
|
||||||
public static class Vendor {
|
public static class Vendor {
|
||||||
@Id
|
@Id
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "vendor", fetch = FetchType.LAZY )
|
@OneToMany(mappedBy = "vendor", fetch = FetchType.LAZY)
|
||||||
private Set<Product> products = new HashSet<>();
|
private Set<Product> products = new HashSet<>();
|
||||||
|
|
||||||
public Vendor() {
|
public Vendor() {
|
||||||
|
@ -314,14 +328,14 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// Entity fetch scrolling
|
// Entity fetch scrolling
|
||||||
|
|
||||||
@Entity( name = "Resource" )
|
@Entity(name = "Resource")
|
||||||
@Table(name = "resources")
|
@Table(name = "resources")
|
||||||
public static class Resource {
|
public static class Resource {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue( generator = "increment" )
|
@GeneratedValue(generator = "increment")
|
||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private String name;
|
||||||
@ManyToOne( fetch = FetchType.LAZY )
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
private User owner;
|
private User owner;
|
||||||
|
|
||||||
public Resource() {
|
public Resource() {
|
||||||
|
@ -357,11 +371,11 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity( name = "User" )
|
@Entity(name = "User")
|
||||||
@Table(name = "users")
|
@Table(name = "users")
|
||||||
public static class User {
|
public static class User {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue( generator = "increment" )
|
@GeneratedValue(generator = "increment")
|
||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -389,15 +403,15 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity( name = "Task" )
|
@Entity(name = "Task")
|
||||||
public static class Task {
|
public static class Task {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue( generator = "increment" )
|
@GeneratedValue(generator = "increment")
|
||||||
private Long id;
|
private Long id;
|
||||||
private String description;
|
private String description;
|
||||||
@ManyToOne( fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
private User user;
|
private User user;
|
||||||
@ManyToOne( fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
private Resource resource;
|
private Resource resource;
|
||||||
private Date dueDate;
|
private Date dueDate;
|
||||||
private Date startDate;
|
private Date startDate;
|
||||||
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue