Repository: incubator-geode
Updated Branches:
  refs/heads/develop 3626c75f8 -> b2d85b4b0


GEODE-1967: Old keys are removed from removedKeyValuesEntries

        * Old keys are removed from removedKeyValuesEntries after the mapping 
is removed from Compact map range indexes.
        * New tests were added to handle various scenarios of old keys being 
destroyed and then inserted again.


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

Branch: refs/heads/develop
Commit: b2d85b4b0c74c25d7872aaca1bbe520b478563f7
Parents: 3626c75
Author: nabarun <[email protected]>
Authored: Fri Oct 7 13:57:34 2016 -0700
Committer: nabarun <[email protected]>
Committed: Mon Oct 10 17:22:05 2016 -0700

----------------------------------------------------------------------
 .../internal/index/CompactMapRangeIndex.java    |   9 +-
 .../MapRangeIndexMaintenanceJUnitTest.java      | 617 ++++++++++++++++++-
 2 files changed, 622 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b2d85b4b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactMapRangeIndex.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactMapRangeIndex.java
 
b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactMapRangeIndex.java
index 234dfae..61c4e22 100644
--- 
a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactMapRangeIndex.java
+++ 
b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactMapRangeIndex.java
@@ -134,11 +134,14 @@ public class CompactMapRangeIndex extends AbstractMapIndex
       oldKeysAndValuesForEntry = Collections.EMPTY_MAP;
     }
     Set<Entry> removedKeyValueEntries = oldKeysAndValuesForEntry != null ? 
