Search in sources :

Example 51 with EntryNotFoundException

use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.

the class UpdateVersionDUnitTest method testUpdateVersionAfterCreateWithSerialSender.

@Test
public void testUpdateVersionAfterCreateWithSerialSender() {
    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.createPartitionedRegion(regionName, "ln1", 1, 1));
    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.createPartitionedRegion(regionName, "", 1, 1));
    vm3.invoke(() -> UpdateVersionDUnitTest.createCache(nyPort));
    vm3.invoke(() -> UpdateVersionDUnitTest.createPartitionedRegion(regionName, "", 1, 1));
    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 PartitionedRegion);
            region.put(key, "value-1");
            region.put(key, "value-2");
            Entry entry = region.getEntry(key);
            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.
            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((PartitionedRegion) 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 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(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 PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName);
            // wait for entry to be received
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    Entry<?, ?> entry = null;
                    try {
                        entry = region.getDataStore().getEntryLocally(0, key, false, false);
                    } catch (EntryNotFoundException e) {
                    // expected
                    } catch (ForceReattemptException e) {
                    // expected
                    } catch (PRLocallyDestroyedException e) {
                        throw new RuntimeException("unexpected exception", e);
                    }
                    if (entry != null) {
                        LogWriterUtils.getLogWriter().info("found entry " + entry);
                    }
                    return (entry != null);
                }

                public String description() {
                    return "Expected " + key + " 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 EntrySnapshot);
                    RegionEntry regionEntry = ((EntrySnapshot) 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 class is wrong: " + entry, entry instanceof EntrySnapshot);
            RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
            VersionStamp stamp = regionEntry.getVersionStamp();
            return stamp.asVersionTag();
        }
    });
    assertEquals("Local and remote site have different timestamps", tag.getVersionTimeStamp(), remoteTag.getVersionTimeStamp());
}
Also used : 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) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) 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 52 with EntryNotFoundException

use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.

the class UpdateVersionDUnitTest method testUpdateVersionAfterCreateWithConcurrentSerialSender.

@Test
public void testUpdateVersionAfterCreateWithConcurrentSerialSender() {
    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);
    // Site 1
    Integer lnPort = (Integer) vm0.invoke(() -> UpdateVersionDUnitTest.createFirstLocatorWithDSId(1));
    final String key = "key-1";
    vm0.invoke(() -> UpdateVersionDUnitTest.createCache(lnPort));
    vm0.invoke(() -> UpdateVersionDUnitTest.createConcurrentSender("ln1", 2, false, 10, 2, false, false, null, true, 2));
    vm0.invoke(() -> UpdateVersionDUnitTest.createPartitionedRegion(regionName, "ln1", 1, 1));
    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.createPartitionedRegion(regionName, "", 1, 1));
    vm3.invoke(() -> UpdateVersionDUnitTest.createCache(nyPort));
    vm3.invoke(() -> UpdateVersionDUnitTest.createPartitionedRegion(regionName, "", 1, 1));
    final VersionTag tag = (VersionTag) vm0.invoke(new SerializableCallable("Put 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 PartitionedRegion);
            region.put(key, "value-1");
            region.put(key, "value-2");
            Entry entry = region.getEntry(key);
            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.
            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((PartitionedRegion) 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 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(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 PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName);
            // wait for entry to be received
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    Entry<?, ?> entry = null;
                    try {
                        entry = region.getDataStore().getEntryLocally(0, key, false, false);
                    } catch (EntryNotFoundException e) {
                    // expected
                    } catch (ForceReattemptException e) {
                    // expected
                    } catch (PRLocallyDestroyedException e) {
                        throw new RuntimeException("unexpected exception", e);
                    }
                    if (entry != null) {
                        LogWriterUtils.getLogWriter().info("found entry " + entry);
                    }
                    return (entry != 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 EntrySnapshot);
                    RegionEntry regionEntry = ((EntrySnapshot) 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 EntrySnapshot);
            RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
            VersionStamp stamp = regionEntry.getVersionStamp();
            return stamp.asVersionTag();
        }
    });
    assertEquals("Local and remote site have different timestamps", tag.getVersionTimeStamp(), remoteTag.getVersionTimeStamp());
}
Also used : 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) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) 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 53 with EntryNotFoundException

