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());
}
}
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();
}
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);
}
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));
}
}
}
}
}
}
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));
}
}
}
}
}
Aggregations