use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class MemoryIndexStoreJUnitTest method testDescendingIteratorWithMultipleRemovedKeysReturnsExpectedOrderOfEntries.
@Test
public void testDescendingIteratorWithMultipleRemovedKeysReturnsExpectedOrderOfEntries() throws Exception {
RegionEntry mockEntry1 = mockEntries[0];
RegionEntry mockEntry2 = mockEntries[1];
RegionEntry mockEntry3 = mockEntries[2];
store.addMapping("1", mockEntry1);
store.addMapping("2", mockEntry2);
store.addMapping("3", mockEntry3);
Set keysToRemove = new HashSet();
keysToRemove.add("2");
keysToRemove.add("1");
Iterator iteratorFirst = store.descendingIterator(keysToRemove);
assertEquals(1, numObjectsIterated(iteratorFirst));
// keysToRemove has been modified by the store, we need to readd the key to remove
keysToRemove.add("2");
keysToRemove.add("1");
Iterator iterator = store.descendingIterator(keysToRemove);
iterator.hasNext();
assertEquals(mockEntry3, ((MemoryIndexStore.MemoryIndexStoreEntry) iterator.next()).getRegionEntry());
assertFalse(iterator.hasNext());
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class MemoryIndexStoreJUnitTest method testSizeWithKeyArgumentReturnsCorrectSize.
@Test
public void testSizeWithKeyArgumentReturnsCorrectSize() throws Exception {
RegionEntry mockEntry1 = mockEntries[0];
RegionEntry mockEntry2 = mockEntries[1];
store.addMapping("1", mockEntry1);
store.addMapping("2", mockEntry2);
assertEquals(1, store.size("1"));
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class MemoryIndexStoreJUnitTest method testUpdateAgainstAConcurrentHashSet.
@Test
public void testUpdateAgainstAConcurrentHashSet() throws Exception {
IntStream.range(0, 150).forEach(i -> {
try {
store.addMapping(1, createRegionEntry(1, new Object()));
} catch (Exception e) {
throw new AssertionError(e);
}
});
RegionEntry entry = createRegionEntry(1, new Object());
store.addMapping(1, entry);
store.updateMapping(2, 1, entry, entry.getValue(null));
assertEquals(151, numObjectsInStore(store));
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class MultiVMRegionTestCase method versionTestGetAllWithVersions.
public void versionTestGetAllWithVersions() {
// this test has timing issues in no-ack
assumeTrue(getRegionAttributes().getScope().isAck());
// scopes
VM vm0 = Host.getHost(0).getVM(0);
VM vm1 = Host.getHost(0).getVM(1);
final String regionName = getUniqueName() + "CCRegion";
SerializableRunnable createRegion = new SerializableRunnable("Create Region") {
@Override
public void run() {
try {
final RegionFactory f;
if (VM.getCurrentVMNum() == 0) {
f = getCache().createRegionFactory(getRegionAttributes(RegionShortcut.LOCAL.toString()));
f.setScope(getRegionAttributes().getScope());
} else {
f = getCache().createRegionFactory(getRegionAttributes());
}
CCRegion = (LocalRegion) f.create(regionName);
} catch (CacheException ex) {
fail("While creating region", ex);
}
}
};
vm0.invoke(createRegion);
vm1.invoke(createRegion);
vm1.invoke(new SerializableRunnable("Populate region and perform some ops") {
@Override
public void run() {
for (int i = 0; i < 100; i++) {
CCRegion.put("cckey" + i, Integer.valueOf(i));
}
for (int i = 0; i < 100; i++) {
CCRegion.put("cckey" + i, Integer.valueOf(i + 1));
}
}
});
vm0.invoke(new SerializableRunnable("Perform getAll") {
@Override
public void run() {
List keys = new LinkedList();
for (int i = 0; i < 100; i++) {
keys.add("cckey" + i);
}
Map result = CCRegion.getAll(keys);
assertTrue(result.size() == keys.size());
LocalRegion r = CCRegion;
for (int i = 0; i < 100; i++) {
RegionEntry entry = r.getRegionEntry("cckey" + i);
int stamp = entry.getVersionStamp().getEntryVersion();
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("checking key cckey" + i + " having version " + stamp + " entry=" + entry);
assertEquals(2, stamp);
assertEquals(result.get("cckey" + i), i + 1);
}
}
});
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class DistributedTransactionDUnitTest method testRegionAndEntryVersionsPR.
@Test
public void testRegionAndEntryVersionsPR() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
createPersistentPR(new VM[] { server1, server2 });
execute(server2, new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
getGemfireCache().getLoggerI18n().fine("TEST:DISTTX=" + mgr.isDistributed());
getGemfireCache().getLoggerI18n().fine("TEST:TX BEGIN");
mgr.begin();
Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
CustId custIdOne = new CustId(1);
Customer customerOne = new Customer("name1", "addr1");
getGemfireCache().getLoggerI18n().fine("TEST:TX PUT 1");
prRegion.put(custIdOne, customerOne);
BucketRegion br = ((PartitionedRegion) prRegion).getBucketRegion(custIdOne);
assertEquals(0L, br.getVersionVector().getCurrentVersion());
getGemfireCache().getLoggerI18n().fine("TEST:TX COMMIT 1");
mgr.commit();
// Verify region version on the region
assertEquals(1L, br.getVersionVector().getCurrentVersion());
RegionEntry re = br.getRegionEntry(custIdOne);
getGemfireCache().getLoggerI18n().fine("TEST:VERSION-STAMP:" + re.getVersionStamp());
// Verify region version on the region entry
assertEquals(1L, re.getVersionStamp().getRegionVersion());
// Verify entry version
assertEquals(1, re.getVersionStamp().getEntryVersion());
mgr.begin();
prRegion.put(custIdOne, new Customer("name1_1", "addr1"));
getGemfireCache().getLoggerI18n().fine("TEST:TX COMMIT 2");
assertEquals(1L, br.getVersionVector().getCurrentVersion());
mgr.commit();
// Verify region version on the region
assertEquals(2L, br.getVersionVector().getCurrentVersion());
re = br.getRegionEntry(custIdOne);
getGemfireCache().getLoggerI18n().fine("TEST:VERSION-STAMP:" + re.getVersionStamp());
// Verify region version on the region entry
assertEquals(2L, re.getVersionStamp().getRegionVersion());
// Verify entry version
assertEquals(2, re.getVersionStamp().getEntryVersion());
return null;
}
});
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
CustId custIdOne = new CustId(1);
BucketRegion br = ((PartitionedRegion) prRegion).getBucketRegion(custIdOne);
// Verify region version on the region
assertEquals(2L, br.getVersionVector().getCurrentVersion());
// Verify region version ont the region entry
RegionEntry re = br.getRegionEntry(custIdOne);
assertEquals(2L, re.getVersionStamp().getRegionVersion());
// Verify entry version
assertEquals(2, re.getVersionStamp().getEntryVersion());
return null;
}
});
}
Aggregations