use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.

the class PartitionedRegionAPIDUnitTest method partitionedRegionTestAfterDestroyRegion.

/**
   * Test the Region operations after the PartitionedRegion has been destroyed
   * 
   * @param prName
   */
public void partitionedRegionTestAfterDestroyRegion(final String prName) {
    /*
     * do some put(), create(), invalidate() operations for PR with accessor + Datastore and
     * validate.
     */
    vm0.invoke(new CacheSerializableRunnable("doPutCreateInvalidateOperations1") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            String exceptionStr = "";
            Region pr = cache.getRegion(prName);
            if (pr == null) {
                fail("PR not created");
            }
            for (int i = putRange_1Start; i <= putRange_1End; i++) {
                // System.out.println("Putting entry for key = " + i);
                pr.put("" + i, "" + i);
            }
            // Create Operation
            for (int i = createRange_1Start; i <= createRange_1End; i++) {
                Object val = null;
                Object key = "" + i;
                if (i % 2 == 0) {
                    val = "" + i;
                }
                pr.create(key, val);
            }
            for (int i = createRange_1Start; i <= createRange_1End; i++) {
                Object val = null;
                Object key = "" + i;
                if (i % 2 == 0) {
                    val = "" + i;
                }
                final String expectedExceptions = EntryExistsException.class.getName();
                getCache().getLogger().info("<ExpectedException action=add>" + expectedExceptions + "</ExpectedException>");
                exceptionStr = ReplyException.class.getName() + ":" + expectedExceptions;
                vm1.invoke(addExceptionTag1(exceptionStr));
                vm2.invoke(addExceptionTag1(exceptionStr));
                vm3.invoke(addExceptionTag1(exceptionStr));
                addExceptionTag1(exceptionStr);
                try {
                    pr.create(key, val);
                    fail("EntryExistsException is not thrown");
                } catch (EntryExistsException expected) {
                // getLogWriter().fine("EntryExistsException is properly thrown");
                }
                vm1.invoke(removeExceptionTag1(exceptionStr));
                vm2.invoke(removeExceptionTag1(exceptionStr));
                vm3.invoke(removeExceptionTag1(exceptionStr));
                removeExceptionTag1(exceptionStr);
                getCache().getLogger().info("<ExpectedException action=remove>" + expectedExceptions + "</ExpectedException>");
            }
            for (int i = invalidateRange_1Start; i <= invalidateRange_1End; i++) {
                // Check that before creating an entry it throws
                // EntryNotFoundException
                final Object val = Integer.toString(i);
                final Object key = Integer.toString(i);
                final String entryNotFoundException = EntryNotFoundException.class.getName();
                getCache().getLogger().info("<ExpectedException action=add>" + entryNotFoundException + "</ExpectedException>");
                exceptionStr = ReplyException.class.getName() + "||" + entryNotFoundException;
                vm1.invoke(addExceptionTag1(exceptionStr));
                vm2.invoke(addExceptionTag1(exceptionStr));
                vm3.invoke(addExceptionTag1(exceptionStr));
                addExceptionTag1(exceptionStr);
                try {
                    pr.invalidate(key);
                    fail("EntryNotFoundException is not thrown for key which does not exists in the system = " + key);
                } catch (EntryNotFoundException expected) {
                }
                vm1.invoke(removeExceptionTag1(exceptionStr));
                vm2.invoke(removeExceptionTag1(exceptionStr));
                vm3.invoke(removeExceptionTag1(exceptionStr));
                removeExceptionTag1(exceptionStr);
                getCache().getLogger().info("<ExpectedException action=remove>" + entryNotFoundException + "</ExpectedException>");
                pr.create(key, val);
                assertTrue("containsValueForKey key=" + key, pr.containsValueForKey(key));
                assertEquals(val, pr.get(key));
                pr.invalidate(key);
                assertFalse(pr.containsValueForKey(key));
                assertNull(pr.get(key));
            }
            for (int i = invalidateRange_1Start; i <= invalidateRange_1End; i++) {
                final Object key = Integer.toString(i);
                pr.destroy(key);
            }
            final String entryNotFoundException = EntryNotFoundException.class.getName();
            getCache().getLogger().info("<ExpectedException action=add>" + entryNotFoundException + "</ExpectedException>");
            exceptionStr = ReplyException.class.getName() + "||" + entryNotFoundException;
            vm1.invoke(addExceptionTag1(exceptionStr));
            vm2.invoke(addExceptionTag1(exceptionStr));
            vm3.invoke(addExceptionTag1(exceptionStr));
            addExceptionTag1(exceptionStr);
            for (int i = invalidateRange_1Start; i <= invalidateRange_1End; i++) {
                // Check that after deleting an entry, invalidate for that entry
                // throws
                // EntryNotFoundException
                Object key = "" + i;
                try {
                    pr.invalidate(key);
                    fail("EntryNotFoundException is not thrown for key which does not exists in the system = " + key);
                } catch (EntryNotFoundException expected) {
                }
            }
            vm1.invoke(removeExceptionTag1(exceptionStr));
            vm2.invoke(removeExceptionTag1(exceptionStr));
            vm3.invoke(removeExceptionTag1(exceptionStr));
            removeExceptionTag1(exceptionStr);
            getCache().getLogger().info("<ExpectedException action=remove>" + entryNotFoundException + "</ExpectedException>");
            LogWriterUtils.getLogWriter().fine("Out of doPutOperations1");
            LogWriterUtils.getLogWriter().fine("All the puts done successfully for vm0.");
        }
    });
    /*
     * do some put(), create(), invalidate() operations for PR with only accessor and validate.
     */
    vm1.invoke(new CacheSerializableRunnable("doPutCreateInvalidateOperations2") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            String exceptionStr = "";
            Region pr = cache.getRegion(prName);
            if (pr == null) {
                fail("PR not created");
            }
            for (int i = putRange_2Start; i <= putRange_2End; i++) {
                // System.out.println("Putting entry for key = " + i);
                pr.put("" + i, "" + i);
            }
            // Create Operation
            for (int i = createRange_2Start; i <= createRange_2End; i++) {
                Object val = null;
                Object key = "" + i;
                if (i % 2 == 0) {
                    val = "" + i;
                }
                pr.create(key, val);
            }
            final String entryExistsException = EntryExistsException.class.getName();
            getCache().getLogger().info("<ExpectedException action=add>" + entryExistsException + "</ExpectedException>");
            exceptionStr = ReplyException.class.getName() + "||" + entryExistsException;
            vm0.invoke(addExceptionTag1(exceptionStr));
            vm2.invoke(addExceptionTag1(exceptionStr));
            vm3.invoke(addExceptionTag1(exceptionStr));
            addExceptionTag1(exceptionStr);
            for (int i = createRange_2Start; i <= createRange_2End; i++) {
                Object val = null;
                Object key = "" + i;
                if (i % 2 == 0) {
                    val = "" + i;
                }
                try {
                    pr.create(key, val);
                    fail("EntryExistsException is not thrown");
                } catch (EntryExistsException expected) {
                // getLogWriter().fine("EntryExistsException is properly thrown");
                }
            }
            vm0.invoke(removeExceptionTag1(exceptionStr));
            vm2.invoke(removeExceptionTag1(exceptionStr));
            vm3.invoke(removeExceptionTag1(exceptionStr));
            removeExceptionTag1(exceptionStr);
            getCache().getLogger().info("<ExpectedException action=remove>" + entryExistsException + "</ExpectedException>");
            // Invalidate Operations
            final String entryNotFoundException = EntryNotFoundException.class.getName();
            getCache().getLogger().info("<ExpectedException action=add>" + entryNotFoundException + "</ExpectedException>");
            exceptionStr = ReplyException.class.getName() + "||" + entryNotFoundException;
            vm0.invoke(addExceptionTag1(exceptionStr));
            vm2.invoke(addExceptionTag1(exceptionStr));
            vm3.invoke(addExceptionTag1(exceptionStr));
            addExceptionTag1(exceptionStr);
            for (int i = invalidateRange_2Start; i <= invalidateRange_2End; i++) {
                // Check that before creating an entry it throws
                // EntryNotFoundException
                final Object val = Integer.toString(i);
                final Object key = Integer.toString(i);
                try {
                    pr.invalidate(key);
                    fail("EntryNotFoundException is not thrown for key which does not exists in the system = " + key);
                } catch (EntryNotFoundException expected) {
                }
                pr.create(key, val);
            }
            vm0.invoke(removeExceptionTag1(exceptionStr));
            vm2.invoke(removeExceptionTag1(exceptionStr));
            vm3.invoke(removeExceptionTag1(exceptionStr));
            removeExceptionTag1(exceptionStr);
            getCache().getLogger().info("<ExpectedException action=remove>" + entryNotFoundException + "</ExpectedException>");
            for (int i = invalidateRange_2Start; i <= invalidateRange_2End; i++) {
                // Check that before creating an entry it throws
                // EntryNotFoundException
                final Object val = Integer.toString(i);
                final Object key = Integer.toString(i);
                assertEquals(val, pr.get(key));
                assertTrue(pr.containsValueForKey(key));
                pr.invalidate(key);
            }
            for (int i = invalidateRange_2Start; i <= invalidateRange_2End; i++) {
                final Object key = Integer.toString(i);
                Object shouldBeNull = pr.get(key);
                assertNull("Key " + key + " should report val null, however it has " + shouldBeNull, shouldBeNull);
                assertFalse("Key " + key + " should report False for containsValueForKey", pr.containsValueForKey(key));
            }
            for (int i = invalidateRange_2Start; i <= invalidateRange_2End; i++) {
                final Object key = Integer.toString(i);
                pr.destroy(key);
            }
            getCache().getLogger().info("<ExpectedException action=add>" + entryNotFoundException + "</ExpectedException>");
            exceptionStr = ReplyException.class.getName() + "||" + entryNotFoundException;
            vm0.invoke(addExceptionTag1(exceptionStr));
            vm2.invoke(addExceptionTag1(exceptionStr));
            vm3.invoke(addExceptionTag1(exceptionStr));
            addExceptionTag1(exceptionStr);
            for (int i = invalidateRange_2Start; i <= invalidateRange_2End; i++) {
                // Check that after deleting an entry, invalidate for that entry
                // throws
                // EntryNotFoundException
                final Object key = Integer.toString(i);
                try {
                    pr.invalidate(key);
                    fail("EntryNotFoundException is not thrown for key which does not exists in the system = " + key);
                } catch (EntryNotFoundException expected) {
                }
            }
            vm0.invoke(removeExceptionTag1(exceptionStr));
            vm2.invoke(removeExceptionTag1(exceptionStr));
            vm3.invoke(removeExceptionTag1(exceptionStr));
            removeExceptionTag1(exceptionStr);
            getCache().getLogger().info("<ExpectedException action=remove>" + entryNotFoundException + "</ExpectedException>");
            LogWriterUtils.getLogWriter().fine("Out of doPutOperations2");
            LogWriterUtils.getLogWriter().fine("All the puts done successfully for vm1.");
        }
    });
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) EntryExistsException(org.apache.geode.cache.EntryExistsException) Cache(org.apache.geode.cache.Cache)

