use of org.apache.geode.internal.cache.versions.VersionStamp in project geode by apache.
the class UpdateVersionJUnitTest method testUpdateVersionAfterCreateOnPR.
/**
* Tests for Partitioned Region.
*/
@Test
public void testUpdateVersionAfterCreateOnPR() {
Cache cache = new CacheFactory().set(MCAST_PORT, "0").create();
Region region = cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);
try {
region.create("key-1", "value-1");
Entry entry = region.getEntry("key-1");
assertTrue(entry instanceof EntrySnapshot);
RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
VersionStamp stamp = regionEntry.getVersionStamp();
// Create a duplicate entry version tag from stamp with newer time-stamp.
VersionTag tag = VersionTag.create(stamp.getMemberID());
int entryVersion = stamp.getEntryVersion();
VersionSource member = stamp.getMemberID();
int dsid = stamp.getDistributedSystemId();
long time = System.currentTimeMillis();
tag.setEntryVersion(entryVersion);
tag.setDistributedSystemId(dsid);
tag.setVersionTimeStamp(time);
tag.setIsGatewayTag(true);
assertTrue(region instanceof PartitionedRegion);
EntryEventImpl event = createNewEvent((PartitionedRegion) region, tag, entry.getKey());
((PartitionedRegion) region).basicUpdateEntryVersion(event);
// Verify the new stamp
entry = region.getEntry("key-1");
assertTrue(entry instanceof EntrySnapshot);
regionEntry = ((EntrySnapshot) entry).getRegionEntry();
stamp = regionEntry.getVersionStamp();
assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
assertEquals(++entryVersion, stamp.getEntryVersion());
assertEquals(member, stamp.getMemberID());
assertEquals(dsid, stamp.getDistributedSystemId());
} finally {
region.destroyRegion();
cache.close();
}
}
use of org.apache.geode.internal.cache.versions.VersionStamp in project geode by apache.
the class UpdateVersionJUnitTest method testUpdateVersionAfterDestroy.
@Test
public void testUpdateVersionAfterDestroy() {
Cache cache = new CacheFactory().set(MCAST_PORT, "0").create();
Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
try {
region.create("key-1", "value-1");
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
region.destroy("key-1");
assertTrue(region instanceof LocalRegion);
Entry entry = ((LocalRegion) region).getEntry("key-1", true);
assertTrue(entry instanceof NonTXEntry);
RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
VersionStamp stamp = regionEntry.getVersionStamp();
// Create a duplicate entry version tag from stamp with newer time-stamp.
VersionTag tag = VersionTag.create(stamp.getMemberID());
int entryVersion = stamp.getEntryVersion();
VersionSource member = stamp.getMemberID();
int dsid = stamp.getDistributedSystemId();
long time = System.currentTimeMillis() + 1;
tag.setEntryVersion(entryVersion);
tag.setDistributedSystemId(dsid);
tag.setVersionTimeStamp(time);
tag.setIsGatewayTag(true);
EntryEventImpl event = createNewEvent((LocalRegion) region, tag, "key-1");
((LocalRegion) region).basicUpdateEntryVersion(event);
// Verify the new stamp
entry = ((LocalRegion) region).getEntry("key-1", true);
assertTrue(entry instanceof NonTXEntry);
regionEntry = ((NonTXEntry) entry).getRegionEntry();
stamp = regionEntry.getVersionStamp();
assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
assertEquals(++entryVersion, stamp.getEntryVersion());
assertEquals(member, stamp.getMemberID());
assertEquals(dsid, stamp.getDistributedSystemId());
} finally {
region.destroyRegion();
cache.close();
}
}
Aggregations