geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasonhu...@apache.org
Subject geode git commit: GEODE-3021: Any call after the first to setPdxStringFlag should no-op
Date Thu, 01 Jun 2017 20:55:59 GMT
Repository: geode
Updated Branches:
  refs/heads/feature/GEODE-3021 [created] e17ad3d22


GEODE-3021: Any call after the first to setPdxStringFlag should no-op

  * The flag isIndexedPdxKeysFlagSet is now checked before setting pdx string flag


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/e17ad3d2
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/e17ad3d2
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/e17ad3d2

Branch: refs/heads/feature/GEODE-3021
Commit: e17ad3d226014e83d21219f2a992caaa73c55018
Parents: 0845152
Author: Jason Huynh <huynhja@gmail.com>
Authored: Thu Jun 1 13:52:41 2017 -0700
Committer: Jason Huynh <huynhja@gmail.com>
Committed: Thu Jun 1 13:55:43 2017 -0700

----------------------------------------------------------------------
 .../query/internal/index/AbstractIndex.java     |  7 ++-
 ...AbstractIndexMaintenanceIntegrationTest.java | 61 ++++++++++++++++++++
 2 files changed, 67 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/e17ad3d2/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/AbstractIndex.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/AbstractIndex.java
b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/AbstractIndex.java
index d9a4e2e..c0e7885 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/AbstractIndex.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/AbstractIndex.java
@@ -2002,7 +2002,8 @@ public abstract class AbstractIndex implements IndexProtocol {
    */
   synchronized void setPdxStringFlag(Object key) {
     // For Null and Undefined keys do not set the isIndexedPdxKeysFlagSet flag
-    if (key == null || key == IndexManager.NULL || key == QueryService.UNDEFINED) {
+    if (isIndexedPdxKeysFlagSet || key == null || key == IndexManager.NULL
+        || key == QueryService.UNDEFINED) {
       return;
     }
     if (!this.isIndexedPdxKeys) {
@@ -2080,4 +2081,8 @@ public abstract class AbstractIndex implements IndexProtocol {
   public void setPopulated(boolean isPopulated) {
     this.isPopulated = isPopulated;
   }
+
+  boolean isIndexOnPdxKeys() {
+    return isIndexedPdxKeys;
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/e17ad3d2/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/AbstractIndexMaintenanceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/AbstractIndexMaintenanceIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/AbstractIndexMaintenanceIntegrationTest.java
index 66ed117..8fbc6d0 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/AbstractIndexMaintenanceIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/AbstractIndexMaintenanceIntegrationTest.java
@@ -14,6 +14,10 @@
  */
 package org.apache.geode.cache.query.internal.index;
 
+import static junit.framework.TestCase.assertFalse;
+import static org.apache.geode.internal.Assert.assertTrue;
+
+import org.apache.geode.pdx.internal.PdxString;
 import org.junit.After;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -40,6 +44,44 @@ public abstract class AbstractIndexMaintenanceIntegrationTest {
   }
 
   @Test
+  public void setPdxStringFlagWithAPdxStringShouldNotBeChangedAfterTheFirstCall() throws
Exception {
+    CacheUtils.startCache();
+    Cache cache = CacheUtils.getCache();
+    LocalRegion region =
+        (LocalRegion) cache.createRegionFactory(RegionShortcut.REPLICATE).create("portfolios");
+    QueryService qs = cache.getQueryService();
+    AbstractIndex statusIndex =
+        createIndex(qs, "statusIndex", "value.status", "/portfolios.entrySet()");
+
+    statusIndex.setPdxStringFlag("StringKey");
+    assertTrue(statusIndex.isIndexedPdxKeysFlagSet);
+    assertFalse(statusIndex.isIndexOnPdxKeys());
+
+    statusIndex.setPdxStringFlag(new PdxString("PdxString Key"));
+    assertTrue(statusIndex.isIndexedPdxKeysFlagSet);
+    assertFalse(statusIndex.isIndexOnPdxKeys());
+  }
+
+  @Test
+  public void setPdxStringFlagWithAStringShouldNotBeChangedAfterTheFirstCall() throws Exception
{
+    CacheUtils.startCache();
+    Cache cache = CacheUtils.getCache();
+    LocalRegion region =
+        (LocalRegion) cache.createRegionFactory(RegionShortcut.REPLICATE).create("portfolios");
+    QueryService qs = cache.getQueryService();
+    AbstractIndex statusIndex =
+        createIndex(qs, "statusIndex", "value.status", "/portfolios.entrySet()");
+
+    statusIndex.setPdxStringFlag(new PdxString("PdxString Key"));
+    assertTrue(statusIndex.isIndexedPdxKeysFlagSet);
+    assertTrue(statusIndex.isIndexOnPdxKeys());
+
+    statusIndex.setPdxStringFlag("PdxString Key");
+    assertTrue(statusIndex.isIndexedPdxKeysFlagSet);
+    assertTrue(statusIndex.isIndexOnPdxKeys());
+  }
+
+  @Test
   public void whenRemovingRegionEntryFromIndexIfEntryDestroyedIsThrownCorrectlyRemoveFromIndexAndNotThrowException()
       throws Exception {
     CacheUtils.startCache();
@@ -58,6 +100,25 @@ public abstract class AbstractIndexMaintenanceIntegrationTest {
     statusIndex.removeIndexMapping(entry, IndexProtocol.OTHER_OP);
   }
 
+  @Test
+  public void testX() throws Exception {
+    CacheUtils.startCache();
+    Cache cache = CacheUtils.getCache();
+    LocalRegion region =
+        (LocalRegion) cache.createRegionFactory(RegionShortcut.REPLICATE).create("portfolios");
+    QueryService qs = cache.getQueryService();
+    AbstractIndex statusIndex = createIndex(qs, "statusIndex", "status", "/portfolios");
+
+    for (int i = 0; i < 100000; i++) {
+      PortfolioPdx p = new PortfolioPdx(i);
+      region.put("KEY-1" + i, p);
+    }
+    qs.newQuery("<trace>select * from /portfolios where status like '%active%'").execute();
+    qs.newQuery("<trace>select * from /portfolios where status like '%ddddddd%'").execute();
+    qs.newQuery("<trace>select * from /portfolios where status like '%active%'").execute();
+    qs.newQuery("<trace>select * from /portfolios where status like '%DDDDDD%'").execute();
+  }
+
   protected abstract AbstractIndex createIndex(final QueryService qs, String name,
       String indexExpression, String regionPath)
       throws IndexNameConflictException, IndexExistsException, RegionNotFoundException;


Mime
View raw message