Search in sources :

Example 31 with RegionEntry

use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.

the class QueryREUpdateInProgressJUnitTest method putREWithUpdateInProgressTrue.

private void putREWithUpdateInProgressTrue(String region) {
    Region reg = CacheUtils.getRegion(region);
    Portfolio[] values = createPortfoliosAndPositions(numOfEntries);
    int i = 0;
    for (Object val : values) {
        reg.put(i, val);
        i++;
    }
    // Set all RegionEntries to be updateInProgress.
    Iterator entryItr = reg.entrySet().iterator();
    while (entryItr.hasNext()) {
        Region.Entry nonTxEntry = (Region.Entry) entryItr.next();
        RegionEntry entry = ((NonTXEntry) nonTxEntry).getRegionEntry();
        entry.setUpdateInProgress(true);
        assertTrue(entry.isUpdateInProgress());
    }
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) Portfolio(org.apache.geode.cache.query.data.Portfolio) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry)

Example 32 with RegionEntry

use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.

the class NewWANConcurrencyCheckForDestroyDUnitTest method getVersionTimestampAfterOp.

/*
   * For VM3 in ds 2.
   */
public static long getVersionTimestampAfterOp() {
    Region region = cache.getRegion("repRegion");
    assertEquals(1, region.size());
    region.destroy("testKey");
    Region.Entry entry = ((LocalRegion) region).getEntry("testKey", /* null, */
    true);
    RegionEntry re = ((EntrySnapshot) entry).getRegionEntry();
    LogWriterUtils.getLogWriter().fine("RegionEntry for testKey: " + re.getKey() + " " + re.getValueInVM((LocalRegion) region));
    assertTrue(re.getValueInVM((LocalRegion) region) instanceof Tombstone);
    VersionTag tag = re.getVersionStamp().asVersionTag();
    return tag.getVersionTimeStamp();
}
Also used : Tombstone(org.apache.geode.internal.cache.Token.Tombstone) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) LocalRegion(org.apache.geode.internal.cache.LocalRegion) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 33 with RegionEntry

use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.

the class ElidedPutAllDUnitTest method testElidedPutAllOnPR.

/**
   * bug #47425 - elided putAll event causes PutAllPartialResultException
   */
@Test
public void testElidedPutAllOnPR() throws Exception {
    final String regionName = getUniqueName() + "Region";
    final String key = "key-1";
    Cache cache = getCache();
    PartitionedRegion region = (PartitionedRegion) cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);
    region.put(key, "value-1");
    region.put(key, "value-2");
    Entry<?, ?> entry = region.getEntry(key);
    assertTrue("expected entry to be in this vm", entry != null);
    VM vm1 = Host.getHost(0).getVM(1);
    vm1.invoke(new SerializableRunnable("perform conflicting update") {

        @Override
        public void run() {
            Cache cache = getCache();
            PartitionedRegion region = (PartitionedRegion) cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);
            try {
                Entry<?, ?> entry = region.getEntry(key);
                assertTrue(entry instanceof EntrySnapshot);
                RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
                final VersionTag<?> tag = regionEntry.getVersionStamp().asVersionTag();
                tag.setEntryVersion(tag.getEntryVersion() - 1);
                tag.setRegionVersion(1);
                Map<String, String> map = new HashMap<String, String>();
                map.put(key, "value-3");
                DistributedPutAllOperation dpao = region.newPutAllOperation(map, null);
                EntryEventImpl event = EntryEventImpl.create(region, Operation.PUTALL_CREATE, null, null, null, true, (DistributedMember) tag.getMemberID());
                event.setOldValue("value-1");
                event.setVersionTag(tag);
                event.setEventId(new EventID(cache.getDistributedSystem()));
                event.setKeyInfo(((PartitionedRegion) region).getKeyInfo(key));
                dpao.addEntry(event, event.getKeyInfo().getBucketId());
                // getLogWriter().info("dpao data = " + dpao.getPutAllEntryData()[0]);
                VersionedObjectList successfulPuts = new VersionedObjectList(1, true, true);
                successfulPuts.addKeyAndVersion(key, tag);
                try {
                    region.postPutAllSend(dpao, successfulPuts);
                } catch (ConcurrentCacheModificationException e) {
                    Assert.fail("Should not have received an exception for an elided operation", e);
                } finally {
                    event.release();
                    dpao.getBaseEvent().release();
                    dpao.freeOffHeapResources();
                }
            } catch (Exception e) {
                Assert.fail("caught unexpected exception", e);
            }
        }
    });
    entry = region.getEntry(key);
    assertTrue("expected value-2: " + entry.getValue(), entry.getValue().equals("value-2"));
    RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
    final VersionTag<?> tag = regionEntry.getVersionStamp().asVersionTag();
    assertTrue(tag.getEntryVersion() == 2);
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) DistributedPutAllOperation(org.apache.geode.internal.cache.DistributedPutAllOperation) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) RegionEntry(org.apache.geode.internal.cache.RegionEntry) Entry(org.apache.geode.cache.Region.Entry) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) DistributedMember(org.apache.geode.distributed.DistributedMember) RegionEntry(org.apache.geode.internal.cache.RegionEntry) EventID(org.apache.geode.internal.cache.EventID) HashMap(java.util.HashMap) Map(java.util.Map) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 34 with RegionEntry

use of org.apache.geode.internal.cache.RegionEntry 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 35 with RegionEntry

use of org.apache.geode.internal.cache.RegionEntry 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)

Aggregations

RegionEntry (org.apache.geode.internal.cache.RegionEntry)56 Test (org.junit.Test)32 LocalRegion (org.apache.geode.internal.cache.LocalRegion)20 UnitTest (org.apache.geode.test.junit.categories.UnitTest)15 Iterator (java.util.Iterator)13 Region (org.apache.geode.cache.Region)13 VM (org.apache.geode.test.dunit.VM)13 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)11 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)10 Host (org.apache.geode.test.dunit.Host)9 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)9 Map (java.util.Map)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 CacheException (org.apache.geode.cache.CacheException)7 EntrySnapshot (org.apache.geode.internal.cache.EntrySnapshot)7 CloseableIterator (org.apache.geode.internal.cache.persistence.query.CloseableIterator)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)5 Entry (java.util.Map.Entry)5 Cache (org.apache.geode.cache.Cache)5