Example 54 with EntryNotFoundException

use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.

the class SerialGatewaySenderQueue method remove.

/**
   * This method removes the last entry. However, it will only let the user remove entries that they
   * have peeked. If the entry was not peeked, this method will silently return.
   */
public synchronized void remove() throws CacheException {
    if (this.peekedIds.isEmpty()) {
        return;
    }
    Long key = this.peekedIds.remove();
    try {
        // Increment the head key
        updateHeadKey(key.longValue());
        removeIndex(key);
        // Remove the entry at that key with a callback arg signifying it is
        // a WAN queue so that AbstractRegionEntry.destroy can get the value
        // even if it has been evicted to disk. In the normal case, the
        // AbstractRegionEntry.destroy only gets the value in the VM.
        this.region.localDestroy(key, WAN_QUEUE_TOKEN);
        this.stats.decQueueSize();
    } catch (EntryNotFoundException ok) {
        // out from underneath us.
        if (logger.isDebugEnabled()) {
            logger.debug("{}: Did not destroy entry at {} it was not there. It should have been removed by conflation.", this, key);
        }
    }
    boolean wasEmpty = this.lastDispatchedKey == this.lastDestroyedKey;
    this.lastDispatchedKey = key;
    if (wasEmpty) {
        notifyAll();
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Destroyed entry at key {} setting the lastDispatched Key to {}. The last destroyed entry was {}", this, key, this.lastDispatchedKey, this.lastDestroyedKey);
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException)

Example 55 with EntryNotFoundException

use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.

the class DistributedNoAckRegionCCEDUnitTest method testOneHopKnownIssues.

@Test
public void testOneHopKnownIssues() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    // this VM, but treat as a remote for uniformity
    VM vm3 = host.getVM(3);
    // create an empty region in vm0 and replicated regions in VM 1 and 3,
    // then perform concurrent ops
    // on the same key while creating the region in VM2. Afterward make
    // sure that all three regions are consistent
    final String name = this.getUniqueName() + "-CC";
    SerializableRunnable createRegion = new SerializableRunnable("Create Region") {

        public void run() {
            try {
                final RegionFactory f;
                int vmNumber = VM.getCurrentVMNum();
                switch(vmNumber) {
                    case 0:
                        f = getCache().createRegionFactory(getRegionAttributes(RegionShortcut.REPLICATE_PROXY.toString()));
                        break;
                    case 1:
                        f = getCache().createRegionFactory(getRegionAttributes(RegionShortcut.REPLICATE.toString()));
                        f.setDataPolicy(DataPolicy.NORMAL);
                        break;
                    default:
                        f = getCache().createRegionFactory(getRegionAttributes());
                        break;
                }
                CCRegion = (LocalRegion) f.create(name);
            } catch (CacheException ex) {
                Assert.fail("While creating region", ex);
            }
        }
    };
    // empty
    vm0.invoke(createRegion);
    // normal
    vm1.invoke(createRegion);
    // replicate
    vm2.invoke(createRegion);
    // case 1: entry already invalid on vm2 (replicate) is invalidated by vm0 (empty)
    final String invalidationKey = "invalidationKey";
    final String destroyKey = "destroyKey";
    SerializableRunnable test = new SerializableRunnable("case 1: second invalidation not applied or distributed") {

        public void run() {
            CCRegion.put(invalidationKey, "initialValue");
            int invalidationCount = CCRegion.getCachePerfStats().getInvalidates();
            CCRegion.invalidate(invalidationKey);
            CCRegion.invalidate(invalidationKey);
            assertEquals(invalidationCount + 1, CCRegion.getCachePerfStats().getInvalidates());
            // also test destroy() while we're at it. It should throw an exception
            int destroyCount = CCRegion.getCachePerfStats().getDestroys();
            CCRegion.destroy(invalidationKey);
            try {
                CCRegion.destroy(invalidationKey);
                fail("expected an EntryNotFoundException");
            } catch (EntryNotFoundException e) {
            // expected
            }
            assertEquals(destroyCount + 1, CCRegion.getCachePerfStats().getDestroys());
        }
    };
    vm0.invoke(test);
    // now do the same with the datapolicy=normal region
    test.setName("case 2: second invalidation not applied or distributed");
    vm1.invoke(test);
}
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) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) Host(org.apache.geode.test.dunit.Host) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)78 Region (org.apache.geode.cache.Region)27 LocalRegion (org.apache.geode.internal.cache.LocalRegion)20 Test (org.junit.Test)18 CacheException (org.apache.geode.cache.CacheException)14 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)13 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)13 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)13 Released (org.apache.geode.internal.offheap.annotations.Released)12 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)10 StoredObject (org.apache.geode.internal.offheap.StoredObject)10 AttributesFactory (org.apache.geode.cache.AttributesFactory)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 CacheWriterException (org.apache.geode.cache.CacheWriterException)8 Entry (org.apache.geode.cache.Region.Entry)8 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)8 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)8 Host (org.apache.geode.test.dunit.Host)8