DonalEvans commented on a change in pull request #6757:
URL: https://github.com/apache/geode/pull/6757#discussion_r694396652



##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/IndexMaintenanceJUnitTest.java
##########
@@ -1057,6 +1071,394 @@ public void testBug43597() throws Exception {
     region.put("1", pf1);
   }
 
+  /**
+   * Starting of section - moved from wrongly spelled old class 
"IndexMaintainceJUnitTest".
+   * GEODE-1505
+   */
+
+  @Test
+  public void test000BUG32452()
+      throws IndexNameConflictException, IndexExistsException, 
RegionNotFoundException {
+    Index i1 = qs.createIndex("tIndex", IndexType.FUNCTIONAL, "vals.secId",
+        SEPARATOR + "portfolio pf, pf.positions.values vals");
+    Index i2 = qs.createIndex("dIndex", IndexType.FUNCTIONAL, 
"pf.getCW(pf.ID)",
+        SEPARATOR + "portfolio pf");
+    Index i3 = qs.createIndex("fIndex", IndexType.FUNCTIONAL, "sIter",
+        SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter");
+    Index i4 = qs.createIndex("cIndex", IndexType.FUNCTIONAL,
+        "pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]", SEPARATOR + 
"portfolio pf");
+    Index i5 = qs.createIndex("inIndex", IndexType.FUNCTIONAL, "kIter.secId",
+        SEPARATOR + "portfolio['0'].positions.values kIter");
+    Index i6 = qs.createIndex("sIndex", IndexType.FUNCTIONAL, "pos.secId",
+        SEPARATOR + "portfolio.values val, val.positions.values pos");
+    Index i7 = qs.createIndex("p1Index", IndexType.PRIMARY_KEY, "pkid", 
SEPARATOR + "portfolio pf");
+    Index i8 = qs.createIndex("p2Index", IndexType.PRIMARY_KEY, "pk", 
SEPARATOR + "portfolio pf");
+    if (!i1.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio index_iter1, 
index_iter1.positions.values index_iter2")
+        || !i1.getCanonicalizedIndexedExpression().equals("index_iter2.secId")
+        || !i1.getFromClause().equals(SEPARATOR + "portfolio pf, 
pf.positions.values vals")
+        || !i1.getIndexedExpression().equals("vals.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i2.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || 
!i2.getCanonicalizedIndexedExpression().equals("index_iter1.getCW(index_iter1.ID)")
+        || !i2.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i2.getIndexedExpression().equals("pf.getCW(pf.ID)")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i3.getCanonicalizedFromClause().equals(
+        SEPARATOR
+            + "portfolio index_iter1, 
index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr index_iter3")
+        || !i3.getCanonicalizedIndexedExpression().equals("index_iter3")
+        || !i3.getFromClause()
+            .equals(
+                SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter")
+        || !i3.getIndexedExpression().equals("sIter")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i4.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i4.getCanonicalizedIndexedExpression().equals(
+            
"index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr[index_iter1.ID]")
+        || !i4.getFromClause().equals(SEPARATOR + "portfolio pf") || 
!i4.getIndexedExpression()
+            .equals("pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i5.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio['0'].positions.values index_iter4")
+        || !i5.getCanonicalizedIndexedExpression().equals("index_iter4.secId")
+        || !i5.getFromClause().equals(SEPARATOR + 
"portfolio['0'].positions.values kIter")
+        || !i5.getIndexedExpression().equals("kIter.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i6.getCanonicalizedFromClause()
+        .equals(
+            SEPARATOR + "portfolio.values index_iter5, 
index_iter5.positions.values index_iter6")
+        || !i6.getCanonicalizedIndexedExpression().equals("index_iter6.secId")
+        || !i6.getFromClause().equals(SEPARATOR + "portfolio.values val, 
val.positions.values pos")
+        || !i6.getIndexedExpression().equals("pos.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i7.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i7.getCanonicalizedIndexedExpression().equals("index_iter1.pkid")
+        || !i7.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i7.getIndexedExpression().equals("pkid")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i8.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i8.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i8.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i8.getIndexedExpression().equals("pk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i1);
+    qs.removeIndex(i2);
+    qs.removeIndex(i3);
+    qs.removeIndex(i4);
+    qs.removeIndex(i5);
+    qs.removeIndex(i6);
+    qs.removeIndex(i7);
+    qs.removeIndex(i8);
+    Index i9 =
+        qs.createIndex("p3Index", IndexType.PRIMARY_KEY, "getPk", SEPARATOR + 
"portfolio pf");
+    if (!i9.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i9.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i9.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i9.getIndexedExpression().equals("getPk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i9);
+  }
+
+  @Test
+  public void numberOfIndexValuesStatIsUpdatedWhenEntryAdded() throws 
Exception {
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    IndexStatistics stats = index.getStatistics();
+    assertEquals(4, stats.getNumberOfValues());
+    region.put("4", new Portfolio(4));
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    stats = index.getStatistics();
+    assertEquals(5, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(3, results.size());
+  }
+
+  /**
+   * Needed to fix this since the key "4" was not found and the size was then 
redueced to 3 after
+   * invalidating the key 3
+   */
+  @Test
+  public void testInvalidatingEntry() throws Exception {

Review comment:
       This test might be better named 
"numberOfIndexValuesStatIsUpdatedWhenEntryInvalidated"

##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/IndexMaintenanceJUnitTest.java
##########
@@ -1057,6 +1071,394 @@ public void testBug43597() throws Exception {
     region.put("1", pf1);
   }
 
+  /**
+   * Starting of section - moved from wrongly spelled old class 
"IndexMaintainceJUnitTest".
+   * GEODE-1505
+   */
+
+  @Test
+  public void test000BUG32452()
+      throws IndexNameConflictException, IndexExistsException, 
RegionNotFoundException {
+    Index i1 = qs.createIndex("tIndex", IndexType.FUNCTIONAL, "vals.secId",
+        SEPARATOR + "portfolio pf, pf.positions.values vals");
+    Index i2 = qs.createIndex("dIndex", IndexType.FUNCTIONAL, 
"pf.getCW(pf.ID)",
+        SEPARATOR + "portfolio pf");
+    Index i3 = qs.createIndex("fIndex", IndexType.FUNCTIONAL, "sIter",
+        SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter");
+    Index i4 = qs.createIndex("cIndex", IndexType.FUNCTIONAL,
+        "pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]", SEPARATOR + 
"portfolio pf");
+    Index i5 = qs.createIndex("inIndex", IndexType.FUNCTIONAL, "kIter.secId",
+        SEPARATOR + "portfolio['0'].positions.values kIter");
+    Index i6 = qs.createIndex("sIndex", IndexType.FUNCTIONAL, "pos.secId",
+        SEPARATOR + "portfolio.values val, val.positions.values pos");
+    Index i7 = qs.createIndex("p1Index", IndexType.PRIMARY_KEY, "pkid", 
SEPARATOR + "portfolio pf");
+    Index i8 = qs.createIndex("p2Index", IndexType.PRIMARY_KEY, "pk", 
SEPARATOR + "portfolio pf");
+    if (!i1.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio index_iter1, 
index_iter1.positions.values index_iter2")
+        || !i1.getCanonicalizedIndexedExpression().equals("index_iter2.secId")
+        || !i1.getFromClause().equals(SEPARATOR + "portfolio pf, 
pf.positions.values vals")
+        || !i1.getIndexedExpression().equals("vals.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i2.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || 
!i2.getCanonicalizedIndexedExpression().equals("index_iter1.getCW(index_iter1.ID)")
+        || !i2.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i2.getIndexedExpression().equals("pf.getCW(pf.ID)")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i3.getCanonicalizedFromClause().equals(
+        SEPARATOR
+            + "portfolio index_iter1, 
index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr index_iter3")
+        || !i3.getCanonicalizedIndexedExpression().equals("index_iter3")
+        || !i3.getFromClause()
+            .equals(
+                SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter")
+        || !i3.getIndexedExpression().equals("sIter")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i4.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i4.getCanonicalizedIndexedExpression().equals(
+            
"index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr[index_iter1.ID]")
+        || !i4.getFromClause().equals(SEPARATOR + "portfolio pf") || 
!i4.getIndexedExpression()
+            .equals("pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i5.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio['0'].positions.values index_iter4")
+        || !i5.getCanonicalizedIndexedExpression().equals("index_iter4.secId")
+        || !i5.getFromClause().equals(SEPARATOR + 
"portfolio['0'].positions.values kIter")
+        || !i5.getIndexedExpression().equals("kIter.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i6.getCanonicalizedFromClause()
+        .equals(
+            SEPARATOR + "portfolio.values index_iter5, 
index_iter5.positions.values index_iter6")
+        || !i6.getCanonicalizedIndexedExpression().equals("index_iter6.secId")
+        || !i6.getFromClause().equals(SEPARATOR + "portfolio.values val, 
val.positions.values pos")
+        || !i6.getIndexedExpression().equals("pos.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i7.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i7.getCanonicalizedIndexedExpression().equals("index_iter1.pkid")
+        || !i7.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i7.getIndexedExpression().equals("pkid")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i8.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i8.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i8.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i8.getIndexedExpression().equals("pk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i1);
+    qs.removeIndex(i2);
+    qs.removeIndex(i3);
+    qs.removeIndex(i4);
+    qs.removeIndex(i5);
+    qs.removeIndex(i6);
+    qs.removeIndex(i7);
+    qs.removeIndex(i8);
+    Index i9 =
+        qs.createIndex("p3Index", IndexType.PRIMARY_KEY, "getPk", SEPARATOR + 
"portfolio pf");
+    if (!i9.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i9.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i9.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i9.getIndexedExpression().equals("getPk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i9);
+  }
+
+  @Test
+  public void numberOfIndexValuesStatIsUpdatedWhenEntryAdded() throws 
Exception {
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    IndexStatistics stats = index.getStatistics();
+    assertEquals(4, stats.getNumberOfValues());
+    region.put("4", new Portfolio(4));
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    stats = index.getStatistics();
+    assertEquals(5, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(3, results.size());
+  }
+
+  /**
+   * Needed to fix this since the key "4" was not found and the size was then 
redueced to 3 after
+   * invalidating the key 3
+   */
+  @Test
+  public void testInvalidatingEntry() throws Exception {
+    IndexStatistics stats = index.getStatistics();
+    region.invalidate("3");
+    assertEquals(3, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(2, results.size());
+  }
+
+  @Test
+  public void testDestroyEntry() throws Exception {
+    IndexStatistics stats = index.getStatistics();
+    region.put("4", new Portfolio(4));
+    region.destroy("4");
+    assertEquals(4, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(2, results.size());
+  }
+
+  // This test has a meaning only for Trunk code as it checks for Map 
implementation
+  // Tests for Region clear operations on Index in a Local VM
+  @Test
+  public void testIndexClearanceOnMapClear() {
+    try {
+      CacheUtils.getCache();
+      isInitDone = false;
+      Query q =
+          qs.newQuery("SELECT DISTINCT * FROM " + SEPARATOR + "portfolio where 
status = 'active'");
+      QueryObserverHolder.setInstance(new QueryObserverAdapter() {
+
+        @Override
+        public void afterIndexLookup(Collection coll) {
+          IndexMaintenanceJUnitTest.this.indexUsed = true;
+        }
+      });
+      SelectResults set = (SelectResults) q.execute();
+      if (set.size() == 0 || !this.indexUsed) {
+        fail("Either Size of the result set is zero or Index is not used ");
+      }
+      this.indexUsed = false;
+
+      region.clear();
+      set = (SelectResults) q.execute();
+      if (set.size() != 0 || !this.indexUsed) {
+        fail("Either Size of the result set is not zero or Index is not used 
");
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.toString());
+    } finally {
+      isInitDone = false;
+      CacheUtils.restartCache();
+    }
+  }
+
+  // Asif : Tests for Region clear operations on Index in a Local VM for cases
+  // when a clear
+  // operation & region put operation occur concurrentlty
+  @Test
+  public void testConcurrentMapClearAndRegionPutOperation() {
+    try {
+      CacheUtils.getCache();
+      isInitDone = false;
+      Query q =
+          qs.newQuery("SELECT DISTINCT * FROM " + SEPARATOR + "portfolio where 
status = 'active'");
+      QueryObserverHolder.setInstance(new QueryObserverAdapter() {
+
+        @Override
+        public void afterIndexLookup(Collection coll) {
+          IndexMaintenanceJUnitTest.this.indexUsed = true;
+        }
+
+        @Override
+        public void beforeRerunningIndexCreationQuery() {
+          // Spawn a separate thread here which does a put opertion on region
+          Thread th = new Thread(new Runnable() {
+
+            @Override
+            public void run() {
+              // Assert that the size of region is now 0
+              assertTrue(region.size() == 0);
+              region.put("" + 8, new Portfolio(8));
+            }
+          });
+          th.start();
+          ThreadUtils.join(th, 30 * 1000);
+          assertTrue(region.size() == 1);
+        }
+      });
+      SelectResults set = (SelectResults) q.execute();
+      if (set.size() == 0 || !this.indexUsed) {
+        fail("Either Size of the result set is zero or Index is not used ");
+      }
+      this.indexUsed = false;
+      region.clear();
+      set = (SelectResults) q.execute();
+      if (set.size() != 1 || !this.indexUsed) {
+        fail("Either Size of the result set is not one or Index is not used ");
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.toString());
+    } finally {
+      isInitDone = false;
+      CacheUtils.restartCache();
+    }
+  }
+
+  @Test
+  public void testIndexUpdate() {

Review comment:
       This test doesn't seem to actually be testing anything about the 
behaviour of indexes, just that adding entries to the region results in more 
results being returned from a query, so it can probably be safely removed.

##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/IndexMaintenanceJUnitTest.java
##########
@@ -1057,6 +1071,394 @@ public void testBug43597() throws Exception {
     region.put("1", pf1);
   }
 
+  /**
+   * Starting of section - moved from wrongly spelled old class 
"IndexMaintainceJUnitTest".
+   * GEODE-1505
+   */
+
+  @Test
+  public void test000BUG32452()
+      throws IndexNameConflictException, IndexExistsException, 
RegionNotFoundException {
+    Index i1 = qs.createIndex("tIndex", IndexType.FUNCTIONAL, "vals.secId",
+        SEPARATOR + "portfolio pf, pf.positions.values vals");
+    Index i2 = qs.createIndex("dIndex", IndexType.FUNCTIONAL, 
"pf.getCW(pf.ID)",
+        SEPARATOR + "portfolio pf");
+    Index i3 = qs.createIndex("fIndex", IndexType.FUNCTIONAL, "sIter",
+        SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter");
+    Index i4 = qs.createIndex("cIndex", IndexType.FUNCTIONAL,
+        "pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]", SEPARATOR + 
"portfolio pf");
+    Index i5 = qs.createIndex("inIndex", IndexType.FUNCTIONAL, "kIter.secId",
+        SEPARATOR + "portfolio['0'].positions.values kIter");
+    Index i6 = qs.createIndex("sIndex", IndexType.FUNCTIONAL, "pos.secId",
+        SEPARATOR + "portfolio.values val, val.positions.values pos");
+    Index i7 = qs.createIndex("p1Index", IndexType.PRIMARY_KEY, "pkid", 
SEPARATOR + "portfolio pf");
+    Index i8 = qs.createIndex("p2Index", IndexType.PRIMARY_KEY, "pk", 
SEPARATOR + "portfolio pf");
+    if (!i1.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio index_iter1, 
index_iter1.positions.values index_iter2")
+        || !i1.getCanonicalizedIndexedExpression().equals("index_iter2.secId")
+        || !i1.getFromClause().equals(SEPARATOR + "portfolio pf, 
pf.positions.values vals")
+        || !i1.getIndexedExpression().equals("vals.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i2.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || 
!i2.getCanonicalizedIndexedExpression().equals("index_iter1.getCW(index_iter1.ID)")
+        || !i2.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i2.getIndexedExpression().equals("pf.getCW(pf.ID)")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i3.getCanonicalizedFromClause().equals(
+        SEPARATOR
+            + "portfolio index_iter1, 
index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr index_iter3")
+        || !i3.getCanonicalizedIndexedExpression().equals("index_iter3")
+        || !i3.getFromClause()
+            .equals(
+                SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter")
+        || !i3.getIndexedExpression().equals("sIter")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i4.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i4.getCanonicalizedIndexedExpression().equals(
+            
"index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr[index_iter1.ID]")
+        || !i4.getFromClause().equals(SEPARATOR + "portfolio pf") || 
!i4.getIndexedExpression()
+            .equals("pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i5.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio['0'].positions.values index_iter4")
+        || !i5.getCanonicalizedIndexedExpression().equals("index_iter4.secId")
+        || !i5.getFromClause().equals(SEPARATOR + 
"portfolio['0'].positions.values kIter")
+        || !i5.getIndexedExpression().equals("kIter.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i6.getCanonicalizedFromClause()
+        .equals(
+            SEPARATOR + "portfolio.values index_iter5, 
index_iter5.positions.values index_iter6")
+        || !i6.getCanonicalizedIndexedExpression().equals("index_iter6.secId")
+        || !i6.getFromClause().equals(SEPARATOR + "portfolio.values val, 
val.positions.values pos")
+        || !i6.getIndexedExpression().equals("pos.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i7.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i7.getCanonicalizedIndexedExpression().equals("index_iter1.pkid")
+        || !i7.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i7.getIndexedExpression().equals("pkid")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i8.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i8.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i8.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i8.getIndexedExpression().equals("pk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i1);
+    qs.removeIndex(i2);
+    qs.removeIndex(i3);
+    qs.removeIndex(i4);
+    qs.removeIndex(i5);
+    qs.removeIndex(i6);
+    qs.removeIndex(i7);
+    qs.removeIndex(i8);
+    Index i9 =
+        qs.createIndex("p3Index", IndexType.PRIMARY_KEY, "getPk", SEPARATOR + 
"portfolio pf");
+    if (!i9.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i9.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i9.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i9.getIndexedExpression().equals("getPk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i9);
+  }
+
+  @Test
+  public void numberOfIndexValuesStatIsUpdatedWhenEntryAdded() throws 
Exception {
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    IndexStatistics stats = index.getStatistics();
+    assertEquals(4, stats.getNumberOfValues());
+    region.put("4", new Portfolio(4));
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    stats = index.getStatistics();
+    assertEquals(5, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(3, results.size());
+  }
+
+  /**
+   * Needed to fix this since the key "4" was not found and the size was then 
redueced to 3 after
+   * invalidating the key 3
+   */
+  @Test
+  public void testInvalidatingEntry() throws Exception {
+    IndexStatistics stats = index.getStatistics();
+    region.invalidate("3");
+    assertEquals(3, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(2, results.size());
+  }
+
+  @Test
+  public void testDestroyEntry() throws Exception {
+    IndexStatistics stats = index.getStatistics();
+    region.put("4", new Portfolio(4));
+    region.destroy("4");
+    assertEquals(4, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(2, results.size());
+  }
+
+  // This test has a meaning only for Trunk code as it checks for Map 
implementation
+  // Tests for Region clear operations on Index in a Local VM
+  @Test
+  public void testIndexClearanceOnMapClear() {

Review comment:
       This test might be better named "indexIsUsedForQueryWhenRegionIsEmpty"

##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/IndexMaintenanceJUnitTest.java
##########
@@ -1057,6 +1071,394 @@ public void testBug43597() throws Exception {
     region.put("1", pf1);
   }
 
+  /**
+   * Starting of section - moved from wrongly spelled old class 
"IndexMaintainceJUnitTest".
+   * GEODE-1505
+   */
+
+  @Test
+  public void test000BUG32452()
+      throws IndexNameConflictException, IndexExistsException, 
RegionNotFoundException {
+    Index i1 = qs.createIndex("tIndex", IndexType.FUNCTIONAL, "vals.secId",
+        SEPARATOR + "portfolio pf, pf.positions.values vals");
+    Index i2 = qs.createIndex("dIndex", IndexType.FUNCTIONAL, 
"pf.getCW(pf.ID)",
+        SEPARATOR + "portfolio pf");
+    Index i3 = qs.createIndex("fIndex", IndexType.FUNCTIONAL, "sIter",
+        SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter");
+    Index i4 = qs.createIndex("cIndex", IndexType.FUNCTIONAL,
+        "pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]", SEPARATOR + 
"portfolio pf");
+    Index i5 = qs.createIndex("inIndex", IndexType.FUNCTIONAL, "kIter.secId",
+        SEPARATOR + "portfolio['0'].positions.values kIter");
+    Index i6 = qs.createIndex("sIndex", IndexType.FUNCTIONAL, "pos.secId",
+        SEPARATOR + "portfolio.values val, val.positions.values pos");
+    Index i7 = qs.createIndex("p1Index", IndexType.PRIMARY_KEY, "pkid", 
SEPARATOR + "portfolio pf");
+    Index i8 = qs.createIndex("p2Index", IndexType.PRIMARY_KEY, "pk", 
SEPARATOR + "portfolio pf");
+    if (!i1.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio index_iter1, 
index_iter1.positions.values index_iter2")
+        || !i1.getCanonicalizedIndexedExpression().equals("index_iter2.secId")
+        || !i1.getFromClause().equals(SEPARATOR + "portfolio pf, 
pf.positions.values vals")
+        || !i1.getIndexedExpression().equals("vals.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i2.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || 
!i2.getCanonicalizedIndexedExpression().equals("index_iter1.getCW(index_iter1.ID)")
+        || !i2.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i2.getIndexedExpression().equals("pf.getCW(pf.ID)")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i3.getCanonicalizedFromClause().equals(
+        SEPARATOR
+            + "portfolio index_iter1, 
index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr index_iter3")
+        || !i3.getCanonicalizedIndexedExpression().equals("index_iter3")
+        || !i3.getFromClause()
+            .equals(
+                SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter")
+        || !i3.getIndexedExpression().equals("sIter")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i4.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i4.getCanonicalizedIndexedExpression().equals(
+            
"index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr[index_iter1.ID]")
+        || !i4.getFromClause().equals(SEPARATOR + "portfolio pf") || 
!i4.getIndexedExpression()
+            .equals("pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i5.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio['0'].positions.values index_iter4")
+        || !i5.getCanonicalizedIndexedExpression().equals("index_iter4.secId")
+        || !i5.getFromClause().equals(SEPARATOR + 
"portfolio['0'].positions.values kIter")
+        || !i5.getIndexedExpression().equals("kIter.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i6.getCanonicalizedFromClause()
+        .equals(
+            SEPARATOR + "portfolio.values index_iter5, 
index_iter5.positions.values index_iter6")
+        || !i6.getCanonicalizedIndexedExpression().equals("index_iter6.secId")
+        || !i6.getFromClause().equals(SEPARATOR + "portfolio.values val, 
val.positions.values pos")
+        || !i6.getIndexedExpression().equals("pos.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i7.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i7.getCanonicalizedIndexedExpression().equals("index_iter1.pkid")
+        || !i7.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i7.getIndexedExpression().equals("pkid")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i8.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i8.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i8.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i8.getIndexedExpression().equals("pk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i1);
+    qs.removeIndex(i2);
+    qs.removeIndex(i3);
+    qs.removeIndex(i4);
+    qs.removeIndex(i5);
+    qs.removeIndex(i6);
+    qs.removeIndex(i7);
+    qs.removeIndex(i8);
+    Index i9 =
+        qs.createIndex("p3Index", IndexType.PRIMARY_KEY, "getPk", SEPARATOR + 
"portfolio pf");
+    if (!i9.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i9.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i9.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i9.getIndexedExpression().equals("getPk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i9);
+  }
+
+  @Test
+  public void numberOfIndexValuesStatIsUpdatedWhenEntryAdded() throws 
Exception {
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    IndexStatistics stats = index.getStatistics();
+    assertEquals(4, stats.getNumberOfValues());
+    region.put("4", new Portfolio(4));
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    stats = index.getStatistics();
+    assertEquals(5, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(3, results.size());
+  }
+
+  /**
+   * Needed to fix this since the key "4" was not found and the size was then 
redueced to 3 after
+   * invalidating the key 3
+   */
+  @Test
+  public void testInvalidatingEntry() throws Exception {
+    IndexStatistics stats = index.getStatistics();
+    region.invalidate("3");
+    assertEquals(3, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(2, results.size());
+  }
+
+  @Test
+  public void testDestroyEntry() throws Exception {

Review comment:
       This test might be better named 
"numberOfIndexValuesStatIsUpdatedWhenEntryDestroyed"

##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/IndexMaintenanceJUnitTest.java
##########
@@ -1057,6 +1071,394 @@ public void testBug43597() throws Exception {
     region.put("1", pf1);
   }
 
+  /**
+   * Starting of section - moved from wrongly spelled old class 
"IndexMaintainceJUnitTest".
+   * GEODE-1505
+   */
+
+  @Test
+  public void test000BUG32452()
+      throws IndexNameConflictException, IndexExistsException, 
RegionNotFoundException {
+    Index i1 = qs.createIndex("tIndex", IndexType.FUNCTIONAL, "vals.secId",
+        SEPARATOR + "portfolio pf, pf.positions.values vals");
+    Index i2 = qs.createIndex("dIndex", IndexType.FUNCTIONAL, 
"pf.getCW(pf.ID)",
+        SEPARATOR + "portfolio pf");
+    Index i3 = qs.createIndex("fIndex", IndexType.FUNCTIONAL, "sIter",
+        SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter");
+    Index i4 = qs.createIndex("cIndex", IndexType.FUNCTIONAL,
+        "pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]", SEPARATOR + 
"portfolio pf");
+    Index i5 = qs.createIndex("inIndex", IndexType.FUNCTIONAL, "kIter.secId",
+        SEPARATOR + "portfolio['0'].positions.values kIter");
+    Index i6 = qs.createIndex("sIndex", IndexType.FUNCTIONAL, "pos.secId",
+        SEPARATOR + "portfolio.values val, val.positions.values pos");
+    Index i7 = qs.createIndex("p1Index", IndexType.PRIMARY_KEY, "pkid", 
SEPARATOR + "portfolio pf");
+    Index i8 = qs.createIndex("p2Index", IndexType.PRIMARY_KEY, "pk", 
SEPARATOR + "portfolio pf");
+    if (!i1.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio index_iter1, 
index_iter1.positions.values index_iter2")
+        || !i1.getCanonicalizedIndexedExpression().equals("index_iter2.secId")
+        || !i1.getFromClause().equals(SEPARATOR + "portfolio pf, 
pf.positions.values vals")
+        || !i1.getIndexedExpression().equals("vals.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i2.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || 
!i2.getCanonicalizedIndexedExpression().equals("index_iter1.getCW(index_iter1.ID)")
+        || !i2.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i2.getIndexedExpression().equals("pf.getCW(pf.ID)")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i3.getCanonicalizedFromClause().equals(
+        SEPARATOR
+            + "portfolio index_iter1, 
index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr index_iter3")
+        || !i3.getCanonicalizedIndexedExpression().equals("index_iter3")
+        || !i3.getFromClause()
+            .equals(
+                SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter")
+        || !i3.getIndexedExpression().equals("sIter")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i4.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i4.getCanonicalizedIndexedExpression().equals(
+            
"index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr[index_iter1.ID]")
+        || !i4.getFromClause().equals(SEPARATOR + "portfolio pf") || 
!i4.getIndexedExpression()
+            .equals("pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i5.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio['0'].positions.values index_iter4")
+        || !i5.getCanonicalizedIndexedExpression().equals("index_iter4.secId")
+        || !i5.getFromClause().equals(SEPARATOR + 
"portfolio['0'].positions.values kIter")
+        || !i5.getIndexedExpression().equals("kIter.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i6.getCanonicalizedFromClause()
+        .equals(
+            SEPARATOR + "portfolio.values index_iter5, 
index_iter5.positions.values index_iter6")
+        || !i6.getCanonicalizedIndexedExpression().equals("index_iter6.secId")
+        || !i6.getFromClause().equals(SEPARATOR + "portfolio.values val, 
val.positions.values pos")
+        || !i6.getIndexedExpression().equals("pos.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i7.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i7.getCanonicalizedIndexedExpression().equals("index_iter1.pkid")
+        || !i7.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i7.getIndexedExpression().equals("pkid")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i8.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i8.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i8.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i8.getIndexedExpression().equals("pk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i1);
+    qs.removeIndex(i2);
+    qs.removeIndex(i3);
+    qs.removeIndex(i4);
+    qs.removeIndex(i5);
+    qs.removeIndex(i6);
+    qs.removeIndex(i7);
+    qs.removeIndex(i8);
+    Index i9 =
+        qs.createIndex("p3Index", IndexType.PRIMARY_KEY, "getPk", SEPARATOR + 
"portfolio pf");
+    if (!i9.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i9.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i9.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i9.getIndexedExpression().equals("getPk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i9);
+  }
+
+  @Test
+  public void numberOfIndexValuesStatIsUpdatedWhenEntryAdded() throws 
Exception {
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    IndexStatistics stats = index.getStatistics();
+    assertEquals(4, stats.getNumberOfValues());
+    region.put("4", new Portfolio(4));
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    stats = index.getStatistics();
+    assertEquals(5, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(3, results.size());
+  }
+
+  /**
+   * Needed to fix this since the key "4" was not found and the size was then 
redueced to 3 after
+   * invalidating the key 3
+   */
+  @Test
+  public void testInvalidatingEntry() throws Exception {
+    IndexStatistics stats = index.getStatistics();
+    region.invalidate("3");
+    assertEquals(3, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(2, results.size());
+  }
+
+  @Test
+  public void testDestroyEntry() throws Exception {
+    IndexStatistics stats = index.getStatistics();
+    region.put("4", new Portfolio(4));
+    region.destroy("4");
+    assertEquals(4, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(2, results.size());
+  }
+
+  // This test has a meaning only for Trunk code as it checks for Map 
implementation
+  // Tests for Region clear operations on Index in a Local VM
+  @Test
+  public void testIndexClearanceOnMapClear() {
+    try {
+      CacheUtils.getCache();
+      isInitDone = false;
+      Query q =
+          qs.newQuery("SELECT DISTINCT * FROM " + SEPARATOR + "portfolio where 
status = 'active'");
+      QueryObserverHolder.setInstance(new QueryObserverAdapter() {
+
+        @Override
+        public void afterIndexLookup(Collection coll) {
+          IndexMaintenanceJUnitTest.this.indexUsed = true;
+        }
+      });
+      SelectResults set = (SelectResults) q.execute();
+      if (set.size() == 0 || !this.indexUsed) {
+        fail("Either Size of the result set is zero or Index is not used ");
+      }
+      this.indexUsed = false;
+
+      region.clear();
+      set = (SelectResults) q.execute();
+      if (set.size() != 0 || !this.indexUsed) {
+        fail("Either Size of the result set is not zero or Index is not used 
");
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.toString());
+    } finally {
+      isInitDone = false;
+      CacheUtils.restartCache();
+    }
+  }
+
+  // Asif : Tests for Region clear operations on Index in a Local VM for cases
+  // when a clear
+  // operation & region put operation occur concurrentlty
+  @Test
+  public void testConcurrentMapClearAndRegionPutOperation() {
+    try {
+      CacheUtils.getCache();
+      isInitDone = false;
+      Query q =
+          qs.newQuery("SELECT DISTINCT * FROM " + SEPARATOR + "portfolio where 
status = 'active'");
+      QueryObserverHolder.setInstance(new QueryObserverAdapter() {
+
+        @Override
+        public void afterIndexLookup(Collection coll) {
+          IndexMaintenanceJUnitTest.this.indexUsed = true;
+        }
+
+        @Override
+        public void beforeRerunningIndexCreationQuery() {
+          // Spawn a separate thread here which does a put opertion on region
+          Thread th = new Thread(new Runnable() {
+
+            @Override
+            public void run() {
+              // Assert that the size of region is now 0
+              assertTrue(region.size() == 0);
+              region.put("" + 8, new Portfolio(8));
+            }
+          });
+          th.start();
+          ThreadUtils.join(th, 30 * 1000);
+          assertTrue(region.size() == 1);
+        }
+      });
+      SelectResults set = (SelectResults) q.execute();
+      if (set.size() == 0 || !this.indexUsed) {
+        fail("Either Size of the result set is zero or Index is not used ");
+      }
+      this.indexUsed = false;
+      region.clear();
+      set = (SelectResults) q.execute();
+      if (set.size() != 1 || !this.indexUsed) {
+        fail("Either Size of the result set is not one or Index is not used ");
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.toString());
+    } finally {
+      isInitDone = false;
+      CacheUtils.restartCache();
+    }
+  }
+
+  @Test
+  public void testIndexUpdate() {
+    try {
+      CacheUtils.getCache();
+      isInitDone = false;
+      qs.removeIndexes();
+
+      index = (IndexProtocol) qs.createIndex("statusIndex", 
IndexType.FUNCTIONAL, "pos.secId",
+          SEPARATOR + "portfolio p , p.positions.values pos");
+      String queryStr =
+          "Select distinct pf from " + SEPARATOR
+              + "portfolio pf , pf.positions.values ps where ps.secId='SUN'";
+
+      Query query = qs.newQuery(queryStr);
+      SelectResults rs = (SelectResults) query.execute();
+      int size1 = rs.size();
+      for (int i = 4; i < 50; ++i) {
+        region.put("" + i, new Portfolio(i));
+      }
+      rs = (SelectResults) query.execute();
+      int size2 = rs.size();
+      assertTrue(size2 > size1);
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail("Test failed due to exception=" + e);
+    } finally {
+      isInitDone = false;
+      CacheUtils.restartCache();
+    }
+
+  }
+
+  /**
+   * Test to compare range and compact index. They should return the same 
results.
+   */
+  @Test
+  public void testCompareRangeAndCompactIndex() {

Review comment:
       This test might be better named 
"rangeAndCompactIndexesShouldReturnTheSameResults"

##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/IndexMaintenanceJUnitTest.java
##########
@@ -1057,6 +1071,394 @@ public void testBug43597() throws Exception {
     region.put("1", pf1);
   }
 
+  /**
+   * Starting of section - moved from wrongly spelled old class 
"IndexMaintainceJUnitTest".
+   * GEODE-1505
+   */
+
+  @Test
+  public void test000BUG32452()

Review comment:
       This test might be better named 
"fromClausesAndIndexedExpressionsMatchExpectedValues"

##########
File path: 
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/IndexMaintenanceJUnitTest.java
##########
@@ -1057,6 +1071,394 @@ public void testBug43597() throws Exception {
     region.put("1", pf1);
   }
 
+  /**
+   * Starting of section - moved from wrongly spelled old class 
"IndexMaintainceJUnitTest".
+   * GEODE-1505
+   */
+
+  @Test
+  public void test000BUG32452()
+      throws IndexNameConflictException, IndexExistsException, 
RegionNotFoundException {
+    Index i1 = qs.createIndex("tIndex", IndexType.FUNCTIONAL, "vals.secId",
+        SEPARATOR + "portfolio pf, pf.positions.values vals");
+    Index i2 = qs.createIndex("dIndex", IndexType.FUNCTIONAL, 
"pf.getCW(pf.ID)",
+        SEPARATOR + "portfolio pf");
+    Index i3 = qs.createIndex("fIndex", IndexType.FUNCTIONAL, "sIter",
+        SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter");
+    Index i4 = qs.createIndex("cIndex", IndexType.FUNCTIONAL,
+        "pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]", SEPARATOR + 
"portfolio pf");
+    Index i5 = qs.createIndex("inIndex", IndexType.FUNCTIONAL, "kIter.secId",
+        SEPARATOR + "portfolio['0'].positions.values kIter");
+    Index i6 = qs.createIndex("sIndex", IndexType.FUNCTIONAL, "pos.secId",
+        SEPARATOR + "portfolio.values val, val.positions.values pos");
+    Index i7 = qs.createIndex("p1Index", IndexType.PRIMARY_KEY, "pkid", 
SEPARATOR + "portfolio pf");
+    Index i8 = qs.createIndex("p2Index", IndexType.PRIMARY_KEY, "pk", 
SEPARATOR + "portfolio pf");
+    if (!i1.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio index_iter1, 
index_iter1.positions.values index_iter2")
+        || !i1.getCanonicalizedIndexedExpression().equals("index_iter2.secId")
+        || !i1.getFromClause().equals(SEPARATOR + "portfolio pf, 
pf.positions.values vals")
+        || !i1.getIndexedExpression().equals("vals.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i2.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || 
!i2.getCanonicalizedIndexedExpression().equals("index_iter1.getCW(index_iter1.ID)")
+        || !i2.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i2.getIndexedExpression().equals("pf.getCW(pf.ID)")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i3.getCanonicalizedFromClause().equals(
+        SEPARATOR
+            + "portfolio index_iter1, 
index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr index_iter3")
+        || !i3.getCanonicalizedIndexedExpression().equals("index_iter3")
+        || !i3.getFromClause()
+            .equals(
+                SEPARATOR + "portfolio pf, 
pf.collectionHolderMap[(pf.ID).toString()].arr sIter")
+        || !i3.getIndexedExpression().equals("sIter")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i4.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i4.getCanonicalizedIndexedExpression().equals(
+            
"index_iter1.collectionHolderMap[index_iter1.ID.toString()].arr[index_iter1.ID]")
+        || !i4.getFromClause().equals(SEPARATOR + "portfolio pf") || 
!i4.getIndexedExpression()
+            .equals("pf.collectionHolderMap[(pf.ID).toString()].arr[pf.ID]")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i5.getCanonicalizedFromClause()
+        .equals(SEPARATOR + "portfolio['0'].positions.values index_iter4")
+        || !i5.getCanonicalizedIndexedExpression().equals("index_iter4.secId")
+        || !i5.getFromClause().equals(SEPARATOR + 
"portfolio['0'].positions.values kIter")
+        || !i5.getIndexedExpression().equals("kIter.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i6.getCanonicalizedFromClause()
+        .equals(
+            SEPARATOR + "portfolio.values index_iter5, 
index_iter5.positions.values index_iter6")
+        || !i6.getCanonicalizedIndexedExpression().equals("index_iter6.secId")
+        || !i6.getFromClause().equals(SEPARATOR + "portfolio.values val, 
val.positions.values pos")
+        || !i6.getIndexedExpression().equals("pos.secId")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i7.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i7.getCanonicalizedIndexedExpression().equals("index_iter1.pkid")
+        || !i7.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i7.getIndexedExpression().equals("pkid")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    if (!i8.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i8.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i8.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i8.getIndexedExpression().equals("pk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i1);
+    qs.removeIndex(i2);
+    qs.removeIndex(i3);
+    qs.removeIndex(i4);
+    qs.removeIndex(i5);
+    qs.removeIndex(i6);
+    qs.removeIndex(i7);
+    qs.removeIndex(i8);
+    Index i9 =
+        qs.createIndex("p3Index", IndexType.PRIMARY_KEY, "getPk", SEPARATOR + 
"portfolio pf");
+    if (!i9.getCanonicalizedFromClause().equals(SEPARATOR + "portfolio 
index_iter1")
+        || !i9.getCanonicalizedIndexedExpression().equals("index_iter1.pk")
+        || !i9.getFromClause().equals(SEPARATOR + "portfolio pf")
+        || !i9.getIndexedExpression().equals("getPk")) {
+      fail("Mismatch found among fromClauses or IndexedExpressions");
+    }
+    qs.removeIndex(i9);
+  }
+
+  @Test
+  public void numberOfIndexValuesStatIsUpdatedWhenEntryAdded() throws 
Exception {
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    IndexStatistics stats = index.getStatistics();
+    assertEquals(4, stats.getNumberOfValues());
+    region.put("4", new Portfolio(4));
+    CacheUtils.log(((CompactRangeIndex) index).dump());
+    stats = index.getStatistics();
+    assertEquals(5, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(3, results.size());
+  }
+
+  /**
+   * Needed to fix this since the key "4" was not found and the size was then 
redueced to 3 after
+   * invalidating the key 3
+   */
+  @Test
+  public void testInvalidatingEntry() throws Exception {
+    IndexStatistics stats = index.getStatistics();
+    region.invalidate("3");
+    assertEquals(3, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(2, results.size());
+  }
+
+  @Test
+  public void testDestroyEntry() throws Exception {
+    IndexStatistics stats = index.getStatistics();
+    region.put("4", new Portfolio(4));
+    region.destroy("4");
+    assertEquals(4, stats.getNumberOfValues());
+    SelectResults results = region.query("status = 'active'");
+    assertEquals(2, results.size());
+  }
+
+  // This test has a meaning only for Trunk code as it checks for Map 
implementation
+  // Tests for Region clear operations on Index in a Local VM
+  @Test
+  public void testIndexClearanceOnMapClear() {
+    try {
+      CacheUtils.getCache();
+      isInitDone = false;
+      Query q =
+          qs.newQuery("SELECT DISTINCT * FROM " + SEPARATOR + "portfolio where 
status = 'active'");
+      QueryObserverHolder.setInstance(new QueryObserverAdapter() {
+
+        @Override
+        public void afterIndexLookup(Collection coll) {
+          IndexMaintenanceJUnitTest.this.indexUsed = true;
+        }
+      });
+      SelectResults set = (SelectResults) q.execute();
+      if (set.size() == 0 || !this.indexUsed) {
+        fail("Either Size of the result set is zero or Index is not used ");
+      }
+      this.indexUsed = false;
+
+      region.clear();
+      set = (SelectResults) q.execute();
+      if (set.size() != 0 || !this.indexUsed) {
+        fail("Either Size of the result set is not zero or Index is not used 
");
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.toString());
+    } finally {
+      isInitDone = false;
+      CacheUtils.restartCache();
+    }
+  }
+
+  // Asif : Tests for Region clear operations on Index in a Local VM for cases
+  // when a clear
+  // operation & region put operation occur concurrentlty
+  @Test
+  public void testConcurrentMapClearAndRegionPutOperation() {
+    try {
+      CacheUtils.getCache();
+      isInitDone = false;
+      Query q =
+          qs.newQuery("SELECT DISTINCT * FROM " + SEPARATOR + "portfolio where 
status = 'active'");
+      QueryObserverHolder.setInstance(new QueryObserverAdapter() {
+
+        @Override
+        public void afterIndexLookup(Collection coll) {
+          IndexMaintenanceJUnitTest.this.indexUsed = true;
+        }
+
+        @Override
+        public void beforeRerunningIndexCreationQuery() {
+          // Spawn a separate thread here which does a put opertion on region
+          Thread th = new Thread(new Runnable() {
+
+            @Override
+            public void run() {
+              // Assert that the size of region is now 0
+              assertTrue(region.size() == 0);
+              region.put("" + 8, new Portfolio(8));
+            }
+          });
+          th.start();
+          ThreadUtils.join(th, 30 * 1000);
+          assertTrue(region.size() == 1);
+        }
+      });
+      SelectResults set = (SelectResults) q.execute();
+      if (set.size() == 0 || !this.indexUsed) {
+        fail("Either Size of the result set is zero or Index is not used ");
+      }
+      this.indexUsed = false;
+      region.clear();
+      set = (SelectResults) q.execute();
+      if (set.size() != 1 || !this.indexUsed) {
+        fail("Either Size of the result set is not one or Index is not used ");
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.toString());
+    } finally {
+      isInitDone = false;
+      CacheUtils.restartCache();
+    }
+  }
+
+  @Test
+  public void testIndexUpdate() {
+    try {
+      CacheUtils.getCache();
+      isInitDone = false;
+      qs.removeIndexes();
+
+      index = (IndexProtocol) qs.createIndex("statusIndex", 
IndexType.FUNCTIONAL, "pos.secId",
+          SEPARATOR + "portfolio p , p.positions.values pos");
+      String queryStr =
+          "Select distinct pf from " + SEPARATOR
+              + "portfolio pf , pf.positions.values ps where ps.secId='SUN'";
+
+      Query query = qs.newQuery(queryStr);
+      SelectResults rs = (SelectResults) query.execute();
+      int size1 = rs.size();
+      for (int i = 4; i < 50; ++i) {
+        region.put("" + i, new Portfolio(i));
+      }
+      rs = (SelectResults) query.execute();
+      int size2 = rs.size();
+      assertTrue(size2 > size1);
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail("Test failed due to exception=" + e);
+    } finally {
+      isInitDone = false;
+      CacheUtils.restartCache();
+    }
+
+  }
+
+  /**
+   * Test to compare range and compact index. They should return the same 
results.
+   */
+  @Test
+  public void testCompareRangeAndCompactIndex() {
+    try {
+      // CacheUtils.restartCache();
+      if (!isInitDone) {
+        isInitDone = true;
+      }
+      qs.removeIndexes();
+
+      String[] queryStr =
+          new String[] {"Select status from " + SEPARATOR + "portfolio pf 
where status='active'",
+              "Select pf.ID from " + SEPARATOR + "portfolio pf where pf.ID > 2 
and pf.ID < 100",
+              "Select * from " + SEPARATOR + "portfolio pf where 
pf.position1.secId > '2'",};
+
+      String[] queryFields = new String[] {"status", "ID", "position1.secId",};
+
+      for (int i = 0; i < queryStr.length; i++) {
+        // Clear indexes if any.
+        qs.removeIndexes();
+
+        // initialize region.
+        region.clear();
+        for (int k = 0; k < 10; k++) {
+          region.put("" + k, new Portfolio(k));
+        }
+
+        for (int j = 0; j < 1; j++) { // With different region size.
+          // Update Region.
+          for (int k = 0; k < (j * 100); k++) {
+            region.put("" + k, new Portfolio(k));
+          }
+
+          // Create compact index.
+          IndexManager.TEST_RANGEINDEX_ONLY = false;
+          index = (IndexProtocol) qs.createIndex(queryFields[i] + "Index", 
IndexType.FUNCTIONAL,
+              queryFields[i], SEPARATOR + "portfolio");
+
+          // Execute Query.
+          SelectResults[][] rs = new SelectResults[1][2];
+          Query query = qs.newQuery(queryStr[i]);
+          rs[0][0] = (SelectResults) query.execute();
+
+          // remove compact index.
+          qs.removeIndexes();
+
+          // Create Range Index.
+          IndexManager.TEST_RANGEINDEX_ONLY = true;
+          index = (IndexProtocol) qs.createIndex(queryFields[i] + "rIndex", 
IndexType.FUNCTIONAL,
+              queryFields[i], SEPARATOR + "portfolio");
+
+          query = qs.newQuery(queryStr[i]);
+          rs[0][1] = (SelectResults) query.execute();
+
+          CacheUtils.log(
+              "#### rs1 size is : " + (rs[0][0]).size() + " rs2 size is : " + 
(rs[0][1]).size());
+          StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
+          ssORrs.CompareQueryResultsWithoutAndWithIndexes(rs, 1, queryStr);
+        }
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail("Test failed due to exception=" + e);
+    } finally {
+      IndexManager.TEST_RANGEINDEX_ONLY = false;
+      isInitDone = false;
+      CacheUtils.restartCache();
+    }
+  }
+
+  /**
+   * Test to acquire range and compact index.
+   */
+  @Test
+  public void testToAcquireCompactRangeIndexEarly() {

Review comment:
       This test isn't asserting anything so it's not really possible for it to 
fail. It should probably just be removed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to