Search in sources :

Example 16 with VersionTag

use of org.apache.geode.internal.cache.versions.VersionTag 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)

Example 17 with VersionTag

use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.

the class RRSynchronizationDUnitTest method createEntry2.

private boolean createEntry2(VM vm, final InternalDistributedMember forMember, final VersionSource memberVersionID) {
    return (Boolean) vm.invoke(new SerializableCallable("create entry2") {

        public Object call() {
            // create a fake event that looks like it came from the lost member and apply it to
            // this cache
            DistributedRegion dr = (DistributedRegion) TestRegion;
            VersionTag tag = new VMVersionTag();
            tag.setMemberID(memberVersionID);
            tag.setRegionVersion(2);
            tag.setEntryVersion(1);
            tag.setIsRemoteForTesting();
            EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "Object3", true, forMember, true, false);
            LogWriterUtils.getLogWriter().info("applying this event to the cache: " + event);
            event.setNewValue(new VMCachedDeserializable("value3", 12));
            event.setVersionTag(tag);
            dr.getRegionMap().basicPut(event, System.currentTimeMillis(), true, false, null, false, false);
            event.release();
            // now create a tombstone so we can be sure these are transferred in delta-GII
            tag = new VMVersionTag();
            tag.setMemberID(memberVersionID);
            tag.setRegionVersion(3);
            tag.setEntryVersion(1);
            tag.setIsRemoteForTesting();
            event = EntryEventImpl.create(dr, Operation.CREATE, "Object5", true, forMember, true, false);
            event.setNewValue(Token.TOMBSTONE);
            event.setVersionTag(tag);
            LogWriterUtils.getLogWriter().info("applying this event to the cache: " + event);
            dr.getRegionMap().basicPut(event, System.currentTimeMillis(), true, false, null, false, false);
            event.release();
            dr.dumpBackingMap();
            LogWriterUtils.getLogWriter().info("version vector is now " + dr.getVersionVector().fullToString());
            assertTrue("should hold entry Object3 now", dr.containsKey("Object3"));
            return true;
        }
    });
}
Also used : VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag)

Example 18 with VersionTag

use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.

the class DiskRegionTestingBase method compareVersionTags.

protected void compareVersionTags(HashMap<String, VersionTag> map1, HashMap<String, VersionTag> map2) {
    assertEquals(map1.size(), map2.size());
    for (String key : map1.keySet()) {
        VersionTag tag1 = map1.get(key);
        VersionTag tag2 = map2.get(key);
        assertEquals(tag1.getEntryVersion(), tag2.getEntryVersion());
        assertEquals(tag1.getRegionVersion(), tag2.getRegionVersion());
        assertEquals(tag1.getMemberID(), tag2.getMemberID());
    }
}
Also used : VersionTag(org.apache.geode.internal.cache.versions.VersionTag)

Example 19 with VersionTag

use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.

the class DiskRegionTestingBase method saveVersionTags.

protected HashMap<String, VersionTag> saveVersionTags(LocalRegion region) {
    HashMap<String, VersionTag> tagmap = new HashMap<String, VersionTag>();
    Iterator entryItr = region.entrySet().iterator();
    while (entryItr.hasNext()) {
        RegionEntry entry = ((NonTXEntry) entryItr.next()).getRegionEntry();
        String key = (String) entry.getKey();
        VersionTag tag = entry.getVersionStamp().asVersionTag();
        tagmap.put(key, tag);
    }
    return tagmap;
}
Also used : NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) HashMap(java.util.HashMap) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Iterator(java.util.Iterator)

Example 20 with VersionTag

use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.

the class DistributedRegionSearchLoadJUnitTest method createSearchLoad.

private void createSearchLoad() {
    SearchLoadAndWriteProcessor proc = mock(SearchLoadAndWriteProcessor.class);
    PowerMockito.mockStatic(SearchLoadAndWriteProcessor.class);
    PowerMockito.when(SearchLoadAndWriteProcessor.getProcessor()).thenReturn(proc);
    VersionTag tag = createVersionTag(true);
    doAnswer(new Answer<EntryEventImpl>() {

        public EntryEventImpl answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            if (args[0] instanceof EntryEventImpl) {
                EntryEventImpl event = (EntryEventImpl) args[0];
                event.setNewValue("NewLoadedValue");
                event.setOperation(Operation.LOCAL_LOAD_CREATE);
            }
            return null;
        }
    }).when(proc).doSearchAndLoad(any(EntryEventImpl.class), anyObject(), anyObject());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) VersionTag(org.apache.geode.internal.cache.versions.VersionTag)

Aggregations

VersionTag (org.apache.geode.internal.cache.versions.VersionTag)225 Test (org.junit.Test)43 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 VM (org.apache.geode.test.dunit.VM)24 CacheException (org.apache.geode.cache.CacheException)22 LocalRegion (org.apache.geode.internal.cache.LocalRegion)22 Region (org.apache.geode.cache.Region)21 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)19 VersionStamp (org.apache.geode.internal.cache.versions.VersionStamp)19 Host (org.apache.geode.test.dunit.Host)19 IOException (java.io.IOException)17 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)16 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)16 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)16 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)16 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)16 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)15 RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)15 ArrayList (java.util.ArrayList)14 CancelException (org.apache.geode.CancelException)14