HHH-9994 - Finish mariadb (mysql) database profile - Fix hibernate-envers tests hang on

This commit is contained in:
Andrea Boriero 2015-08-19 18:11:20 +01:00
parent 300aa418fb
commit 444c7f0eda
16 changed files with 65 additions and 14 deletions

View File

@ -58,3 +58,9 @@ jar {
'org.apache.tools.ant;resolution:=optional' 'org.apache.tools.ant;resolution:=optional'
} }
} }
tasks."matrix_mariadb" {
beforeTest { descriptor ->
println "Starting test: " + descriptor
}
}

View File

@ -14,6 +14,7 @@ import org.hibernate.Session;
import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory; import org.hibernate.envers.AuditReaderFactory;
import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.configuration.EnversSettings;
import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -52,6 +53,11 @@ public abstract class BaseEnversFunctionalTestCase extends BaseNonConfigCoreFunc
} }
protected AuditReader getAuditReader() { protected AuditReader getAuditReader() {
Session session = getSession();
if(session.getTransaction().getStatus() != TransactionStatus.ACTIVE ){
session.getTransaction().begin();
}
return AuditReaderFactory.get( getSession() ); return AuditReaderFactory.get( getSession() );
} }

View File

@ -12,6 +12,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.transaction.SystemException; import javax.transaction.SystemException;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
@ -29,12 +30,14 @@ import org.hibernate.jpa.HibernateEntityManagerFactory;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.spi.Bootstrap; import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.internal.EntityManagerImpl;
import org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter; import org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter;
import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.BeforeClassOnce; import org.hibernate.testing.BeforeClassOnce;
import org.hibernate.testing.jta.TestingJtaPlatformImpl; import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import org.hibernate.testing.junit4.Helper; import org.hibernate.testing.junit4.Helper;
import org.junit.After; import org.junit.After;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -263,10 +266,28 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest
} }
protected AuditReader getAuditReader() { protected AuditReader getAuditReader() {
EntityManager entityManager = getOrCreateEntityManager();
PersistenceUnitTransactionType transactionType = ((EntityManagerImpl) entityManager).getTransactionType();
if ( transactionType == PersistenceUnitTransactionType.JTA ) {
if ( !JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) ) {
try {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
else if ( !entityManager.getTransaction().isActive() ) {
entityManager.getTransaction().begin();
}
if ( auditReader != null ) { if ( auditReader != null ) {
return auditReader; return auditReader;
} }
return auditReader = AuditReaderFactory.get( getOrCreateEntityManager() );
return auditReader = AuditReaderFactory.get( entityManager );
} }
protected EntityManager createIsolatedEntityManager() { protected EntityManager createIsolatedEntityManager() {

View File

@ -9,6 +9,7 @@ package org.hibernate.envers.test.integration.basic;
import java.util.Map; import java.util.Map;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.envers.configuration.EnversSettings; import org.hibernate.envers.configuration.EnversSettings;
import org.hibernate.envers.exception.AuditException; import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.test.BaseEnversFunctionalTestCase; import org.hibernate.envers.test.BaseEnversFunctionalTestCase;
@ -16,13 +17,16 @@ import org.hibernate.envers.test.entities.StrTestEntity;
import org.hibernate.envers.test.integration.collection.norevision.Name; import org.hibernate.envers.test.integration.collection.norevision.Name;
import org.hibernate.envers.test.integration.collection.norevision.Person; import org.hibernate.envers.test.integration.collection.norevision.Person;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.junit.Test; import org.junit.Test;
/** /**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/ */
@TestForIssue(jiraKey = "HHH-5565") @TestForIssue(jiraKey = "HHH-5565")
@SkipForDialect(value = MySQL5Dialect.class, comment = "The test hangs on")
public class OutsideTransactionTest extends BaseEnversFunctionalTestCase { public class OutsideTransactionTest extends BaseEnversFunctionalTestCase {
@Override @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {

View File

@ -63,6 +63,8 @@ public abstract class AbstractCollectionChangeTest extends BaseEnversFunctionalT
session.getTransaction().commit(); session.getTransaction().commit();
personId = p.getId(); personId = p.getId();
session.close();
} }
@Test @Test

View File

@ -448,7 +448,6 @@ public class DefaultValueComponents extends BaseEnversJPAFunctionalTestCase {
String expectedComp2Str1Rev1, String expectedComp2Str1Rev2) { String expectedComp2Str1Rev1, String expectedComp2Str1Rev2) {
// Verify that the entity was correctly persisted // Verify that the entity was correctly persisted
EntityManager em = getEntityManager(); EntityManager em = getEntityManager();
em.getTransaction().begin();
Long entCount = (Long) em.createQuery( Long entCount = (Long) em.createQuery(
"select count(s) from DefaultValueComponentTestEntity s where s.id = " "select count(s) from DefaultValueComponentTestEntity s where s.id = "
+ expectedId.toString() + expectedId.toString()
@ -483,6 +482,5 @@ public class DefaultValueComponents extends BaseEnversJPAFunctionalTestCase {
else { else {
assert expectedComp2Str1Rev2.equals( comp2Str1Rev2 ); assert expectedComp2Str1Rev2.equals( comp2Str1Rev2 );
} }
em.getTransaction().commit();
} }
} }

View File

@ -57,6 +57,7 @@ public class EmbeddableWithDeclaredDataTest extends BaseEnversJPAFunctionalTestC
// Reload and Compare Revision // Reload and Compare Revision
EntityManager em = getEntityManager(); EntityManager em = getEntityManager();
em.getTransaction().begin();
EntityWithEmbeddableWithDeclaredData entityLoaded = em.find( EntityWithEmbeddableWithDeclaredData.class, id ); EntityWithEmbeddableWithDeclaredData entityLoaded = em.find( EntityWithEmbeddableWithDeclaredData.class, id );
AuditReader reader = AuditReaderFactory.get( em ); AuditReader reader = AuditReaderFactory.get( em );
@ -65,7 +66,7 @@ public class EmbeddableWithDeclaredDataTest extends BaseEnversJPAFunctionalTestC
Assert.assertEquals( 1, revs.size() ); Assert.assertEquals( 1, revs.size() );
EntityWithEmbeddableWithDeclaredData entityRev1 = reader.find( EntityWithEmbeddableWithDeclaredData.class, id, revs.get( 0 ) ); EntityWithEmbeddableWithDeclaredData entityRev1 = reader.find( EntityWithEmbeddableWithDeclaredData.class, id, revs.get( 0 ) );
em.getTransaction().commit();
Assert.assertEquals( entityLoaded.getName(), entityRev1.getName() ); Assert.assertEquals( entityLoaded.getName(), entityRev1.getName() );
// only value.codeArt should be audited because it is the only audited field in EmbeddableWithDeclaredData; // only value.codeArt should be audited because it is the only audited field in EmbeddableWithDeclaredData;

View File

@ -55,6 +55,7 @@ public class EmbeddableWithNoDeclaredDataTest extends BaseEnversJPAFunctionalTes
// Reload and Compare Revision // Reload and Compare Revision
EntityManager em = getEntityManager(); EntityManager em = getEntityManager();
em.getTransaction().begin();
EntityWithEmbeddableWithNoDeclaredData entityLoaded = em.find( EntityWithEmbeddableWithNoDeclaredData.class, id ); EntityWithEmbeddableWithNoDeclaredData entityLoaded = em.find( EntityWithEmbeddableWithNoDeclaredData.class, id );
AuditReader reader = AuditReaderFactory.get( em ); AuditReader reader = AuditReaderFactory.get( em );
@ -64,6 +65,7 @@ public class EmbeddableWithNoDeclaredDataTest extends BaseEnversJPAFunctionalTes
EntityWithEmbeddableWithNoDeclaredData entityRev1 = reader.find( EntityWithEmbeddableWithNoDeclaredData.class, id, revs.get( 0 ) ); EntityWithEmbeddableWithNoDeclaredData entityRev1 = reader.find( EntityWithEmbeddableWithNoDeclaredData.class, id, revs.get( 0 ) );
em.getTransaction().commit();
Assert.assertEquals( entityLoaded.getName(), entityRev1.getName() ); Assert.assertEquals( entityLoaded.getName(), entityRev1.getName() );
// value should be null because there is no data in EmbeddableWithNoDeclaredData // value should be null because there is no data in EmbeddableWithNoDeclaredData

View File

@ -43,9 +43,11 @@ public class EnumTypeTest extends BaseEnversJPAFunctionalTestCase {
@Test @Test
public void testEnumRepresentation() { public void testEnumRepresentation() {
EntityManager entityManager = getEntityManager(); EntityManager entityManager = getEntityManager();
entityManager.getTransaction().begin();
List<Object[]> values = entityManager.createNativeQuery( List<Object[]> values = entityManager.createNativeQuery(
"SELECT enum1, enum2 FROM EnumTypeEntity_AUD ORDER BY rev ASC" "SELECT enum1, enum2 FROM EnumTypeEntity_AUD ORDER BY rev ASC"
).getResultList(); ).getResultList();
entityManager.getTransaction().commit();
entityManager.close(); entityManager.close();
Assert.assertNotNull( values ); Assert.assertNotNull( values );

View File

@ -60,8 +60,6 @@ public class AddDelTest extends BaseEnversFunctionalTestCase {
public void testRevisionsCountOfGivenIdStrEntity() { public void testRevisionsCountOfGivenIdStrEntity() {
// Revision 2 has not changed entity's state. // Revision 2 has not changed entity's state.
Assert.assertEquals( Arrays.asList( 1, 3 ), getAuditReader().getRevisions( GivenIdStrEntity.class, 1 ) ); Assert.assertEquals( Arrays.asList( 1, 3 ), getAuditReader().getRevisions( GivenIdStrEntity.class, 1 ) );
getSession().close();
} }
@Test @Test
@ -74,7 +72,5 @@ public class AddDelTest extends BaseEnversFunctionalTestCase {
3 3
) )
); );
getSession().close();
} }
} }

View File

@ -106,8 +106,12 @@ public class BasicJoinColumnSet extends BaseEnversJPAFunctionalTestCase {
@Test @Test
public void testHistoryOfColl1() { public void testHistoryOfColl1() {
StrTestEntity str1 = getEntityManager().find( StrTestEntity.class, str1_id ); EntityManager entityManager = getEntityManager();
StrTestEntity str2 = getEntityManager().find( StrTestEntity.class, str2_id ); entityManager.getTransaction().begin();
StrTestEntity str1 = entityManager.find( StrTestEntity.class, str1_id );
StrTestEntity str2 = entityManager.find( StrTestEntity.class, str2_id );
entityManager.getTransaction().commit();
SetJoinColumnRefCollEntity rev1 = getAuditReader().find( SetJoinColumnRefCollEntity.class, coll1_id, 1 ); SetJoinColumnRefCollEntity rev1 = getAuditReader().find( SetJoinColumnRefCollEntity.class, coll1_id, 1 );
SetJoinColumnRefCollEntity rev2 = getAuditReader().find( SetJoinColumnRefCollEntity.class, coll1_id, 2 ); SetJoinColumnRefCollEntity rev2 = getAuditReader().find( SetJoinColumnRefCollEntity.class, coll1_id, 2 );

View File

@ -65,6 +65,8 @@ public class AuditedCollectionProxyTest extends BaseEnversJPAFunctionalTestCase
public void testProxyIdentifier() { public void testProxyIdentifier() {
EntityManager em = getEntityManager(); EntityManager em = getEntityManager();
em.getTransaction().begin();
ListRefEdEntity listReferencedEntity1 = em.getReference( ListRefEdEntity listReferencedEntity1 = em.getReference(
ListRefEdEntity.class, id_ListRefEdEntity1 ListRefEdEntity.class, id_ListRefEdEntity1
); );
@ -76,12 +78,10 @@ public class AuditedCollectionProxyTest extends BaseEnversJPAFunctionalTestCase
Integer.valueOf( 3 ), "refing3", listReferencedEntity1 Integer.valueOf( 3 ), "refing3", listReferencedEntity1
); );
em.getTransaction().begin();
em.persist( refingEntity3 ); em.persist( refingEntity3 );
em.getTransaction().commit();
listReferencedEntity1.getReffering().size(); listReferencedEntity1.getReffering().size();
em.getTransaction().commit();
} }
} }

View File

@ -71,6 +71,5 @@ public class QueryingWithProxyObjectTest extends BaseEnversFunctionalTestCase {
.getSingleResult(); .getSingleResult();
Assert.assertEquals( originalSte, ste ); Assert.assertEquals( originalSte, ste );
getSession().close();
} }
} }

