Search in sources :

Example 1 with RegionClearedException

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();
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) RegionEntry(org.apache.geode.internal.cache.RegionEntry) RegionClearedException(org.apache.geode.internal.cache.RegionClearedException) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with RegionClearedException

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();
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) RegionEntry(org.apache.geode.internal.cache.RegionEntry) RegionClearedException(org.apache.geode.internal.cache.RegionClearedException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

CacheException (org.apache.geode.cache.CacheException)2 RegionFactory (org.apache.geode.cache.RegionFactory)2 RegionClearedException (org.apache.geode.internal.cache.RegionClearedException)2 RegionEntry (org.apache.geode.internal.cache.RegionEntry)2 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 VM (org.apache.geode.test.dunit.VM)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 Test (org.junit.Test)2 VMVersionTag (org.apache.geode.internal.cache.versions.VMVersionTag)1 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)1