HHH-7569 Correct test-only failures in hibernate-core-master-matrix CI

job
This commit is contained in:
brmeyer 2012-09-19 05:24:51 -04:00
parent 8c58af3b19
commit 6660d2412a
3 changed files with 228 additions and 326 deletions

View File

@ -1,14 +1,18 @@
package org.hibernate.test.hqlfetchscroll; package org.hibernate.test.hqlfetchscroll;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.junit.Test;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.ScrollableResults; import org.hibernate.ScrollableResults;
import org.hibernate.Session; import org.hibernate.Session;
@ -17,18 +21,11 @@ import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.transform.DistinctRootEntityResultTransformer; import org.hibernate.transform.DistinctRootEntityResultTransformer;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
@ -36,340 +33,255 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testNoScroll() { public void testNoScroll() {
try { Session s = openSession();
insertTestData(); List list = s.createQuery( QUERY ).setResultTransformer( DistinctRootEntityResultTransformer.INSTANCE ).list();
Session s = openSession(); assertResultFromAllUsers( list );
List list = s.createQuery( QUERY ).setResultTransformer( DistinctRootEntityResultTransformer.INSTANCE ).list(); s.close();
assertResultFromAllUsers( list );
s.close();
}
finally {
deleteAll();
}
} }
@Test @Test
@SkipForDialect( { SQLServerDialect.class, Oracle8iDialect.class, H2Dialect.class } ) @SkipForDialect( { SQLServerDialect.class, Oracle8iDialect.class, H2Dialect.class } )
public void testScroll() { public void testScroll() {
//"SQL Server, Oracle, and H2 do not sort the result set automatically, so failure as expected","HQLScrollFetchTest" ); Session s = openSession();
try { ScrollableResults results = s.createQuery( QUERY ).scroll();
insertTestData(); List list = new ArrayList();
Session s = openSession(); while ( results.next() ) {
ScrollableResults results = s.createQuery( QUERY ).scroll(); list.add( results.get( 0 ) );
List list = new ArrayList();
while ( results.next() ) {
list.add( results.get( 0 ) );
}
assertResultFromAllUsers( list );
s.close();
}
finally {
deleteAll();
} }
assertResultFromAllUsers( list );
s.close();
} }
@Test @Test
public void testIncompleteScrollFirstResult() { public void testIncompleteScrollFirstResult() {
try { Session s = openSession();
insertTestData(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
Session s = openSession(); results.next();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); Parent p = (Parent) results.get( 0 );
results.next(); assertResultFromOneUser( p );
Parent p = (Parent) results.get( 0 ); s.close();
assertResultFromOneUser( p );
s.close();
}
finally {
deleteAll();
}
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testIncompleteScrollSecondResult() { public void testIncompleteScrollSecondResult() {
try { Session s = openSession();
insertTestData(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
Session s = openSession(); results.next();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); Parent p = (Parent) results.get( 0 );
results.next(); assertResultFromOneUser( p );
Parent p = (Parent) results.get( 0 ); results.next();
assertResultFromOneUser( p ); p = (Parent) results.get( 0 );
results.next(); assertResultFromOneUser( p );
p = (Parent) results.get( 0 ); s.close();
assertResultFromOneUser( p );
s.close();
}
finally {
deleteAll();
}
} }
@Test @Test
public void testIncompleteScrollFirstResultInTransaction() { public void testIncompleteScrollFirstResultInTransaction() {
try { Session s = openSession();
insertTestData(); Transaction tx = s.beginTransaction();
Session s = openSession(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
Transaction tx = s.beginTransaction(); results.next();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); Parent p = (Parent) results.get( 0 );
results.next(); assertResultFromOneUser( p );
Parent p = (Parent) results.get( 0 ); tx.commit();
assertResultFromOneUser( p ); s.close();
tx.commit();
s.close();
}
finally {
deleteAll();
}
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testIncompleteScrollSecondResultInTransaction() { public void testIncompleteScrollSecondResultInTransaction() {
try { Session s = openSession();
insertTestData(); Transaction tx = s.beginTransaction();
Session s = openSession(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
Transaction tx = s.beginTransaction(); results.next();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); Parent p = (Parent) results.get( 0 );
results.next(); assertResultFromOneUser( p );
Parent p = (Parent) results.get( 0 ); results.next();
assertResultFromOneUser( p ); p = (Parent) results.get( 0 );
results.next(); assertResultFromOneUser( p );
p = (Parent) results.get( 0 ); tx.commit();
assertResultFromOneUser( p ); s.close();
tx.commit();
s.close();
}
finally {
deleteAll();
}
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-1283") @TestForIssue( jiraKey = "HHH-1283")
public void testIncompleteScroll() { public void testIncompleteScroll() {
try { Session s = openSession();
insertTestData(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
Session s = openSession(); results.next();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); Parent p = (Parent) results.get( 0 );
results.next(); assertResultFromOneUser( p );
Parent p = (Parent) results.get( 0 ); // get the other parent entity from the persistence context along with its first child
assertResultFromOneUser( p ); // retrieved from the resultset.
// get the other parent entity from the persistence context along with its first child Parent pOther = null;
// retrieved from the resultset. Child cOther = null;
Parent pOther = null; for ( Object entity : ( (SessionImplementor) s ).getPersistenceContext().getEntitiesByKey().values() ) {
Child cOther = null; if ( Parent.class.isInstance( entity ) ) {
for ( Object entity : ( (SessionImplementor) s ).getPersistenceContext().getEntitiesByKey().values() ) { if ( entity != p ) {
if ( Parent.class.isInstance( entity ) ) { if ( pOther != null ) {
if ( entity != p ) { fail( "unexpected parent found." );
if ( pOther != null ) {
fail( "unexpected parent found." );
}
pOther = (Parent) entity;
} }
} pOther = (Parent) entity;
else if ( Child.class.isInstance( entity ) ) {
if ( ! p.getChildren().contains( entity ) ) {
if ( cOther != null ) {
fail( "unexpected child entity found" );
}
cOther = (Child) entity;
}
}
else {
fail( "unexpected type of entity." );
} }
} }
// check that the same second parent is obtained by calling Session.get() else if ( Child.class.isInstance( entity ) ) {
assertNull( pOther ); if ( ! p.getChildren().contains( entity ) ) {
assertNull( cOther ); if ( cOther != null ) {
s.close(); fail( "unexpected child entity found" );
} }
finally { cOther = (Child) entity;
deleteAll(); }
}
else {
fail( "unexpected type of entity." );
}
} }
// check that the same second parent is obtained by calling Session.get()
assertNull( pOther );
assertNull( cOther );
s.close();
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testIncompleteScrollLast() { public void testIncompleteScrollLast() {
try { Session s = openSession();
insertTestData(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
Session s = openSession(); results.next();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); Parent p = (Parent) results.get( 0 );
results.next(); assertResultFromOneUser( p );
Parent p = (Parent) results.get( 0 ); results.last();
assertResultFromOneUser( p ); // get the other parent entity from the persistence context.
results.last(); // since the result set was scrolled to the end, the other parent entity's collection has been
// get the other parent entity from the persistence context. // properly initialized.
// since the result set was scrolled to the end, the other parent entity's collection has been Parent pOther = null;
// properly initialized. Set childrenOther = new HashSet();
Parent pOther = null; for ( Object entity : ( ( SessionImplementor) s ).getPersistenceContext().getEntitiesByKey().values() ) {
Set childrenOther = new HashSet(); if ( Parent.class.isInstance( entity ) ) {
for ( Object entity : ( ( SessionImplementor) s ).getPersistenceContext().getEntitiesByKey().values() ) { if ( entity != p ) {
if ( Parent.class.isInstance( entity ) ) { if ( pOther != null ) {
if ( entity != p ) { fail( "unexpected parent found." );
if ( pOther != null ) {
fail( "unexpected parent found." );
}
pOther = (Parent) entity;
} }
} pOther = (Parent) entity;
else if ( Child.class.isInstance( entity ) ) {
if ( ! p.getChildren().contains( entity ) ) {
childrenOther.add( entity );
}
}
else {
fail( "unexpected type of entity." );
} }
} }
// check that the same second parent is obtained by calling Session.get() else if ( Child.class.isInstance( entity ) ) {
assertSame( pOther, s.get( Parent.class, "parent2" ) ); if ( ! p.getChildren().contains( entity ) ) {
assertNotNull( pOther ); childrenOther.add( entity );
// access pOther's collection; should be completely loaded }
assertTrue( Hibernate.isInitialized( pOther.getChildren() ) ); }
assertEquals( childrenOther, pOther.getChildren() ); else {
assertResultFromOneUser( pOther ); fail( "unexpected type of entity." );
s.close(); }
}
finally {
deleteAll();
} }
// check that the same second parent is obtained by calling Session.get()
assertSame( pOther, s.get( Parent.class, "parent2" ) );
assertNotNull( pOther );
// access pOther's collection; should be completely loaded
assertTrue( Hibernate.isInitialized( pOther.getChildren() ) );
assertEquals( childrenOther, pOther.getChildren() );
assertResultFromOneUser( pOther );
s.close();
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testScrollOrderParentAsc() { public void testScrollOrderParentAsc() {
try { Session s = openSession();
insertTestData(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
Session s = openSession(); List list = new ArrayList();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); while ( results.next() ) {
List list = new ArrayList(); list.add( results.get( 0 ) );
while ( results.next() ) {
list.add( results.get( 0 ) );
}
assertResultFromAllUsers( list );
s.close();
}
finally {
deleteAll();
} }
assertResultFromAllUsers( list );
s.close();
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testScrollOrderParentDesc() { public void testScrollOrderParentDesc() {
try { Session s = openSession();
insertTestData(); ScrollableResults results = s.createQuery( QUERY + " order by p.name desc" ).scroll();
Session s = openSession(); List list = new ArrayList();
ScrollableResults results = s.createQuery( QUERY + " order by p.name desc" ).scroll(); while ( results.next() ) {
List list = new ArrayList(); list.add( results.get( 0 ) );
while ( results.next() ) {
list.add( results.get( 0 ) );
}
assertResultFromAllUsers( list );
s.close();
}
finally {
deleteAll();
} }
assertResultFromAllUsers( list );
s.close();
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testScrollOrderParentAscChildrenAsc() { public void testScrollOrderParentAscChildrenAsc() {
try { Session s = openSession();
insertTestData(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name asc" ).scroll();
Session s = openSession(); List list = new ArrayList();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name asc" ).scroll(); while ( results.next() ) {
List list = new ArrayList(); list.add( results.get( 0 ) );
while ( results.next() ) {
list.add( results.get( 0 ) );
}
assertResultFromAllUsers( list );
s.close();
}
finally {
deleteAll();
} }
assertResultFromAllUsers( list );
s.close();
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testScrollOrderParentAscChildrenDesc() { public void testScrollOrderParentAscChildrenDesc() {
try { Session s = openSession();
insertTestData(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name desc" ).scroll();
Session s = openSession(); List list = new ArrayList();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name desc" ).scroll(); while ( results.next() ) {
List list = new ArrayList(); list.add( results.get( 0 ) );
while ( results.next() ) {
list.add( results.get( 0 ) );
}
assertResultFromAllUsers( list );
s.close();
}
finally {
deleteAll();
} }
assertResultFromAllUsers( list );
s.close();
} }
@Test @Test
public void testScrollOrderChildrenDesc() { public void testScrollOrderChildrenDesc() {
Session s = openSession();
Transaction t = s.beginTransaction();
Parent p0 = new Parent( "parent0" );
s.save( p0 );
t.commit();
s.close();
s = openSession();
ScrollableResults results = s.createQuery( QUERY + " order by c.name desc" ).scroll();
List list = new ArrayList();
while ( results.next() ) {
list.add( results.get( 0 ) );
}
try { try {
insertTestData(); assertResultFromAllUsers( list );
Session s = openSession(); fail( "should have failed because data is ordered incorrectly." );
Transaction t = s.beginTransaction(); }
Parent p0 = new Parent( "parent0" ); catch ( AssertionError ex ) {
s.save( p0 ); // expected
t.commit();
s.close();
s = openSession();
ScrollableResults results = s.createQuery( QUERY + " order by c.name desc" ).scroll();
List list = new ArrayList();
while ( results.next() ) {
list.add( results.get( 0 ) );
}
try {
assertResultFromAllUsers( list );
fail( "should have failed because data is ordered incorrectly." );
}
catch ( AssertionError ex ) {
// expected
}
finally {
s.close();
}
} }
finally { finally {
deleteAll(); s.close();
} }
} }
@Test @Test
public void testListOrderChildrenDesc() { public void testListOrderChildrenDesc() {
Session s = openSession();
Transaction t = s.beginTransaction();
Parent p0 = new Parent( "parent0" );
s.save( p0 );
t.commit();
s.close();
s = openSession();
List results = s.createQuery( QUERY + " order by c.name desc" ).list();
try { try {
insertTestData(); assertResultFromAllUsers( results );
Session s = openSession(); fail( "should have failed because data is ordered incorrectly." );
Transaction t = s.beginTransaction(); }
Parent p0 = new Parent( "parent0" ); catch ( AssertionError ex ) {
s.save( p0 ); // expected
t.commit();
s.close();
s = openSession();
List results = s.createQuery( QUERY + " order by c.name desc" ).list();
try {
assertResultFromAllUsers( results );
fail( "should have failed because data is ordered incorrectly." );
}
catch ( AssertionError ex ) {
// expected
}
finally {
s.close();
}
} }
finally { finally {
deleteAll(); s.close();
} }
} }
@ -388,7 +300,44 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
} }
} }
private void deleteAll() { @Override
protected void prepareTest() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
Child child_1_1 = new Child( "achild1-1");
Child child_1_2 = new Child( "ychild1-2");
Child child_1_3 = new Child( "dchild1-3");
Child child_2_1 = new Child( "bchild2-1");
Child child_2_2 = new Child( "cchild2-2");
Child child_2_3 = new Child( "zchild2-3");
s.save( child_1_1 );
s.save( child_2_1 );
s.save( child_1_2 );
s.save( child_2_2 );
s.save( child_1_3 );
s.save( child_2_3 );
s.flush();
Parent p1 = new Parent( "parent1" );
p1.addChild( child_1_1 );
p1.addChild( child_1_2 );
p1.addChild( child_1_3 );
s.save( p1 );
Parent p2 = new Parent( "parent2" );
p2.addChild( child_2_1 );
p2.addChild( child_2_2 );
p2.addChild( child_2_3 );
s.save( p2 );
t.commit();
s.close();
}
@Override
protected void cleanupTest() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
List list = s.createQuery( "from Parent" ).list(); List list = s.createQuery( "from Parent" ).list();
@ -398,59 +347,8 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
t.commit(); t.commit();
s.close(); s.close();
} }
private void insertTestData() {
Session s = openSession();
Transaction t = s.beginTransaction();
Child child_1_1 = new Child( "achild1-1");
Child child_1_2 = new Child( "ychild1-2");
Child child_1_3 = new Child( "dchild1-3");
Child child_2_1 = new Child( "bchild2-1");
Child child_2_2 = new Child( "cchild2-2");
Child child_2_3 = new Child( "zchild2-3");
s.save( child_1_1 );
s.save( child_2_1 );
s.save( child_1_2 );
s.save( child_2_2 );
s.save( child_1_3 );
s.save( child_2_3 );
s.flush();
Parent p1 = new Parent( "parent1" );
p1.addChild( child_1_1 );
p1.addChild( child_1_2 );
p1.addChild( child_1_3 );
s.save( p1 );
Parent p2 = new Parent( "parent2" );
p2.addChild( child_2_1 );
p2.addChild( child_2_2 );
p2.addChild( child_2_3 );
s.save( p2 );
t.commit();
s.close();
}
// private void insertTestData() {
// Session s = openSession();
// Transaction t = s.beginTransaction();
// s.save( makeParent( "parent1", "child1-1", "child1-2", "child1-3" ) );
// s.save( makeParent( "parent2", "child2-1", "child2-2", "child2-3" ) );
// t.commit();
// s.close();
// }
public String[] getMappings() { public String[] getMappings() {
return new String[] { "hqlfetchscroll/ParentChild.hbm.xml" }; return new String[] { "hqlfetchscroll/ParentChild.hbm.xml" };
} }
// protected Object makeParent(String name, String child1, String child2, String child3) {
// Parent parent = new Parent( name );
// parent.addChild( new Child( child1 ) );
// parent.addChild( new Child( child2 ) );
// parent.addChild( new Child( child3 ) );
// return parent;
// }
} }

View File

@ -23,6 +23,11 @@
*/ */
package org.hibernate.jpa.test.packaging; package org.hibernate.jpa.test.packaging;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
@ -30,12 +35,12 @@ import java.net.URLConnection;
import java.net.URLStreamHandler; import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory; import java.net.URLStreamHandlerFactory;
import java.util.Set; import java.util.Set;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import org.junit.Test; import org.hibernate.dialect.H2Dialect;
import org.hibernate.jpa.packaging.internal.ClassFilter; import org.hibernate.jpa.packaging.internal.ClassFilter;
import org.hibernate.jpa.packaging.internal.Entry; import org.hibernate.jpa.packaging.internal.Entry;
import org.hibernate.jpa.packaging.internal.ExplodedJarVisitor; import org.hibernate.jpa.packaging.internal.ExplodedJarVisitor;
@ -47,20 +52,17 @@ import org.hibernate.jpa.packaging.internal.JarProtocolVisitor;
import org.hibernate.jpa.packaging.internal.JarVisitor; import org.hibernate.jpa.packaging.internal.JarVisitor;
import org.hibernate.jpa.packaging.internal.JarVisitorFactory; import org.hibernate.jpa.packaging.internal.JarVisitorFactory;
import org.hibernate.jpa.packaging.internal.PackageFilter; import org.hibernate.jpa.packaging.internal.PackageFilter;
import org.hibernate.jpa.test.pack.explodedpar.Carpet;
import org.hibernate.jpa.test.pack.defaultpar.Version; import org.hibernate.jpa.test.pack.defaultpar.Version;
import org.hibernate.jpa.test.pack.explodedpar.Carpet;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
* @author Hardy Ferentschik * @author Hardy Ferentschik
*/ */
@RequiresDialect( H2Dialect.class ) // Nothing dialect-specific -- no need to run in matrix.
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class JarVisitorTest extends PackagingTestCase { public class JarVisitorTest extends PackagingTestCase {
@Test @Test

View File

@ -447,7 +447,9 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
sessionFactory.getCache().evictNaturalIdRegions(); sessionFactory.getCache().evictNaturalIdRegions();
} }
} }
protected boolean isCleanupTestDataRequired(){return false;}
protected boolean isCleanupTestDataRequired() { return false; }
protected void cleanupTestData() throws Exception { protected void cleanupTestData() throws Exception {
Session s = openSession(); Session s = openSession();
s.beginTransaction(); s.beginTransaction();