Search in sources :

Example 1 with NonTXEntry

use of org.apache.geode.internal.cache.LocalRegion.NonTXEntry in project geode by apache.

the class UpdateVersionDUnitTest method testUpdateVersionAfterCreateWithSerialSenderOnDR.

@Test
public void testUpdateVersionAfterCreateWithSerialSenderOnDR() {
    Host host = Host.getHost(0);
    // server1 site1
    VM vm0 = host.getVM(0);
    // server2 site1
    VM vm1 = host.getVM(1);
    // server1 site2
    VM vm2 = host.getVM(2);
    // server2 site2
    VM vm3 = host.getVM(3);
    final String key = "key-1";
    // Site 1
    Integer lnPort = (Integer) vm0.invoke(() -> UpdateVersionDUnitTest.createFirstLocatorWithDSId(1));
    vm0.invoke(() -> UpdateVersionDUnitTest.createCache(lnPort));
    vm0.invoke(() -> UpdateVersionDUnitTest.createSender("ln1", 2, false, 10, 1, false, false, null, true));
    vm0.invoke(() -> UpdateVersionDUnitTest.createReplicatedRegion(regionName, "ln1"));
    vm0.invoke(() -> UpdateVersionDUnitTest.startSender("ln1"));
    vm0.invoke(() -> UpdateVersionDUnitTest.waitForSenderRunningState("ln1"));
    // Site 2
    Integer nyPort = (Integer) vm2.invoke(() -> UpdateVersionDUnitTest.createFirstRemoteLocator(2, lnPort));
    Integer nyRecPort = (Integer) vm2.invoke(() -> UpdateVersionDUnitTest.createReceiver(nyPort));
    vm2.invoke(() -> UpdateVersionDUnitTest.createReplicatedRegion(regionName, ""));
    vm3.invoke(() -> UpdateVersionDUnitTest.createCache(nyPort));
    vm3.invoke(() -> UpdateVersionDUnitTest.createReplicatedRegion(regionName, ""));
    final VersionTag tag = (VersionTag) vm0.invoke(new SerializableCallable("Update a single entry and get its version") {

        @Override
        public Object call() throws CacheException {
            Cache cache = CacheFactory.getAnyInstance();
            Region region = cache.getRegion(regionName);
            assertTrue(region instanceof DistributedRegion);
            region.put(key, "value-1");
            region.put(key, "value-2");
            Entry entry = region.getEntry(key);
            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.
            VersionSource memberId = (VersionSource) cache.getDistributedSystem().getDistributedMember();
            VersionTag tag = VersionTag.create(memberId);
            int entryVersion = stamp.getEntryVersion() - 1;
            int dsid = stamp.getDistributedSystemId();
            long time = System.currentTimeMillis();
            tag.setEntryVersion(entryVersion);
            tag.setDistributedSystemId(dsid);
            tag.setVersionTimeStamp(time);
            tag.setIsRemoteForTesting();
            EntryEventImpl event = createNewEvent((DistributedRegion) region, tag, entry.getKey(), "value-3");
            ((LocalRegion) region).basicUpdate(event, false, true, 0L, false);
            // Verify the new stamp
            entry = region.getEntry(key);
            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 + 1, stamp.getEntryVersion());
            assertEquals(dsid, stamp.getDistributedSystemId());
            return stamp.asVersionTag();
        }
    });
    VersionTag remoteTag = (VersionTag) vm3.invoke(new SerializableCallable("Get timestamp from remote site") {

        @Override
        public Object call() throws Exception {
            Cache cache = CacheFactory.getAnyInstance();
            final Region region = cache.getRegion(regionName);
            // wait for entry to be received
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    return (region.getEntry(key) != null);
                }

                public String description() {
                    return "Expected key-1 to be received on remote WAN site";
                }
            };
            Wait.waitForCriterion(wc, 30000, 500, true);
            wc = new WaitCriterion() {

                public boolean done() {
                    Entry entry = region.getEntry(key);
                    assertTrue(entry instanceof NonTXEntry);
                    RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
                    return regionEntry.getVersionStamp().getVersionTimeStamp() == tag.getVersionTimeStamp();
                }

                public String description() {
                    return "waiting for timestamp to be updated";
                }
            };
            Wait.waitForCriterion(wc, 30000, 500, true);
            Entry entry = region.getEntry(key);
            assertTrue(entry instanceof NonTXEntry);
            RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
            VersionStamp stamp = regionEntry.getVersionStamp();
            return stamp.asVersionTag();
        }
    });
    assertEquals("Local and remote site have different timestamps", tag.getVersionTimeStamp(), remoteTag.getVersionTimeStamp());
}
Also used : NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) Host(org.apache.geode.test.dunit.Host) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) Entry(org.apache.geode.cache.Region.Entry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 2 with NonTXEntry

use of org.apache.geode.internal.cache.LocalRegion.NonTXEntry in project geode by apache.

the class NewWANConcurrencyCheckForDestroyDUnitTest method getVersionTimestampAfterPutAllOp.

/*
   * For VM1 in ds 1. Used in testPutAllEventSequenceOnSerialGatewaySender.
   */
public static long getVersionTimestampAfterPutAllOp() {
    Region region = cache.getRegion("repRegion");
    while (!(region.containsKey("testKey"))) {
        Wait.pause(10);
    }
    assertEquals(1, region.size());
    Region.Entry entry = ((LocalRegion) region).getEntry("testKey", /* null, */
    true);
    RegionEntry re = null;
    if (entry instanceof EntrySnapshot) {
        re = ((EntrySnapshot) entry).getRegionEntry();
    } else if (entry instanceof NonTXEntry) {
        re = ((NonTXEntry) entry).getRegionEntry();
    }
    if (re != null) {
        LogWriterUtils.getLogWriter().fine("RegionEntry for testKey: " + re.getKey() + " " + re.getValueInVM((LocalRegion) region));
        VersionTag tag = re.getVersionStamp().asVersionTag();
        return tag.getVersionTimeStamp();
    } else {
        return -1;
    }
}
Also used : NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) LocalRegion(org.apache.geode.internal.cache.LocalRegion) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 3 with NonTXEntry

