From 6f947f2ab018272ef547cc23693dd836629cc472 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Tue, 3 Jun 2014 21:28:24 -0700 Subject: [PATCH] HHH-5690 : Entity cache after persist, flush, rollback (test case) (cherry picked from commit dad4c64d5694262eee86f4645ac61dffa489b03e) Conflicts: hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java --- .../BasicTransactionalTestCase.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java index 46e8cc1b3b..5c1fdbc75f 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java @@ -45,6 +45,7 @@ import org.hibernate.cfg.Configuration; import org.hibernate.stat.SecondLevelCacheStatistics; import org.hibernate.stat.Statistics; import org.hibernate.testing.FailureExpectedWithNewUnifiedXsd; +import org.hibernate.testing.TestForIssue; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; @@ -221,6 +222,56 @@ public class BasicTransactionalTestCase extends AbstractFunctionalTestCase { } } + @Test + @TestForIssue( jiraKey = "HHH-5690") + public void testPersistEntityFlushRollbackNotInEntityCache() throws Exception { + Statistics stats = sessionFactory().getStatistics(); + stats.clear(); + + Item item = null; + Transaction txn = null; + Session s = null; + + beginTx(); + try { + s = openSession(); + txn = s.beginTransaction(); + item = new Item(); + item.setName( "steve" ); + item.setDescription( "steve's item" ); + s.persist( item ); + s.flush(); + setRollbackOnlyTx(); + } + catch (Exception e) { + setRollbackOnlyTx( e ); + } + finally { + commitOrRollbackTx(); + s.close(); + } + + // item should not be in entity cache. + SecondLevelCacheStatistics slcs = stats.getSecondLevelCacheStatistics( Item.class.getName() ); + assertTrue( slcs.getEntries().isEmpty() ); + + beginTx(); + try { + s = openSession(); + txn = s.beginTransaction(); + item = (Item) s.get( Item.class, item.getId() ); + assertNull( item ); + txn.commit(); + s.close(); + } + catch (Exception e) { + setRollbackOnlyTx( e ); + } + finally { + commitOrRollbackTx(); + } + } + @Test @FailureExpectedWithNewUnifiedXsd public void testQueryCacheInvalidation() throws Exception {