Search in sources :

Example 46 with CacheWriterException

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

the class ClientInterestNotifyDUnitTest method registerInterest.

/**
   * register interest with the server on ALL_KEYS
   *
   */
public static void registerInterest() {
    try {
        Cache cacheClient = GemFireCacheImpl.getInstance();
        Region region1 = cacheClient.getRegion(Region.SEPARATOR + REGION_NAME1);
        Region region2 = cacheClient.getRegion(Region.SEPARATOR + REGION_NAME2);
        // We intentionally do not register interest in region 3 to check no events recvd.
        Region region3 = cacheClient.getRegion(Region.SEPARATOR + REGION_NAME3);
        assertTrue(region1 != null);
        assertTrue(region2 != null);
        assertTrue(region3 != null);
        region1.registerInterest("ALL_KEYS", InterestResultPolicy.KEYS_VALUES, false, true);
        region2.registerInterest("ALL_KEYS", InterestResultPolicy.KEYS_VALUES, false, false);
    // We intentionally do not register interest in region 3 to check no events recvd.
    // region3.registerInterestBlah();
    } catch (CacheWriterException e) {
        fail("test failed due to " + e);
    }
}
Also used : Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 47 with CacheWriterException

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

the class ClientServerMiscDUnitTest method registerInterestForInvalidatesInBothTheRegions.

public static void registerInterestForInvalidatesInBothTheRegions() {
    try {
        Cache cache = new ClientServerMiscDUnitTest().getCache();
        Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME1);
        assertNotNull(r1);
        Region r2 = cache.getRegion(Region.SEPARATOR + REGION_NAME2);
        assertNotNull(r2);
        r1.registerInterest("ALL_KEYS", false, false);
        r2.registerInterest("ALL_KEYS", false, false);
    } catch (CacheWriterException e) {
        e.printStackTrace();
        Assert.fail("Test failed due to CacheWriterException during registerInterestnBothRegions", e);
    }
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 48 with CacheWriterException

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

the class ConflationDUnitTest method unregisterInterest.

/**
   * register interest with the server on ALL_KEYS
   *
   */
public static void unregisterInterest() {
    try {
        Region region1 = cache.getRegion(Region.SEPARATOR + REGION_NAME1);
        Region region2 = cache.getRegion(Region.SEPARATOR + REGION_NAME2);
        region1.unregisterInterest("ALL_KEYS");
        region2.unregisterInterest("ALL_KEYS");
    } catch (CacheWriterException e) {
        fail("test failed due to " + e);
    }
}
Also used : HARegion(org.apache.geode.internal.cache.HARegion) Region(org.apache.geode.cache.Region) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 49 with CacheWriterException

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

the class RemoteTransactionDUnitTest method testOriginRemoteIsTrueForRemoteReplicatedRegions.