use of org.apache.geode.internal.cache.LocalRegion.NonTXEntry in project geode by apache.

the class NewWANConcurrencyCheckForDestroyDUnitTest method testConflictChecksBasedOnDsidAndTimeStamp.

/**
   * Tests if conflict checks are happening based on DSID and timestamp even if version tag is
   * generated in local distributed system.
   */
@Test
public void testConflictChecksBasedOnDsidAndTimeStamp() {
    // create two distributed systems with each having a cache containing
    // a Replicated Region with one entry and concurrency checks enabled.
    // Site 1
    Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
    createCacheInVMs(lnPort, vm1);
    Integer lnRecPort = (Integer) vm1.invoke(() -> WANTestBase.createReceiver());
    // Site 2
    Integer nyPort = (Integer) vm2.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
    createCacheInVMs(nyPort, vm3);
    Integer nyRecPort = (Integer) vm3.invoke(() -> WANTestBase.createReceiver());
    LogWriterUtils.getLogWriter().info("Created locators and receivers in 2 distributed systems");
    // Site 1
    vm1.invoke(() -> WANTestBase.createSender("ln1", 2, false, 10, 1, false, false, null, true));
    vm1.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ln1", isOffHeap()));
    vm1.invoke(() -> WANTestBase.startSender("ln1"));
    vm1.invoke(() -> WANTestBase.waitForSenderRunningState("ln1"));
    // Site 2
    vm3.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ny1", isOffHeap()));
    vm4.invoke(() -> WANTestBase.createCache(nyPort));
    vm4.invoke(() -> WANTestBase.createSender("ny1", 1, false, 10, 1, false, false, null, true));
    vm4.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ny1", isOffHeap()));
    vm4.invoke(() -> WANTestBase.startSender("ny1"));
    vm4.invoke(() -> WANTestBase.waitForSenderRunningState("ny1"));
    Wait.pause(2000);
    // Perform a put in vm1
    vm1.invoke(new CacheSerializableRunnable("Putting an entry in ds1") {

        @Override
        public void run2() throws CacheException {
            assertNotNull(cache);
            Region region = cache.getRegion("/repRegion");
            region.put("testKey", "testValue1");
            assertEquals(1, region.size());
        }
    });
    // wait for vm4 to have later timestamp before sending operation to vm1
    Wait.pause(300);
    AsyncInvocation asynch = vm4.invokeAsync(new CacheSerializableRunnable("Putting an entry in ds2 in vm4") {

        @Override
        public void run2() throws CacheException {
            assertNotNull(cache);
            Region region = cache.getRegion("/repRegion");
            region.put("testKey", "testValue2");
            assertEquals(1, region.size());
            assertEquals("testValue2", region.get("testKey"));
        }
    });
    try {
        asynch.join(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // Wait for all local ds events be received by vm3.
    Wait.pause(1000);
    vm3.invoke(new CacheSerializableRunnable("Check dsid") {

        @Override
        public void run2() throws CacheException {
            Region region = cache.getRegion("repRegion");
            Region.Entry entry = ((LocalRegion) region).getEntry("testKey", /* null, */
            true);
            // commented while merging revision 43582
            RegionEntry re = null;
            if (entry instanceof EntrySnapshot) {
                re = ((EntrySnapshot) entry).getRegionEntry();
            } else if (entry instanceof NonTXEntry) {
                re = ((NonTXEntry) entry).getRegionEntry();
            }
            VersionTag tag = re.getVersionStamp().asVersionTag();
            assertEquals(2, tag.getDistributedSystemId());
        }
    });
    // Check vm3 has latest timestamp from vm4.
    long putAllTimeStampVm1 = (Long) vm4.invoke(() -> NewWANConcurrencyCheckForDestroyDUnitTest.getVersionTimestampAfterPutAllOp());
    long putAllTimeStampVm3 = (Long) vm3.invoke(() -> NewWANConcurrencyCheckForDestroyDUnitTest.getVersionTimestampAfterPutAllOp());
    assertEquals(putAllTimeStampVm1, putAllTimeStampVm3);
}
Also used : NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) CacheException(org.apache.geode.cache.CacheException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RegionEntry(org.apache.geode.internal.cache.RegionEntry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with NonTXEntry

use of org.apache.geode.internal.cache.LocalRegion.NonTXEntry 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 5 with NonTXEntry

use of org.apache.geode.internal.cache.LocalRegion.NonTXEntry in project geode by apache.

the class UpdateVersionJUnitTest method testUpdateVersionAfterCreate.

/**
   * Tests for LocalRegion.
   */
@Test
public void testUpdateVersionAfterCreate() {
    Cache cache = new CacheFactory().set(MCAST_PORT, "0").create();
    Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
    try {
        region.create("key-1", "value-1");
        Entry entry = region.getEntry("key-1");
        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);
        assertTrue(region instanceof LocalRegion);
        EntryEventImpl event = createNewEvent((LocalRegion) region, tag, entry.getKey());
        ((LocalRegion) region).basicUpdateEntryVersion(event);
        // Verify the new stamp
        entry = region.getEntry("key-1");
        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();
    }
}
Also used : NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) Entry(org.apache.geode.cache.Region.Entry) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)14 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)9 Test (org.junit.Test)8 Region (org.apache.geode.cache.Region)7 Entry (org.apache.geode.cache.Region.Entry)6 VersionStamp (org.apache.geode.internal.cache.versions.VersionStamp)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 RegionEntry (org.apache.geode.internal.cache.RegionEntry)4 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)4 EntrySnapshot (org.apache.geode.internal.cache.EntrySnapshot)3 LocalRegion (org.apache.geode.internal.cache.LocalRegion)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 Iterator (java.util.Iterator)2 Set (java.util.Set)2 Host (org.apache.geode.test.dunit.Host)2 VM (org.apache.geode.test.dunit.VM)2 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1