From 957a210610b7e67d0f75a8708ade90f87b9f0142 Mon Sep 17 00:00:00 2001 From: Radim Vansa Date: Mon, 5 Oct 2015 12:47:25 +0200 Subject: [PATCH] HHH-10163 QueryResultsRegion is not invalidated from evictAll() --- .../impl/BaseTransactionalDataRegion.java | 18 +++++++++++++++--- .../query/QueryResultsRegionImpl.java | 6 ++++++ .../infinispan/query/QueryRegionImplTest.java | 17 +++++++++++++---- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java index f4fdd377ef..9cb25ee5a7 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java @@ -64,7 +64,7 @@ public abstract class BaseTransactionalDataRegion private Strategy strategy; protected enum Strategy { - VALIDATION, TOMBSTONES, VERSIONED_ENTRIES + NONE, VALIDATION, TOMBSTONES, VERSIONED_ENTRIES } /** @@ -89,6 +89,16 @@ public abstract class BaseTransactionalDataRegion && !configuration.transaction().autoCommit(); // TODO: make these timeouts configurable tombstoneExpiration = InfinispanRegionFactory.PENDING_PUTS_CACHE_CONFIGURATION.expiration().maxIdle(); + if (!isRegionAccessStrategyEnabled()) { + strategy = Strategy.NONE; + } + } + + /** + * @return True if this region is accessed through RegionAccessStrategy, false if it is accessed directly. + */ + protected boolean isRegionAccessStrategyEnabled() { + return true; } @Override @@ -182,9 +192,10 @@ public abstract class BaseTransactionalDataRegion @Override protected void runInvalidation(boolean inTransaction) { if (strategy == null) { - return; + throw new IllegalStateException("Strategy was not set"); } switch (strategy) { + case NONE: case VALIDATION: super.runInvalidation(inTransaction); return; @@ -247,9 +258,10 @@ public abstract class BaseTransactionalDataRegion @Override public Map toMap() { if (strategy == null) { - return Collections.EMPTY_MAP; + throw new IllegalStateException("Strategy was not set"); } switch (strategy) { + case NONE: case VALIDATION: return super.toMap(); case TOMBSTONES: diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/query/QueryResultsRegionImpl.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/query/QueryResultsRegionImpl.java index 18d18b66fe..c04c0302c0 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/query/QueryResultsRegionImpl.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/query/QueryResultsRegionImpl.java @@ -74,6 +74,12 @@ public class QueryResultsRegionImpl extends BaseTransactionalDataRegion implemen if (transactional) { log.warn("Use non-transactional query caches for best performance!"); } + + } + + @Override + protected boolean isRegionAccessStrategyEnabled() { + return false; } @Override diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTest.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTest.java index cf8581bd20..eadc2a707f 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTest.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTest.java @@ -42,10 +42,7 @@ import org.infinispan.util.concurrent.IsolationLevel; import org.jboss.logging.Logger; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Tests of QueryResultRegionImpl. @@ -379,6 +376,18 @@ public class QueryRegionImplTest extends AbstractGeneralDataRegionTest { }); } + @Test + @TestForIssue(jiraKey = "HHH-10163") + public void testEvictAll() throws Exception { + withQueryRegion((sessionFactory, region) -> { + withSession(sessionFactory, s -> region.put(s, KEY, VALUE1)); + withSession(sessionFactory, s -> assertEquals(VALUE1, region.get(s, KEY))); + region.evictAll(); + withSession(sessionFactory, s -> assertNull(region.get(s, KEY))); + assertEquals(Collections.EMPTY_MAP, region.toMap()); + }); + } + @Listener public class GetBlocker { private final CountDownLatch latch;