Search in sources :

Example 1 with RegionEntryToValuesMap

use of org.apache.geode.cache.query.internal.index.AbstractIndex.RegionEntryToValuesMap in project geode by apache.

the class IndexMaintenanceJUnitTest method testMapKeyIndexMaintenanceForNonCompactTypeSpecificKeysIndex.

@Test
public void testMapKeyIndexMaintenanceForNonCompactTypeSpecificKeysIndex() throws Exception {
    IndexManager.TEST_RANGEINDEX_ONLY = true;
    QueryService qs;
    qs = CacheUtils.getQueryService();
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    int ID = 1;
    // and so on
    for (; ID <= 5; ++ID) {
        MapKeyIndexData mkid = new MapKeyIndexData(ID);
        for (int j = 1; j <= ID; ++j) {
            mkid.maap.put("key" + j, "val" + j);
        }
        testRgn.put(ID, mkid);
    }
    // ID = 5;
    --ID;
    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "objs.maap['key1','key2','key3','key7']", "/testRgn objs");
    assertEquals(i1.getCanonicalizedIndexedExpression(), "index_iter1.maap['key1','key2','key3','key7']");
    assertTrue(i1 instanceof MapRangeIndex);
    MapRangeIndex mri = (MapRangeIndex) i1;
    // Test index maintenance
    // addition of new Portfolio object
    Map<Object, AbstractIndex> indxMap = mri.getRangeIndexHolderForTesting();
    assertEquals(indxMap.size(), 3);
    for (int j = 1; j <= 3; ++j) {
        assertTrue(indxMap.containsKey("key" + j));
        RangeIndex rng = (RangeIndex) indxMap.get("key" + j);
        Iterator itr = rng.valueToEntriesMap.values().iterator();
        assertEquals(rng.valueToEntriesMap.size(), 1);
        assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        while (itr.hasNext()) {
            RegionEntryToValuesMap entryMap = (RegionEntryToValuesMap) itr.next();
            assertEquals(ID + 1 - j, entryMap.getNumEntries());
            for (Integer elem : expectedElements) {
                RegionEntry re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
        }
    }
    for (int j = 4; j <= ID; ++j) {
        assertFalse(indxMap.containsKey("key" + j));
    }
    // addition of new Portfolio in the Map
    // ID = 6
    ++ID;
    MapKeyIndexData mkid = new MapKeyIndexData(ID);
    for (int j = 1; j <= ID; ++j) {
        mkid.maap.put("key" + j, "val" + j);
    }
    testRgn.put(ID, mkid);
    assertEquals(indxMap.size(), 3);
    for (int j = 1; j <= 3; ++j) {
        assertTrue(indxMap.containsKey("key" + j));
        RangeIndex rng = (RangeIndex) indxMap.get("key" + j);
        Iterator itr = rng.valueToEntriesMap.values().iterator();
        assertEquals(rng.valueToEntriesMap.size(), 1);
        assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        while (itr.hasNext()) {
            RegionEntryToValuesMap entryMap = (RegionEntryToValuesMap) itr.next();
            assertEquals(ID + 1 - j, entryMap.getNumEntries());
            for (Integer elem : expectedElements) {
                RegionEntry re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
        }
    }
    for (int j = 4; j <= ID; ++j) {
        assertFalse(indxMap.containsKey("key" + j));
    }
    // addition of new key in the positions map
    mkid.maap.put("key7", "val7");
    testRgn.put(ID, mkid);
    assertEquals(indxMap.size(), 4);
    for (int j = 1; j <= 3; ++j) {
        assertTrue(indxMap.containsKey("key" + j));
        RangeIndex rng = (RangeIndex) indxMap.get("key" + j);
        Iterator itr = rng.valueToEntriesMap.values().iterator();
        assertEquals(rng.valueToEntriesMap.size(), 1);
        assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        while (itr.hasNext()) {
            RegionEntryToValuesMap entryMap = (RegionEntryToValuesMap) itr.next();
            assertEquals(ID + 1 - j, entryMap.getNumEntries());
            for (Integer elem : expectedElements) {
                RegionEntry re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
        }
    }
    assertTrue(indxMap.containsKey("key7"));
    RangeIndex rng = (RangeIndex) indxMap.get("key7");
    Iterator itr = rng.valueToEntriesMap.values().iterator();
    assertEquals(rng.valueToEntriesMap.size(), 1);
    assertTrue(rng.valueToEntriesMap.containsKey("val7"));
    RegionEntryToValuesMap entryMap = (RegionEntryToValuesMap) itr.next();
    assertEquals(1, entryMap.getNumEntries());
    RegionEntry re = testRgn.basicGetEntry(6);
    entryMap.containsEntry(re);
    // deletion of key in the positions map
    mkid.maap.remove("key7");
    testRgn.put(ID, mkid);
    // No Key Indexes are removed from a MapRangeIndex even if they are empty.
    assertEquals(indxMap.size(), 4);
    for (int j = 1; j <= 3; ++j) {
        assertTrue(indxMap.containsKey("key" + j));
        rng = (RangeIndex) indxMap.get("key" + j);
        itr = rng.valueToEntriesMap.values().iterator();
        assertEquals(rng.valueToEntriesMap.size(), 1);
        assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        while (itr.hasNext()) {
            entryMap = (RegionEntryToValuesMap) itr.next();
            assertEquals(ID + 1 - j, entryMap.getNumEntries());
            for (Integer elem : expectedElements) {
                re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
        }
    }
    // update of key in the positions map
    mkid = (MapKeyIndexData) testRgn.get(1);
    mkid.maap.put("key1", "val2");
    testRgn.put(1, mkid);
    assertEquals(indxMap.size(), 4);
    for (int j = 1; j <= 3; ++j) {
        String keey = "key" + j;
        assertTrue(indxMap.containsKey(keey));
        rng = (RangeIndex) indxMap.get(keey);
        itr = rng.valueToEntriesMap.values().iterator();
        if (keey.equals("key1")) {
            assertEquals(rng.valueToEntriesMap.size(), 2);
            assertTrue(rng.valueToEntriesMap.containsKey("val1"));
            assertTrue(rng.valueToEntriesMap.containsKey("val2"));
        } else {
            assertEquals(rng.valueToEntriesMap.size(), 1);
            assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        }
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        if (keey.equals("key1")) {
            assertEquals(rng.valueToEntriesMap.size(), 2);
            entryMap = (RegionEntryToValuesMap) rng.valueToEntriesMap.get("val1");
            assertEquals(5, entryMap.getNumEntries());
            expectedElements.remove(1);
            for (Integer elem : expectedElements) {
                re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
            entryMap = (RegionEntryToValuesMap) rng.valueToEntriesMap.get("val2");
            assertEquals(1, entryMap.getNumEntries());
            re = testRgn.basicGetEntry(1);
            assertTrue(entryMap.containsEntry(re));
        } else {
            while (itr.hasNext()) {
                entryMap = (RegionEntryToValuesMap) itr.next();
                assertEquals(ID + 1 - j, entryMap.getNumEntries());
                for (Integer elem : expectedElements) {
                    re = testRgn.basicGetEntry(elem);
                    assertTrue(entryMap.containsEntry(re));
                }
            }
        }
    }
    // deletion of portfolio object key in the positions map
    testRgn.remove(3);
    assertEquals(indxMap.size(), 4);
    for (int j = 1; j <= 3; ++j) {
        String keey = "key" + j;
        assertTrue(indxMap.containsKey(keey));
        rng = (RangeIndex) indxMap.get(keey);
        itr = rng.valueToEntriesMap.values().iterator();
        if (keey.equals("key1")) {
            assertEquals(rng.valueToEntriesMap.size(), 2);
            assertTrue(rng.valueToEntriesMap.containsKey("val1"));
            assertTrue(rng.valueToEntriesMap.containsKey("val2"));
        } else {
            assertEquals(rng.valueToEntriesMap.size(), 1);
            assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        }
        if (keey.equals("key1")) {
            assertEquals(rng.valueToEntriesMap.size(), 2);
            entryMap = (RegionEntryToValuesMap) rng.valueToEntriesMap.get("val1");
            assertEquals(4, entryMap.getNumEntries());
            for (int k = 2; k <= 6; ++k) {
                if (k == 3) {
                    continue;
                } else {
                    re = testRgn.basicGetEntry(k);
                    assertTrue(entryMap.containsEntry(re));
                }
            }
            entryMap = (RegionEntryToValuesMap) rng.valueToEntriesMap.get("val2");
            assertEquals(1, entryMap.getNumEntries());
            re = testRgn.basicGetEntry(1);
            assertTrue(entryMap.containsEntry(re));
        } else {
            while (itr.hasNext()) {
                entryMap = (RegionEntryToValuesMap) itr.next();
                assertEquals(ID - j, entryMap.getNumEntries());
                for (int p = j; p <= ID; ++p) {
                    re = testRgn.basicGetEntry(p);
                    if (p == 3) {
                        assertNull(re);
                    } else {
                        assertTrue(entryMap.containsEntry(re));
                    }
                }
            }
        }
    }
}
Also used : Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) RegionEntryToValuesMap(org.apache.geode.cache.query.internal.index.AbstractIndex.RegionEntryToValuesMap) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) CloseableIterator(org.apache.geode.internal.cache.persistence.query.CloseableIterator) Iterator(java.util.Iterator) RegionEntry(org.apache.geode.internal.cache.RegionEntry) HashSet(java.util.HashSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with RegionEntryToValuesMap

use of org.apache.geode.cache.query.internal.index.AbstractIndex.RegionEntryToValuesMap in project geode by apache.

the class IndexMaintenanceJUnitTest method testMapKeyIndexMaintenanceForNonCompactTypeAllKeysIndex.

@Test
public void testMapKeyIndexMaintenanceForNonCompactTypeAllKeysIndex() throws Exception {
    IndexManager.TEST_RANGEINDEX_ONLY = true;
    QueryService qs;
    qs = CacheUtils.getQueryService();
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    int ID = 1;
    // and so on
    for (; ID <= 5; ++ID) {
        MapKeyIndexData mkid = new MapKeyIndexData(ID);
        for (int j = 1; j <= ID; ++j) {
            mkid.maap.put("key" + j, "val" + j);
        }
        testRgn.put(ID, mkid);
    }
    --ID;
    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "objs.maap[*]", "/testRgn objs");
    assertEquals(i1.getCanonicalizedIndexedExpression(), "index_iter1.maap[*]");
    assertTrue(i1 instanceof MapRangeIndex);
    MapRangeIndex mri = (MapRangeIndex) i1;
    // Test index maintenance
    // addition of new Portfolio object
    Map<Object, AbstractIndex> indxMap = mri.getRangeIndexHolderForTesting();
    assertEquals(indxMap.size(), ID);
    for (int j = 1; j <= ID; ++j) {
        assertTrue(indxMap.containsKey("key" + j));
        RangeIndex rng = (RangeIndex) indxMap.get("key" + j);
        Iterator itr = rng.valueToEntriesMap.values().iterator();
        assertEquals(rng.valueToEntriesMap.size(), 1);
        assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        while (itr.hasNext()) {
            RegionEntryToValuesMap entryMap = (RegionEntryToValuesMap) itr.next();
            assertEquals(ID + 1 - j, entryMap.getNumEntries());
            for (Integer elem : expectedElements) {
                RegionEntry re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
        }
    }
    // addition of new Portfolio in the Map
    // ID = 6;
    ++ID;
    MapKeyIndexData mkid = new MapKeyIndexData(ID);
    for (int j = 1; j <= ID; ++j) {
        mkid.maap.put("key" + j, "val" + j);
    }
    testRgn.put(ID, mkid);
    assertEquals(indxMap.size(), ID);
    for (int j = 1; j <= ID; ++j) {
        assertTrue(indxMap.containsKey("key" + j));
        RangeIndex rng = (RangeIndex) indxMap.get("key" + j);
        Iterator itr = rng.valueToEntriesMap.values().iterator();
        assertEquals(rng.valueToEntriesMap.size(), 1);
        assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        while (itr.hasNext()) {
            RegionEntryToValuesMap entryMap = (RegionEntryToValuesMap) itr.next();
            assertEquals(ID + 1 - j, entryMap.getNumEntries());
            for (Integer elem : expectedElements) {
                RegionEntry re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
        }
    }
    // addition of new key in the positions map
    mkid.maap.put("key7", "val7");
    testRgn.put(ID, mkid);
    assertEquals(indxMap.size(), 7);
    for (int j = 1; j <= ID; ++j) {
        assertTrue(indxMap.containsKey("key" + j));
        RangeIndex rng = (RangeIndex) indxMap.get("key" + j);
        Iterator itr = rng.valueToEntriesMap.values().iterator();
        assertEquals(rng.valueToEntriesMap.size(), 1);
        assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        while (itr.hasNext()) {
            RegionEntryToValuesMap entryMap = (RegionEntryToValuesMap) itr.next();
            assertEquals(ID + 1 - j, entryMap.getNumEntries());
            for (Integer elem : expectedElements) {
                RegionEntry re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
        }
    }
    assertTrue(indxMap.containsKey("key7"));
    RangeIndex rng = (RangeIndex) indxMap.get("key7");
    Iterator itr = rng.valueToEntriesMap.values().iterator();
    assertEquals(rng.valueToEntriesMap.size(), 1);
    assertTrue(rng.valueToEntriesMap.containsKey("val7"));
    RegionEntryToValuesMap entryMap = (RegionEntryToValuesMap) itr.next();
    assertEquals(1, entryMap.getNumEntries());
    RegionEntry re = testRgn.basicGetEntry(6);
    entryMap.containsEntry(re);
    // deletion of key in the positions map
    mkid.maap.remove("key7");
    testRgn.put(ID, mkid);
    assertEquals(indxMap.size(), ID + 1);
    for (int j = 1; j <= ID; ++j) {
        assertTrue(indxMap.containsKey("key" + j));
        rng = (RangeIndex) indxMap.get("key" + j);
        itr = rng.valueToEntriesMap.values().iterator();
        assertEquals(rng.valueToEntriesMap.size(), 1);
        assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        while (itr.hasNext()) {
            entryMap = (RegionEntryToValuesMap) itr.next();
            assertEquals(ID + 1 - j, entryMap.getNumEntries());
            for (Integer elem : expectedElements) {
                re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
        }
    }
    // update of key in the positions map
    mkid = (MapKeyIndexData) testRgn.get(1);
    mkid.maap.put("key1", "val2");
    testRgn.put(1, mkid);
    assertEquals(indxMap.size(), ID + 1);
    for (int j = 1; j <= ID; ++j) {
        String keey = "key" + j;
        assertTrue(indxMap.containsKey(keey));
        rng = (RangeIndex) indxMap.get(keey);
        itr = rng.valueToEntriesMap.values().iterator();
        if (keey.equals("key1")) {
            assertEquals(rng.valueToEntriesMap.size(), 2);
            assertTrue(rng.valueToEntriesMap.containsKey("val1"));
            assertTrue(rng.valueToEntriesMap.containsKey("val2"));
        } else {
            assertEquals(rng.valueToEntriesMap.size(), 1);
            assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        }
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        if (keey.equals("key1")) {
            assertEquals(rng.valueToEntriesMap.size(), 2);
            entryMap = (RegionEntryToValuesMap) rng.valueToEntriesMap.get("val1");
            assertEquals(5, entryMap.getNumEntries());
            expectedElements.remove(1);
            for (Integer elem : expectedElements) {
                re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
            entryMap = (RegionEntryToValuesMap) rng.valueToEntriesMap.get("val2");
            assertEquals(1, entryMap.getNumEntries());
            re = testRgn.basicGetEntry(1);
            assertTrue(entryMap.containsEntry(re));
        } else {
            while (itr.hasNext()) {
                entryMap = (RegionEntryToValuesMap) itr.next();
                assertEquals(ID + 1 - j, entryMap.getNumEntries());
                for (Integer elem : expectedElements) {
                    re = testRgn.basicGetEntry(elem);
                    assertTrue(entryMap.containsEntry(re));
                }
            }
        }
    }
    // deletion of portfolio object key in the positions map
    testRgn.remove(ID);
    // ID = 5;
    --ID;
    // No Key Indexes are removed from a MapRangeIndex even if they are empty.
    assertEquals(indxMap.size(), ID + 2);
    for (int j = 1; j <= ID; ++j) {
        String keey = "key" + j;
        assertTrue(indxMap.containsKey(keey));
        rng = (RangeIndex) indxMap.get(keey);
        itr = rng.valueToEntriesMap.values().iterator();
        if (keey.equals("key1")) {
            assertEquals(rng.valueToEntriesMap.size(), 2);
            assertTrue(rng.valueToEntriesMap.containsKey("val1"));
            assertTrue(rng.valueToEntriesMap.containsKey("val2"));
        } else {
            assertEquals(rng.valueToEntriesMap.size(), 1);
            assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        }
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        if (keey.equals("key1")) {
            assertEquals(rng.valueToEntriesMap.size(), 2);
            entryMap = (RegionEntryToValuesMap) rng.valueToEntriesMap.get("val1");
            assertEquals(4, entryMap.getNumEntries());
            expectedElements.remove(1);
            for (Integer elem : expectedElements) {
                re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
            entryMap = (RegionEntryToValuesMap) rng.valueToEntriesMap.get("val2");
            assertEquals(1, entryMap.getNumEntries());
            re = testRgn.basicGetEntry(1);
            assertTrue(entryMap.containsEntry(re));
        } else {
            while (itr.hasNext()) {
                entryMap = (RegionEntryToValuesMap) itr.next();
                assertEquals(ID + 1 - j, entryMap.getNumEntries());
                for (Integer elem : expectedElements) {
                    re = testRgn.basicGetEntry(elem);
                    assertTrue(entryMap.containsEntry(re));
                }
            }
        }
    }
}
Also used : Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) RegionEntryToValuesMap(org.apache.geode.cache.query.internal.index.AbstractIndex.RegionEntryToValuesMap) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) CloseableIterator(org.apache.geode.internal.cache.persistence.query.CloseableIterator) Iterator(java.util.Iterator) RegionEntry(org.apache.geode.internal.cache.RegionEntry) HashSet(java.util.HashSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with RegionEntryToValuesMap

use of org.apache.geode.cache.query.internal.index.AbstractIndex.RegionEntryToValuesMap in project geode by apache.

the class IndexMaintenanceJUnitTest method testMapIndexRecreationForAllKeys.

// @Test
// public void testCompactMapIndexRecreationForAllKeys() throws Exception
// {
//
// QueryService qs;
// qs = CacheUtils.getQueryService();
// LocalRegion testRgn = (LocalRegion)CacheUtils.createRegion("testRgn", null);
// int ID = 1;
// // Add some test data now
// // Add 5 main objects. 1 will contain key1, 2 will contain key1 & key2
// // and so on
// for (; ID <= 5; ++ID) {
// MapKeyIndexData mkid = new MapKeyIndexData(ID);
// for (int j = 1; j <= ID; ++j) {
// mkid.maap.put("key" + j, "val" + j);
// }
// testRgn.put(ID, mkid);
// }
// --ID;
// Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "objs.maap[*]",
// "/testRgn objs");
// assertIndexDetailsEquals(i1.getCanonicalizedIndexedExpression(), "index_iter1.maap[*]");
// assertTrue(i1 instanceof CompactMapRangeIndex);
// CompactMapRangeIndex mri = (CompactMapRangeIndex)i1;
// // Test index maintenance
// // addition of new Portfolio object
// Map<Object, CompactRangeIndex> indxMap = mri.getRangeIndexHolderForTesting();
// assertIndexDetailsEquals(indxMap.size(), ID);
// for (int j = 1; j <= ID; ++j) {
// assertTrue(indxMap.containsKey("key" + j));
// CompactRangeIndex rng = indxMap.get("key" + j);
// Iterator itr = rng.valueToEntriesMap.values().iterator();
// assertIndexDetailsEquals(rng.valueToEntriesMap.size(), 1);
// assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
// Set<Integer> expectedElements = new HashSet<Integer>();
// for (int k = j; k <= ID; ++k) {
// expectedElements.add(k);
// }
// Object mapValue = rng.valueToEntriesMap.get("val" + j);
// int size = 0;
// if (mapValue instanceof RegionEntry) {
// size = 1;
// }
// else if (mapValue instanceof ConcurrentHashSet) {
// size = ((ConcurrentHashSet)mapValue).size();
// }
// assertIndexDetailsEquals(expectedElements.size(), size);
// for (Integer elem : expectedElements) {
// RegionEntry re = testRgn.basicGetEntry(elem);
// if (mapValue instanceof RegionEntry) {
// assertTrue(mapValue.equals(re));
// }
// else if (mapValue instanceof ConcurrentHashSet) {
// assertTrue(((ConcurrentHashSet)mapValue).contains(re));
// }
// else {
// fail("no map value");
// }
// }
// }
// IndexManager im = testRgn.getIndexManager();
// im.rerunIndexCreationQuery();
// ID =5;
// i1 =im.getIndex("Index1");
// assertIndexDetailsEquals(i1.getCanonicalizedIndexedExpression(), "index_iter1.maap[*]");
// assertTrue(i1 instanceof CompactMapRangeIndex);
// mri = (CompactMapRangeIndex)i1;
// // Test index maintenance
// // addition of new Portfolio object
// indxMap = mri.getRangeIndexHolderForTesting();
// assertIndexDetailsEquals(indxMap.size(), ID);
// for (int j = 1; j <= ID; ++j) {
// assertTrue(indxMap.containsKey("key" + j));
// CompactRangeIndex rng = indxMap.get("key" + j);
// Iterator itr = rng.valueToEntriesMap.values().iterator();
// assertIndexDetailsEquals(rng.valueToEntriesMap.size(), 1);
// assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
// Set<Integer> expectedElements = new HashSet<Integer>();
// for (int k = j; k <= ID; ++k) {
// expectedElements.add(k);
// }
// Object mapValue = rng.valueToEntriesMap.get("val" + j);
// int size = 0;
// if (mapValue instanceof RegionEntry) {
// size = 1;
// }
// else if (mapValue instanceof ConcurrentHashSet) {
// size = ((ConcurrentHashSet)mapValue).size();
// }
// assertIndexDetailsEquals(expectedElements.size(), size);
// for (Integer elem : expectedElements) {
// RegionEntry re = testRgn.basicGetEntry(elem);
// if (mapValue instanceof RegionEntry) {
// assertTrue(mapValue.equals(re));
// }
// else if (mapValue instanceof ConcurrentHashSet) {
// assertTrue(((ConcurrentHashSet)mapValue).contains(re));
// }
// else {
// fail("no map value");
// }
// }
// }
// }
@Test
public void testMapIndexRecreationForAllKeys() throws Exception {
    IndexManager.TEST_RANGEINDEX_ONLY = true;
    QueryService qs;
    qs = CacheUtils.getQueryService();
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    int ID = 1;
    // and so on
    for (; ID <= 5; ++ID) {
        MapKeyIndexData mkid = new MapKeyIndexData(ID);
        for (int j = 1; j <= ID; ++j) {
            mkid.maap.put("key" + j, "val" + j);
        }
        testRgn.put(ID, mkid);
    }
    --ID;
    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "objs.maap[*]", "/testRgn objs");
    assertEquals(i1.getCanonicalizedIndexedExpression(), "index_iter1.maap[*]");
    assertTrue(i1 instanceof MapRangeIndex);
    MapRangeIndex mri = (MapRangeIndex) i1;
    // Test index maintenance
    // addition of new Portfolio object
    Map<Object, AbstractIndex> indxMap = mri.getRangeIndexHolderForTesting();
    assertEquals(indxMap.size(), ID);
    for (int j = 1; j <= ID; ++j) {
        assertTrue(indxMap.containsKey("key" + j));
        RangeIndex rng = (RangeIndex) indxMap.get("key" + j);
        Iterator itr = rng.valueToEntriesMap.values().iterator();
        assertEquals(rng.valueToEntriesMap.size(), 1);
        assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        while (itr.hasNext()) {
            RegionEntryToValuesMap entryMap = (RegionEntryToValuesMap) itr.next();
            assertEquals(ID + 1 - j, entryMap.getNumEntries());
            for (Integer elem : expectedElements) {
                RegionEntry re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
        }
    }
    IndexManager im = testRgn.getIndexManager();
    im.rerunIndexCreationQuery();
    ID = 5;
    i1 = im.getIndex("Index1");
    assertEquals(i1.getCanonicalizedIndexedExpression(), "index_iter1.maap[*]");
    assertTrue(i1 instanceof MapRangeIndex);
    mri = (MapRangeIndex) i1;
    // Test index maintenance
    // addition of new Portfolio object
    indxMap = mri.getRangeIndexHolderForTesting();
    assertEquals(indxMap.size(), ID);
    for (int j = 1; j <= ID; ++j) {
        assertTrue(indxMap.containsKey("key" + j));
        RangeIndex rng = (RangeIndex) indxMap.get("key" + j);
        Iterator itr = rng.valueToEntriesMap.values().iterator();
        assertEquals(rng.valueToEntriesMap.size(), 1);
        assertTrue(rng.valueToEntriesMap.containsKey("val" + j));
        Set<Integer> expectedElements = new HashSet<Integer>();
        for (int k = j; k <= ID; ++k) {
            expectedElements.add(k);
        }
        while (itr.hasNext()) {
            RegionEntryToValuesMap entryMap = (RegionEntryToValuesMap) itr.next();
            assertEquals(ID + 1 - j, entryMap.getNumEntries());
            for (Integer elem : expectedElements) {
                RegionEntry re = testRgn.basicGetEntry(elem);
                assertTrue(entryMap.containsEntry(re));
            }
        }
    }
}
Also used : Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) RegionEntryToValuesMap(org.apache.geode.cache.query.internal.index.AbstractIndex.RegionEntryToValuesMap) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) CloseableIterator(org.apache.geode.internal.cache.persistence.query.CloseableIterator) Iterator(java.util.Iterator) RegionEntry(org.apache.geode.internal.cache.RegionEntry) HashSet(java.util.HashSet) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 Index (org.apache.geode.cache.query.Index)3 QueryService (org.apache.geode.cache.query.QueryService)3 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)3 RegionEntryToValuesMap (org.apache.geode.cache.query.internal.index.AbstractIndex.RegionEntryToValuesMap)3 LocalRegion (org.apache.geode.internal.cache.LocalRegion)3 RegionEntry (org.apache.geode.internal.cache.RegionEntry)3 CloseableIterator (org.apache.geode.internal.cache.persistence.query.CloseableIterator)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 Test (org.junit.Test)3