@Test
public void testOriginRemoteIsTrueForRemoteReplicatedRegions() {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore = host.getVM(1);
    initAccessorAndDataStore(accessor, datastore, 0);
    class OriginRemoteRRWriter extends CacheWriterAdapter {

        int fireC = 0;

        int fireD = 0;

        int fireU = 0;

        public void beforeCreate(EntryEvent event) throws CacheWriterException {
            if (!event.isOriginRemote()) {
                throw new CacheWriterException("SUP?? This CREATE is supposed to be isOriginRemote");
            }
            fireC++;
        }

        public void beforeDestroy(EntryEvent event) throws CacheWriterException {
            getGemfireCache().getLoggerI18n().fine("SWAP:writer:createEvent:" + event);
            if (!event.isOriginRemote()) {
                throw new CacheWriterException("SUP?? This DESTROY is supposed to be isOriginRemote");
            }
            fireD++;
        }

        public void beforeUpdate(EntryEvent event) throws CacheWriterException {
            if (!event.isOriginRemote()) {
                throw new CacheWriterException("SUP?? This UPDATE is supposed to be isOriginRemote");
            }
            fireU++;
        }
    }
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region refRegion = getCache().getRegion(D_REFERENCE);
            refRegion.getAttributesMutator().setCacheWriter(new OriginRemoteRRWriter());
            return null;
        }
    });
    accessor.invoke(new DoOpsInTX(OP.PUT));
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            TXStateProxy tx = mgr.internalSuspend();
            assertNotNull(tx);
            mgr.internalResume(tx);
            mgr.commit();
            return null;
        }
    });
    accessor.invoke(new DoOpsInTX(OP.DESTROY));
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            TXStateProxy tx = mgr.internalSuspend();
            assertNotNull(tx);
            mgr.internalResume(tx);
            mgr.commit();
            return null;
        }
    });
    accessor.invoke(new DoOpsInTX(OP.PUT));
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            TXStateProxy tx = mgr.internalSuspend();
            assertNotNull(tx);
            mgr.internalResume(tx);
            mgr.commit();
            return null;
        }
    });
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region refRegion = getCache().getRegion(D_REFERENCE);
            OriginRemoteRRWriter w = (OriginRemoteRRWriter) refRegion.getAttributes().getCacheWriter();
            assertEquals(1, w.fireC);
            assertEquals(1, w.fireD);
            assertEquals(1, w.fireU);
            return null;
        }
    });
}
Also used : CacheWriterAdapter(org.apache.geode.cache.util.CacheWriterAdapter) 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) VM(org.apache.geode.test.dunit.VM) EntryEvent(org.apache.geode.cache.EntryEvent) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) CacheWriterException(org.apache.geode.cache.CacheWriterException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 50 with CacheWriterException

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

the class PutAllCSDUnitTest method testClientDestroyOfUncreatedEntry.

/**
   * Checks to see if a client does a destroy that throws an exception from CacheWriter
   * beforeDestroy that the size of the region is still correct. See bug 51583.
   */
@Test
public void testClientDestroyOfUncreatedEntry() throws CacheException, InterruptedException {
    final String title = "testClientDestroyOfUncreatedEntry:";
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM client1 = host.getVM(1);
    final String regionName = getUniqueName();
    final String serverHost = NetworkUtils.getServerHostName(server1.getHost());
    // set <true, false> means <PR=true, notifyBySubscription=false> to test local-invalidates
    final int serverPort1 = createBridgeServer(server1, regionName, 0, false, 0, null);
    createClient(client1, regionName, serverHost, new int[] { serverPort1 }, -1, -1, false, true, true);
    server1.invoke(addExceptionTag1(expectedExceptions));
    client1.invoke(addExceptionTag1(expectedExceptions));
    server1.invoke(new CacheSerializableRunnable(title + "server1 add cacheWriter") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            // Install cacheWriter that causes the very first destroy to fail
            region.getAttributesMutator().setCacheWriter(new MyWriter(0));
        }
    });
    assertEquals(0, getRegionSize(server1, regionName));
    client1.invoke(new CacheSerializableRunnable(title + "client1 destroy") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            try {
                region.destroy("bogusKey");
                fail("Expect ServerOperationException caused by CacheWriterException");
            } catch (ServerOperationException expected) {
                assertTrue(expected.getCause() instanceof CacheWriterException);
            }
        }
    });
    assertEquals(0, getRegionSize(server1, regionName));
    server1.invoke(removeExceptionTag1(expectedExceptions));
    client1.invoke(removeExceptionTag1(expectedExceptions));
    stopBridgeServers(getCache());
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) CacheWriterException(org.apache.geode.cache.CacheWriterException) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Aggregations

CacheWriterException (org.apache.geode.cache.CacheWriterException)50 Region (org.apache.geode.cache.Region)22 Test (org.junit.Test)14 EntryEvent (org.apache.geode.cache.EntryEvent)13 Released (org.apache.geode.internal.offheap.annotations.Released)12 AttributesFactory (org.apache.geode.cache.AttributesFactory)11 CacheException (org.apache.geode.cache.CacheException)11 TimeoutException (org.apache.geode.cache.TimeoutException)11 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)10 CacheWriterAdapter (org.apache.geode.cache.util.CacheWriterAdapter)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)9 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)8 VM (org.apache.geode.test.dunit.VM)8 Cache (org.apache.geode.cache.Cache)7 RegionEvent (org.apache.geode.cache.RegionEvent)7 Host (org.apache.geode.test.dunit.Host)7 IOException (java.io.IOException)6 CacheWriter (org.apache.geode.cache.CacheWriter)6 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)6 InternalGemFireError (org.apache.geode.InternalGemFireError)5