Search in sources :

Example 46 with EntryNotFoundException

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

the class DistributedCacheTestCase method remoteInvalidate.

/**
   * Invalidates the value of an entry in a region in a remote VM
   *
   * @param regionName The name of a region that is a sub-region of the root region
   * @param entryName Must be {@link java.io.Serializable}
   */
protected static void remoteInvalidate(String regionName, String entryName) throws CacheException {
    Region root = getRootRegion();
    Region region = root.getSubregion(regionName);
    Region sub = region.getSubregion(entryName);
    if (sub == null) {
        String s = "Entry \"" + entryName + "\" does not exist";
        throw new EntryNotFoundException(s);
    }
    sub.invalidate(entryName);
}
Also used : EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) Region(org.apache.geode.cache.Region)

Example 47 with EntryNotFoundException

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

the class DistributedCacheTestCase method remoteAssertEntryValue.

/**
   * Asserts that the value of an entry in a region is what we expect it to be.
   *
   * @param regionName The name of a region that is a sub-region of the root region
   * @param entryName Must be {@link java.io.Serializable}
   */
protected static void remoteAssertEntryValue(String regionName, String entryName, Object expected) throws CacheException {
    Region root = getRootRegion();
    Region region = root.getSubregion(regionName);
    Region sub = region.getSubregion(entryName);
    if (sub == null) {
        String s = "Entry \"" + entryName + "\" does not exist";
        throw new EntryNotFoundException(s);
    }
    assertEquals(expected, sub.get(entryName));
}
Also used : EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) Region(org.apache.geode.cache.Region)

Example 48 with EntryNotFoundException

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

the class DistributedCacheTestCase method remoteReplace.

/**
   * Replaces the value of an entry in a region in a remote VM
   *
   * @param regionName The name of a region that is a sub-region of the root region
   * @param entryName Must be {@link java.io.Serializable}
   * @param value The value used to replace
   */
protected static void remoteReplace(String regionName, String entryName, Object value) throws CacheException {
    Region root = getRootRegion();
    Region region = root.getSubregion(regionName);
    Region sub = region.getSubregion(entryName);
    if (sub == null) {
        String s = "Entry \"" + entryName + "\" does not exist";
        throw new EntryNotFoundException(s);
    }
    sub.put(entryName, value);
    LogWriterUtils.getLogWriter().info("Replaced value " + value + "in entry " + entryName + " in region '" + region.getFullPath() + "'");
}
Also used : EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) Region(org.apache.geode.cache.Region)

Example 49 with EntryNotFoundException

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

the class RemoteTransactionDUnitTest method testRemoteFetchVersionMessage.

@Test
public void testRemoteFetchVersionMessage() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final String regionName = getName();
    final VersionTag tag = (VersionTag) vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            LocalRegion r = (LocalRegion) getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
            r.put("key", "value");
            return r.getRegionEntry("key").getVersionStamp().asVersionTag();
        }
    });
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            AttributesFactory af = new AttributesFactory();
            af.setDataPolicy(DataPolicy.EMPTY);
            af.setScope(Scope.DISTRIBUTED_ACK);
            DistributedRegion r = (DistributedRegion) getCache().createRegion(regionName, af.create());
            r.cache.getLogger().info("SWAP:sending:remoteTagRequest");
            VersionTag remote = r.fetchRemoteVersionTag("key");
            r.cache.getLogger().info("SWAP:remoteTag:" + remote);
            try {
                remote = r.fetchRemoteVersionTag("nonExistentKey");
                fail("expected exception not thrown");
            } catch (EntryNotFoundException e) {
            }
            assertEquals(tag, remote);
            return null;
        }
    });
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) 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) Host(org.apache.geode.test.dunit.Host) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 50 with EntryNotFoundException

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

the class RemoteTransactionDUnitTest method validateContains.

void validateContains(CustId custId, Set<OrderId> ordersSet, boolean containsKey, boolean containsValue) {
    Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
    Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
    Region<CustId, Order> refRegion = getCache().getRegion(D_REFERENCE);
    boolean rContainsKC = custRegion.containsKey(custId);
    boolean rContainsKO = containsKey;
    for (OrderId o : ordersSet) {
        getGemfireCache().getLoggerI18n().fine("SWAP:rContainsKO:" + rContainsKO + " containsKey:" + orderRegion.containsKey(o));
        rContainsKO = rContainsKO && orderRegion.containsKey(o);
    }
    boolean rContainsKR = refRegion.containsKey(custId);
    boolean rContainsVC = custRegion.containsValueForKey(custId);
    boolean rContainsVO = containsValue;
    for (OrderId o : ordersSet) {
        rContainsVO = rContainsVO && orderRegion.containsValueForKey(o);
    }
    boolean rContainsVR = refRegion.containsValueForKey(custId);
    assertEquals(containsKey, rContainsKC);
    assertEquals(containsKey, rContainsKO);
    assertEquals(containsKey, rContainsKR);
    assertEquals(containsValue, rContainsVR);
    assertEquals(containsValue, rContainsVC);
    assertEquals(containsValue, rContainsVO);
    if (containsKey) {
        Region.Entry eC = custRegion.getEntry(custId);
        for (OrderId o : ordersSet) {
            assertNotNull(orderRegion.getEntry(o));
        }
        Region.Entry eR = refRegion.getEntry(custId);
        assertNotNull(eC);
        assertNotNull(eR);
    // assertIndexDetailsEquals(1,custRegion.size());
    // assertIndexDetailsEquals(1,orderRegion.size());
    // assertIndexDetailsEquals(1,refRegion.size());
    } else {
        // assertIndexDetailsEquals(0,refRegion.size());
        try {
            Region.Entry eC = custRegion.getEntry(custId);
            assertNull("should have had an EntryNotFoundException:" + eC, eC);
        } catch (EntryNotFoundException enfe) {
        // this is what we expect
        }
        try {
            for (OrderId o : ordersSet) {
                assertNull("should have had an EntryNotFoundException:" + orderRegion.getEntry(o), orderRegion.getEntry(o));
            }
        } catch (EntryNotFoundException enfe) {
        // this is what we expect
        }
        try {
            Region.Entry eR = refRegion.getEntry(custId);
            assertNull("should have had an EntryNotFoundException:" + eR, eR);
        } catch (EntryNotFoundException enfe) {
        // this is what we expect
        }
    }
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) Entry(org.apache.geode.cache.Region.Entry) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) Region(org.apache.geode.cache.Region) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

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