Search in sources :

Example 1 with CacheLoaderException

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

the class CqServiceImpl method stopCq.

/**
   * Called directly on server side.
   */
@Override
public void stopCq(String cqName, ClientProxyMembershipID clientId) throws CqException {
    String serverCqName = cqName;
    if (clientId != null) {
        serverCqName = this.constructServerCqName(cqName, clientId);
        removeFromCacheForServerToConstructedCQName(cqName, clientId);
    }
    ServerCQImpl cQuery = null;
    StringId errMsg = null;
    Exception ex = null;
    try {
        HashMap<String, CqQueryImpl> cqMap = cqQueryMap;
        if (!cqMap.containsKey(serverCqName)) {
            /*
         * gregp 052808: We should silently fail here instead of throwing error. This is to deal
         * with races in recovery
         */
            return;
        }
        cQuery = (ServerCQImpl) getCq(serverCqName);
    } catch (CacheLoaderException e1) {
        errMsg = LocalizedStrings.CqService_CQ_NOT_FOUND_IN_THE_CQ_META_REGION_CQNAME_0;
        ex = e1;
    } catch (TimeoutException e2) {
        errMsg = LocalizedStrings.CqService_TIMEOUT_WHILE_TRYING_TO_GET_CQ_FROM_META_REGION_CQNAME_0;
        ex = e2;
    } finally {
        if (ex != null) {
            String s = errMsg.toLocalizedString(cqName);
            if (logger.isDebugEnabled()) {
                logger.debug(s);
            }
            throw new CqException(s, ex);
        }
    }
    try {
        if (!cQuery.isStopped()) {
            cQuery.stop();
        }
    } catch (CqClosedException cce) {
        throw new CqException(cce.getMessage());
    } finally {
        // If this CQ is stopped, disable caching event keys for this CQ.
        // this.removeCQFromCaching(cQuery.getServerCqName());
        this.removeFromMatchingCqMap(cQuery);
    }
    // Send stop message to peers.
    cQuery.getCqBaseRegion().getFilterProfile().stopCq(cQuery);
}
Also used : StringId(org.apache.geode.i18n.StringId) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CqException(org.apache.geode.cache.query.CqException) CqClosedException(org.apache.geode.cache.query.CqClosedException) TimeoutException(org.apache.geode.cache.TimeoutException) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CqClosedException(org.apache.geode.cache.query.CqClosedException) QueryException(org.apache.geode.cache.query.QueryException) TimeoutException(org.apache.geode.cache.TimeoutException)

Example 2 with CacheLoaderException

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

the class SearchAndLoadDUnitTest method testLocalLoad.