View File

@ -43,6 +43,7 @@ public class ReadWriteExpressionChange extends BaseEnversJPAFunctionalTestCase {
@Test @Test
public void shouldRespectWriteExpression() { public void shouldRespectWriteExpression() {
EntityManager em = getEntityManager(); EntityManager em = getEntityManager();
em.getTransaction().begin();
List resultList = em.createNativeQuery( "select size_in_cm from t_staff_AUD where id =" + id ).getResultList(); List resultList = em.createNativeQuery( "select size_in_cm from t_staff_AUD where id =" + id ).getResultList();
Assert.assertEquals( 1, resultList.size() ); Assert.assertEquals( 1, resultList.size() );
Double sizeInCm = null; Double sizeInCm = null;
@ -52,6 +53,7 @@ public class ReadWriteExpressionChange extends BaseEnversJPAFunctionalTestCase {
else { else {
sizeInCm = (Double) resultList.get( 0 ); sizeInCm = (Double) resultList.get( 0 );
} }
em.getTransaction().commit();
Assert.assertEquals( HEIGHT_CENTIMETERS, sizeInCm.doubleValue(), 0.00000001 ); Assert.assertEquals( HEIGHT_CENTIMETERS, sizeInCm.doubleValue(), 0.00000001 );
} }

View File

@ -8,9 +8,13 @@ package org.hibernate.envers.test.integration.reventity.removal;
import org.hibernate.envers.enhanced.SequenceIdRevisionEntity; import org.hibernate.envers.enhanced.SequenceIdRevisionEntity;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
/** /**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/ */
@RequiresDialectFeature(DialectChecks.SupportsCascadeDeleteCheck.class)
public class RemoveDefaultRevisionEntity extends AbstractRevisionEntityRemovalTest { public class RemoveDefaultRevisionEntity extends AbstractRevisionEntityRemovalTest {
@Override @Override
protected Class<?> getRevisionEntityClass() { protected Class<?> getRevisionEntityClass() {

View File

@ -10,9 +10,13 @@ import java.util.Map;
import org.hibernate.envers.enhanced.SequenceIdTrackingModifiedEntitiesRevisionEntity; import org.hibernate.envers.enhanced.SequenceIdTrackingModifiedEntitiesRevisionEntity;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
/** /**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/ */
@RequiresDialectFeature(DialectChecks.SupportsCascadeDeleteCheck.class)
public class RemoveTrackingRevisionEntity extends AbstractRevisionEntityRemovalTest { public class RemoveTrackingRevisionEntity extends AbstractRevisionEntityRemovalTest {
@Override @Override
public void addConfigOptions(Map configuration) { public void addConfigOptions(Map configuration) {