oldKeysAndValuesForEntry.entrySet() : Collections.EMPTY_SET;
-     for (Map.Entry<?, ?> keyValue : removedKeyValueEntries) {
+    Iterator<Entry> iterator = removedKeyValueEntries.iterator();
+     while (iterator.hasNext()) {
+       Entry keyValue = iterator.next();
       Object indexKey = keyValue.getKey() == null ? IndexManager.NULL : 
keyValue.getKey();
        if (!presentKeys.contains(indexKey)) {
-        CompactRangeIndex rg = (CompactRangeIndex) 
this.mapKeyToValueIndex.get(keyValue.getKey());
-        rg.removeMapping(keyValue.getValue(), entry);
+         CompactRangeIndex rg = (CompactRangeIndex) 
this.mapKeyToValueIndex.get(keyValue.getKey());
+         rg.removeMapping(keyValue.getValue(), entry);
+         iterator.remove();
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b2d85b4b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/MapRangeIndexMaintenanceJUnitTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/MapRangeIndexMaintenanceJUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/MapRangeIndexMaintenanceJUnitTest.java
index b651272..7ed00a4 100644
--- 
a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/MapRangeIndexMaintenanceJUnitTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/MapRangeIndexMaintenanceJUnitTest.java
@@ -82,7 +82,7 @@ public class MapRangeIndexMaintenanceJUnitTest{
     assertEquals(100, region.size());
     qs = CacheUtils.getQueryService();
     
-    keyIndex1 = (IndexProtocol) qs.createIndex(INDEX_NAME, "positions['SUN', 
'IBM']", "/portfolio ");
+    keyIndex1 = (IndexProtocol) qs.createIndex(INDEX_NAME, "positions['SUN', 
'IBM']", "/portfolio p");
     
     assertTrue(keyIndex1 instanceof CompactMapRangeIndex);
 
@@ -531,7 +531,622 @@ public class MapRangeIndexMaintenanceJUnitTest{
     assertEquals(1, results.size());
   }
 
+  @Test
+  public void 
updatingWithSameKeysDifferentValuesAfterRemovingShouldReinsertIndexMappings() 
throws Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+
+    Portfolio p2 = new Portfolio(1, 1);
+    HashMap map2 = new HashMap();
+    p2.positions = map2;
+    map2.put("GOOG", 1);
+    region.put(1, p2);
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(0, results.size());
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map3.put("SUN",3);
+    map3.put("IBM",4);
+    region.put(1, p3);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(0, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 3")
+                                .execute();
+    assertEquals(1, results.size());
+
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['GOOG'] = 1")
+                                .execute();
+
+    assertEquals(0, results.size());
+  }
+
+  @Test
+  public void 
updatingWithSameKeysDifferentValuesAfterRemovingUsingRegionDestroyShouldReinsertIndexMappings()
 throws Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(1, results.size());
+
+    region.destroy(1);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(0, results.size());
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map3.put("SUN",3);
+    map3.put("IBM",4);
+    region.put(1, p3);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(0, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 3")
+                                .execute();
+    assertEquals(1, results.size());
+
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['GOOG'] = 1")
+                                .execute();
+
+    assertEquals(0, results.size());
+  }
+
+  @Test
+  public void 
updatingWithSameKeysDifferentValuesAfterRemovingUsingInplaceModificationShouldReinsertIndexMappings()
 throws Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+
+
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(1, results.size());
+
+    map1.remove("SUN");
+    map1.remove("IBM");
+    map1.put("GOOG",1);
+
+    region.put(1,p1);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                               .execute();
+    assertEquals(0, results.size());
+
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map3.put("SUN",3);
+    map3.put("IBM",4);
+    region.put(1, p3);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(0, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 3")
+                                .execute();
+    assertEquals(1, results.size());
+
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['GOOG'] = 1")
+                                .execute();
+
+    assertEquals(0, results.size());
+  }
+
+  @Test
+  public void 
updatingWithSameKeysSameValuesAfterRemovingShouldReinsertIndexMappings() throws 
Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(1, results.size());
+
+    Portfolio p2 = new Portfolio(1, 1);
+    HashMap map2 = new HashMap();
+    p2.positions = map2;
+    map2.put("GOOG", 1);
+    region.put(1, p2);
+
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(0, results.size());
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map3.put("SUN",1);
+    map3.put("IBM",2);
+    region.put(1, p3);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(1, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['IBM'] = 2")
+                                .execute();
+    assertEquals(1, results.size());
+
+  }
+
+  @Test
+  public void 
updatingWithSameKeysSameValuesAfterRemovingUsingRegionDestroyShouldReinsertIndexMappings()
 throws Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(1, results.size());
+
+    region.destroy(1);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(0, results.size());
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map3.put("SUN",1);
+    map3.put("IBM",2);
+    region.put(1, p3);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(1, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['IBM'] = 2")
+                                .execute();
+    assertEquals(1, results.size());
+
+  }
+
+  @Test
+  public void 
updatingWithSameKeysSameValuesAfterRemovingUsingInPlaceModificationShouldReinsertIndexMappings()
 throws Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(1, results.size());
+
+    map1.remove("SUN");
+    map1.remove("IBM");
+
+    map1.put("GOOG", 2);
+    region.put(1, p1);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(0, results.size());
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map3.put("SUN",1);
+    map3.put("IBM",2);
+    region.put(1, p3);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(1, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['IBM'] = 2")
+                                .execute();
+    assertEquals(1, results.size());
+
+  }
+
+
+  @Test
+  public void 
updatingWithSameKeysSameValuesAfterRemovingShouldReinsertIndexMappingsWithTwoRegionPuts()
 throws Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+    Portfolio p2 = new Portfolio(1, 1);
+    HashMap map2 = new HashMap();
+    map2.put("SUN", 1);
+    map2.put("IBM", 2);
+    p2.positions = map1;
+    region.put(2, p2);
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(2, results.size());
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map2.put("GOOG", 1);
+    region.put(1, p3);
+
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(1, results.size());
+
+    Portfolio p4 = new Portfolio(1, 1);
+    HashMap map4 = new HashMap();
+    p4.positions = map4;
+    map4.put("SUN",1);
+    map4.put("IBM",2);
+    region.put(1, p4);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(2, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['IBM'] = 2")
+                                .execute();
+    assertEquals(2, results.size());
+
+  }
+
+  @Test
+  public void 
updatingWithSameKeysSameValuesAfterRemovingUsingRegionDestroyShouldReinsertIndexMappingsWithTwoRegionPuts()
 throws Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+    Portfolio p2 = new Portfolio(1, 1);
+    HashMap map2 = new HashMap();
+    map2.put("SUN", 1);
+    map2.put("IBM", 2);
+    p2.positions = map1;
+    region.put(2, p2);
+
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(2, results.size());
+
+    region.destroy(1);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(1, results.size());
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map3.put("SUN",1);
+    map3.put("IBM",2);
+    region.put(1, p3);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(2, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['IBM'] = 2")
+                                .execute();
+    assertEquals(2, results.size());
+
+  }
+
+  @Test
+  public void 
updatingWithSameKeysSameValuesAfterRemovingUsingInPlaceModificationShouldReinsertIndexMappingsWithTwoRegionPuts()
 throws Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+    Portfolio p2 = new Portfolio(1, 1);
+    HashMap map2 = new HashMap();
+    map2.put("SUN", 1);
+    map2.put("IBM", 2);
+    p2.positions = map1;
+    region.put(2, p2);
+
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(2, results.size());
+
+    map1.remove("SUN");
+    map1.remove("IBM");
+
+    map1.put("GOOG", 2);
+    region.put(1, p1);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(1, results.size());
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map3.put("SUN",1);
+    map3.put("IBM",2);
+    region.put(1, p3);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(2, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['IBM'] = 2")
+                                .execute();
+    assertEquals(2, results.size());
+
+  }
+
+  @Test
+  public void 
updatingWithSameKeysDifferentValuesAfterRemovingShouldReinsertIndexMappingsWithTwoRegionPuts()
 throws Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map3.put("SUN",5);
+    map3.put("IBM",6);
+    region.put(2, p3);
+
+
+    Portfolio p2 = new Portfolio(1, 1);
+    HashMap map2 = new HashMap();
+    p2.positions = map2;
+    map2.put("GOOG", 1);
+    region.put(1, p2);
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(0, results.size());
+
+    Portfolio p4 = new Portfolio(1, 1);
+    HashMap map4 = new HashMap();
+    p4.positions = map4;
+    map4.put("SUN",3);
+    map4.put("IBM",4);
+    region.put(1, p4);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(0, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 3")
+                                .execute();
+    assertEquals(1, results.size());
+
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['GOOG'] = 1")
+                                .execute();
+
+    assertEquals(0, results.size());
+  }
+
+  @Test
+  public void 
updatingWithSameKeysDifferentValuesAfterRemovingUsingRegionDestroyShouldReinsertIndexMappingsWithTwoRegionPuts()
 throws Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+    Portfolio p2 = new Portfolio(1, 1);
+    HashMap map2 = new HashMap();
+    map2.put("SUN", 5);
+    map2.put("IBM", 6);
+    p2.positions = map2;
+    region.put(2, p2);
+
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(1, results.size());
+
+    region.destroy(1);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(0, results.size());
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map3.put("SUN",3);
+    map3.put("IBM",4);
+    region.put(1, p3);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(0, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 3")
+                                .execute();
+    assertEquals(1, results.size());
+
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['GOOG'] = 1")
+                                .execute();
+
+    assertEquals(0, results.size());
+  }
+
+  @Test
+  public void 
updatingWithSameKeysDifferentValuesAfterRemovingUsingInplaceModificationShouldReinsertIndexMappingsWithTwoRegionPuts()
 throws Exception {
+    AttributesFactory af = new AttributesFactory();
+    af.setScope(Scope.LOCAL);
+    region = CacheUtils.createRegion("portfolio", af.create(), false);
+    qs = CacheUtils.getQueryService();
+    Index keyIndex1 = qs.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
 
+    Portfolio p1 = new Portfolio(1, 1);
+    HashMap map1 = new HashMap();
+    map1.put("SUN", 1);
+    map1.put("IBM", 2);
+    p1.positions = map1;
+    region.put(1, p1);
+
+
+    Portfolio p2 = new Portfolio(1, 1);
+    HashMap map2 = new HashMap();
+    map2.put("SUN", 5);
+    map2.put("IBM", 6);
+    p2.positions = map2;
+    region.put(2, p2);
+
+    SelectResults results = (SelectResults) qs.newQuery("select * from 
/portfolio p where p.positions['SUN'] = 1")
+                                              .execute();
+    assertEquals(1, results.size());
+
+    map1.remove("SUN");
+    map1.remove("IBM");
+    map1.put("GOOG",1);
+
+    region.put(1,p1);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(0, results.size());
+
+
+    Portfolio p3 = new Portfolio(1, 1);
+    HashMap map3 = new HashMap();
+    p3.positions = map3;
+    map3.put("SUN",3);
+    map3.put("IBM",4);
+    region.put(1, p3);
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 1")
+                                .execute();
+    assertEquals(0, results.size());
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['SUN'] = 3")
+                                .execute();
+    assertEquals(1, results.size());
+
+
+    results = (SelectResults) qs.newQuery("select * from /portfolio p where 
p.positions['GOOG'] = 1")
+                                .execute();
+
+    assertEquals(0, results.size());
+  }
 
 
   /**

Reply via email to