@Test
public void testLocalLoad() throws CacheException, InterruptedException {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final String name = this.getUniqueName() + "-ACK";
    final String objectName = "C";
    final Integer value = new Integer(44);
    remoteLoaderInvoked = false;
    loaderInvoked = false;
    vm0.invoke(new SerializableRunnable("Create ACK Region") {

        public void run() {
            remoteLoaderInvoked = false;
            loaderInvoked = false;
            try {
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setEarlyAck(false);
                factory.setCacheLoader(new CacheLoader() {

                    public Object load(LoaderHelper helper) {
                        loaderInvoked = true;
                        return value;
                    }

                    public void close() {
                    }
                });
                Region region = createRegion(name, factory.create());
                region.create(objectName, null);
            } catch (CacheException ex) {
                Assert.fail("While creating ACK region", ex);
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Create ACK Region") {

        public void run() {
            remoteLoaderInvoked = false;
            loaderInvoked = false;
            try {
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setEarlyAck(false);
                factory.setCacheLoader(new CacheLoader() {

                    public Object load(LoaderHelper helper) {
                        remoteLoaderInvoked = true;
                        return value;
                    }

                    public void close() {
                    }
                });
                createRegion(name, factory.create());
            } catch (CacheException ex) {
                Assert.fail("While creating ACK region", ex);
            }
        }
    });
    vm0.invoke(new SerializableRunnable("Get a value from local loader") {

        public void run() {
            try {
                Object result = getRootRegion().getSubregion(name).get(objectName);
                assertEquals(value, result);
                assertEquals(new Boolean(loaderInvoked), Boolean.TRUE);
                assertEquals(new Boolean(remoteLoaderInvoked), Boolean.FALSE);
            } catch (CacheLoaderException cle) {
            } catch (TimeoutException te) {
            }
        }
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) LoaderHelper(org.apache.geode.cache.LoaderHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) TimeoutException(org.apache.geode.cache.TimeoutException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 3 with CacheLoaderException

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

the class SearchAndLoadDUnitTest method testNetSearch.

@Test
public void testNetSearch() throws CacheException, InterruptedException {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final String name = this.getUniqueName() + "-ACK";
    final String objectName = "NetSearchKey";
    final Integer value = new Integer(440);
    vm0.invoke(new SerializableRunnable("Create ACK Region") {

        public void run() {
            try {
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setEarlyAck(false);
                factory.setStatisticsEnabled(true);
                Region region = createRegion(name, factory.create());
                region.create(objectName, null);
            } catch (CacheException ex) {
                Assert.fail("While creating ACK region", ex);
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Create ACK Region") {

        public void run() {
            try {
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setEarlyAck(false);
                factory.setStatisticsEnabled(true);
                Region region = createRegion(name, factory.create());
                region.put(objectName, value);
            } catch (CacheException ex) {
                Assert.fail("While creating ACK region", ex);
            }
        }
    });
    vm2.invoke(new SerializableRunnable("Create ACK Region") {

        public void run() {
            try {
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setEarlyAck(false);
                factory.setStatisticsEnabled(true);
                Region region = createRegion(name, factory.create());
                region.create(objectName, null);
            } catch (CacheException ex) {
                Assert.fail("While creating ACK region", ex);
            }
        }
    });
    vm0.invoke(new SerializableRunnable("Get a value") {

        public void run() {
            try {
                Object result = null;
                result = getRootRegion().getSubregion(name).get(objectName);
                assertEquals(value, result);
            // System.err.println("Results is " + result.toString() + " Key is " +
            // objectName.toString());
            } catch (CacheLoaderException cle) {
                Assert.fail("While Get a value", cle);
            } catch (TimeoutException te) {
                Assert.fail("While Get a value", te);
            }
        }
    });
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheException(org.apache.geode.cache.CacheException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) TimeoutException(org.apache.geode.cache.TimeoutException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with CacheLoaderException

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

the class SearchAndLoadDUnitTest method testEmptyNetLoad.

/**
   * Confirm that a netLoad that returns null will NOT allow other netLoad methods to be called.
   */
@Test
public void testEmptyNetLoad() throws CacheException, InterruptedException {
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final String name = this.getUniqueName() + "-ACK";
    final String objectName = "B";
    loaderInvoked = false;
    remoteLoaderInvoked = false;
    remoteLoaderInvokedCount = 0;
    vm0.invoke(new SerializableRunnable("Create ACK Region") {

        public void run() {
            loaderInvoked = false;
            remoteLoaderInvoked = false;
            remoteLoaderInvokedCount = 0;
            try {
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setEarlyAck(false);
                // factory.setCacheLoader(new CacheLoader() {
                // public Object load(LoaderHelper helper) {
                /// loaderInvoked = true;
                // return value;
                // }
                //
                // public void close() {
                //
                // }
                // });
                Region region = createRegion(name, factory.create());
                region.create(objectName, null);
            } catch (CacheException ex) {
                Assert.fail("While creating ACK region", ex);
            }
        }
    });
    SerializableRunnable installLoader = new SerializableRunnable("Create ACK Region") {

        public void run() {
            loaderInvoked = false;
            remoteLoaderInvoked = false;
            remoteLoaderInvokedCount = 0;
            try {
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setEarlyAck(false);
                factory.setCacheLoader(new CacheLoader() {

                    public Object load(LoaderHelper helper) {
                        remoteLoaderInvoked = true;
                        remoteLoaderInvokedCount++;
                        return null;
                    }

                    public void close() {
                    }
                });
                createRegion(name, factory.create());
            } catch (CacheException ex) {
                Assert.fail("While creating ACK region", ex);
            }
        }
    };
    vm1.invoke(installLoader);
    vm2.invoke(installLoader);
    vm0.invoke(new SerializableRunnable("Get a value from remote loader") {

        public void run() {
            for (int i = 0; i < 1; i++) {
                try {
                    Object result = getRootRegion().getSubregion(name).get(objectName);
                    assertEquals(null, result);
                    assertEquals(false, loaderInvoked);
                // getRootRegion().getSubregion(name).invalidate(objectName);
                } catch (CacheLoaderException cle) {
                    Assert.fail("While getting value for ACK region", cle);
                }/*
           * catch(EntryNotFoundException enfe) { fail("While getting value for ACK region", enfe);
           * 
           * }
           */
                 catch (TimeoutException te) {
                    Assert.fail("While getting value for ACK region", te);
                }
            }
        }
    });
    // we only invoke one netLoad loader even when they return null.
    boolean xor = vmRemoteLoaderInvoked(vm1) ^ vmRemoteLoaderInvoked(vm2);
    assertEquals("vm1=" + vmRemoteLoaderInvoked(vm1) + " vm2=" + vmRemoteLoaderInvoked(vm2) + " vm1Count=" + vmRemoteLoaderInvokedCount(vm1) + " vm2Count=" + vmRemoteLoaderInvokedCount(vm2), true, xor);
    int total = vmRemoteLoaderInvokedCount(vm1) + vmRemoteLoaderInvokedCount(vm2);
    assertEquals("vm1=" + vmRemoteLoaderInvokedCount(vm1) + " vm2=" + vmRemoteLoaderInvokedCount(vm2), 1, total);
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) LoaderHelper(org.apache.geode.cache.LoaderHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) TimeoutException(org.apache.geode.cache.TimeoutException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 5 with CacheLoaderException

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

the class GlobalLockingDUnitTest method testLoadLockTimeout.

/**
   * get lock in one VM, try to invoke loader in other
   */
@Test
public void testLoadLockTimeout() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final String name = this.getUniqueName();
    final Object key = new Integer(5);
    // In first VM, get a lock on the entry
    vm0.invoke(new CacheSerializableRunnable("Get lock") {

        public void run2() throws CacheException {
            Region r = getOrCreateRootRegion().createSubregion(name, getGlobalAttrs());
            Lock lock = r.getDistributedLock(key);
            lock.lock();
        }
    });
    // In second VM, do a get that tries to invoke a loader
    vm1.invoke(new CacheSerializableRunnable("Lock timeout local loader") {

        public void run2() throws CacheException {
            getOrCreateRootRegion().getCache().setLockTimeout(2);
            Region r = getOrCreateRootRegion().createSubregion(name, getGlobalAttrs());
            r.getAttributesMutator().setCacheLoader(new CacheLoader() {

                public Object load(LoaderHelper helper) throws CacheLoaderException {
                    throw new CacheLoaderException("Made it into the loader!");
                }

                public void close() {
                }
            });
            try {
                r.get(key);
                fail("get() should have thrown TimeoutException");
            } catch (TimeoutException ex) {
            // pass
            }
        }
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) Lock(java.util.concurrent.locks.Lock) LoaderHelper(org.apache.geode.cache.LoaderHelper) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) TimeoutException(org.apache.geode.cache.TimeoutException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) DLockTest(org.apache.geode.test.junit.categories.DLockTest)

Aggregations

CacheLoaderException (org.apache.geode.cache.CacheLoaderException)45 Test (org.junit.Test)32 LoaderHelper (org.apache.geode.cache.LoaderHelper)31 Region (org.apache.geode.cache.Region)31 AttributesFactory (org.apache.geode.cache.AttributesFactory)25 VM (org.apache.geode.test.dunit.VM)23 CacheException (org.apache.geode.cache.CacheException)22 Host (org.apache.geode.test.dunit.Host)22 CacheLoader (org.apache.geode.cache.CacheLoader)19 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)19 TimeoutException (org.apache.geode.cache.TimeoutException)15 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)15 LocalRegion (org.apache.geode.internal.cache.LocalRegion)14 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)11 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)10 CacheWriterException (org.apache.geode.cache.CacheWriterException)9 StoredObject (org.apache.geode.internal.offheap.StoredObject)8 EntryEvent (org.apache.geode.cache.EntryEvent)7 AttributesMutator (org.apache.geode.cache.AttributesMutator)6 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)6