use of org.apache.geode.internal.cache.RegionClearedException in project geode by apache.
the class DistributedAckRegionCCEDUnitTest method testTombstoneExpirationRace.
/**
* make sure that an operation performed on a new region entry created after a tombstone has been
* reaped is accepted by another member that has yet to reap the tombstone
*/
@Test
public void testTombstoneExpirationRace() {
VM vm0 = Host.getHost(0).getVM(0);
VM vm1 = Host.getHost(0).getVM(1);
// VM vm2 = Host.getHost(0).getVM(2);
final String name = this.getUniqueName() + "-CC";
SerializableRunnable createRegion = new SerializableRunnable("Create Region") {
public void run() {
try {
RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
CCRegion = (LocalRegion) f.create(name);
CCRegion.put("cckey0", "ccvalue");
// version number will end up at 4
CCRegion.put("cckey0", "ccvalue");
} catch (CacheException ex) {
org.apache.geode.test.dunit.Assert.fail("While creating region", ex);
}
}
};
vm0.invoke(createRegion);
vm1.invoke(createRegion);
// vm2.invoke(createRegion);
vm1.invoke(new SerializableRunnable("Create local tombstone and adjust time") {
public void run() {
// make the entry for cckey0 a tombstone in this VM and set its modification time to be
// older
// than the tombstone GC interval. This means it could be in the process of being reaped by
// distributed-GC
RegionEntry entry = CCRegion.getRegionEntry("cckey0");
VersionTag tag = entry.getVersionStamp().asVersionTag();
assertTrue(tag.getEntryVersion() > 1);
tag.setVersionTimeStamp(System.currentTimeMillis() - TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT - 1000);
entry.getVersionStamp().setVersionTimeStamp(tag.getVersionTimeStamp());
try {
entry.makeTombstone(CCRegion, tag);
} catch (RegionClearedException e) {
org.apache.geode.test.dunit.Assert.fail("region was mysteriously cleared during unit testing", e);
}
}
});
// now remove the entry on vm0, simulating that it initiated a GC, and perform a CREATE with a
// new version number
vm0.invoke(new SerializableRunnable("Locally destroy the entry and do a create that will be propagated with v1") {
public void run() {
CCRegion.getRegionMap().removeEntry("cckey0", CCRegion.getRegionEntry("cckey0"), true);
if (CCRegion.getRegionEntry("ckey0") != null) {
fail("expected removEntry to remove the entry from the region's map");
}
CCRegion.put("cckey0", "updateAfterReap");
}
});
vm1.invoke(new SerializableRunnable("Check that the create() was applied") {
public void run() {
RegionEntry entry = CCRegion.getRegionEntry("cckey0");
assertTrue(entry.getVersionStamp().getEntryVersion() == 1);
}
});
disconnectAllFromDS();
}
use of org.apache.geode.internal.cache.RegionClearedException in project geode by apache.
the class GlobalRegionCCEDUnitTest method testTombstoneExpirationRace.
/**
* make sure that an operation performed on a new region entry created after a tombstone has been
* reaped is accepted by another member that has yet to reap the tombstone
*/
@Test
public void testTombstoneExpirationRace() {
VM vm0 = Host.getHost(0).getVM(0);
VM vm1 = Host.getHost(0).getVM(1);
// VM vm2 = Host.getHost(0).getVM(2);
final String name = this.getUniqueName() + "-CC";
SerializableRunnable createRegion = new SerializableRunnable("Create Region") {
public void run() {
try {
RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
CCRegion = (LocalRegion) f.create(name);
CCRegion.put("cckey0", "ccvalue");
// version number will end up at 4
CCRegion.put("cckey0", "ccvalue");
} catch (CacheException ex) {
Assert.fail("While creating region", ex);
}
}
};
vm0.invoke(createRegion);
vm1.invoke(createRegion);
// vm2.invoke(createRegion);
vm1.invoke(new SerializableRunnable("Create local tombstone and adjust time") {
public void run() {
// make the entry for cckey0 a tombstone in this VM and set its
// modification time to be older than the tombstone GC interval. This
// means it could be in the process of being reaped by distributed-GC
RegionEntry entry = CCRegion.getRegionEntry("cckey0");
VersionTag tag = entry.getVersionStamp().asVersionTag();
assertTrue(tag.getEntryVersion() > 1);
tag.setVersionTimeStamp(System.currentTimeMillis() - TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT - 1000);
entry.getVersionStamp().setVersionTimeStamp(tag.getVersionTimeStamp());
try {
entry.makeTombstone(CCRegion, tag);
} catch (RegionClearedException e) {
Assert.fail("region was mysteriously cleared during unit testing", e);
}
}
});
// now remove the entry on vm0, simulating that it initiated a GC, and
// perform a CREATE with a new version number
vm0.invoke(new SerializableRunnable("Locally destroy the entry and do a create that will be propagated with v1") {
public void run() {
CCRegion.getRegionMap().removeEntry("cckey0", CCRegion.getRegionEntry("cckey0"), true);
if (CCRegion.getRegionEntry("ckey0") != null) {
fail("expected removEntry to remove the entry from the region's map");
}
CCRegion.put("cckey0", "updateAfterReap");
}
});
vm1.invoke(new SerializableRunnable("Check that the create() was applied") {
public void run() {
RegionEntry entry = CCRegion.getRegionEntry("cckey0");
assertTrue(entry.getVersionStamp().getEntryVersion() == 1);
}
});
disconnectAllFromDS();
}
Aggregations