Search in sources :

Example 46 with TimeoutException

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

the class CqServiceImpl method closeCq.

@Override
public void closeCq(String cqName, ClientProxyMembershipID clientProxyId) throws CqException {
    String serverCqName = cqName;
    if (clientProxyId != null) {
        serverCqName = this.constructServerCqName(cqName, clientProxyId);
        removeFromCacheForServerToConstructedCQName(cqName, clientProxyId);
    }
    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) cqMap.get(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 {
        cQuery.close(false);
        // CqBaseRegion
        try {
            LocalRegion baseRegion = cQuery.getCqBaseRegion();
            if (baseRegion != null && !baseRegion.isDestroyed()) {
                // Server specific clean up.
                if (isServer()) {
                    FilterProfile fp = baseRegion.getFilterProfile();
                    if (fp != null) {
                        fp.closeCq(cQuery);
                    }
                    CacheClientProxy clientProxy = cQuery.getCacheClientNotifier().getClientProxy(clientProxyId);
                    clientProxy.decCqCount();
                    if (clientProxy.hasNoCq()) {
                        this.stats.decClientsWithCqs();
                    }
                }
            }
        } catch (Exception e) {
            // May be cache is being shutdown
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to remove CQ from the base region. CqName : {}", cqName);
            }
        }
        if (isServer()) {
            removeFromBaseRegionToCqNameMap(cQuery.getRegionName(), serverCqName);
        }
        LocalRegion baseRegion = cQuery.getCqBaseRegion();
        if (baseRegion.getFilterProfile().getCqCount() <= 0) {
            if (logger.isDebugEnabled()) {
                logger.debug("Should update the profile for this partitioned region {} for not requiring old value", baseRegion);
            }
        }
    } catch (CqClosedException cce) {
        throw new CqException(cce.getMessage());
    } finally {
        this.removeFromMatchingCqMap(cQuery);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CqException(org.apache.geode.cache.query.CqException) CqClosedException(org.apache.geode.cache.query.CqClosedException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) 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) FilterProfile(org.apache.geode.internal.cache.FilterProfile) StringId(org.apache.geode.i18n.StringId) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) TimeoutException(org.apache.geode.cache.TimeoutException)

Example 47 with TimeoutException

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

the class PutAllGlobalDUnitTest method testputAllGlobalRemoteVM.

// test methods
@Test
public void testputAllGlobalRemoteVM() throws Throwable {
    // Test Fails: AssertionError: Should have thrown TimeoutException
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final int socketPort = vm0.invoke(() -> this.openSocket());
    AsyncInvocation async1 = vm0.invokeAsync(() -> this.putAllMethod());
    AsyncInvocation async2 = vm1.invokeAsync(new CacheSerializableRunnable("put from another vm") {

        public void run2() throws CacheException {
            long endTime = System.currentTimeMillis() + 5000;
            boolean connected = false;
            while (!connected && (System.currentTimeMillis() < endTime)) {
                try {
                    Socket sock = new Socket(InetAddress.getLocalHost(), socketPort);
                    connected = true;
                    sock.close();
                } catch (IOException ioe) {
                    // ignored - will time out using 'endTime'
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException ie) {
                        fail("Interrupted while waiting for async1 invocation");
                    }
                }
            }
            if (!connected) {
                fail("unable to connect to async1 invocation");
            }
            long startTime = 0;
            try {
                Thread.sleep(500);
                LogWriterUtils.getLogWriter().info("async2 proceeding with put operation");
                startTime = System.currentTimeMillis();
                region.put(new Integer(1), "mapVal");
                LogWriterUtils.getLogWriter().info("async2 done with put operation");
                fail("Should have thrown TimeoutException");
            } catch (TimeoutException Tx) {
                // Tx.printStackTrace();
                LogWriterUtils.getLogWriter().info("PASS: As expected Caught TimeoutException ");
                if (startTime + TIMEOUT_PERIOD + DLockGrantor.GRANTOR_THREAD_MAX_WAIT < /* slop of grantor max wait ms */
                System.currentTimeMillis()) {
                    LogWriterUtils.getLogWriter().warning("though this test passed, the put() timed out in " + (System.currentTimeMillis() - startTime) + " instead of the expected " + TIMEOUT_PERIOD + " milliseconds");
                }
            } catch (Exception ex) {
                Assert.fail("async2 threw unexpected exception", ex);
            // ex.printStackTrace();
            }
        }
    });
    ThreadUtils.join(async2, 30 * 1000);
    if (async2.exceptionOccurred()) {
        ThreadUtils.join(async1, 30 * 1000);
        Assert.fail("async2 failed", async2.getException());
    }
    ThreadUtils.join(async1, 30 * 1000);
    if (async1.exceptionOccurred()) {
        Assert.fail("async1 failed", async1.getException());
    }
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) TimeoutException(org.apache.geode.cache.TimeoutException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) TimeoutException(org.apache.geode.cache.TimeoutException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 48 with TimeoutException

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

the class RemoveGlobalDUnitTest method testRemoveGlobalMultiVM.

// end of testRemoveGlobalSingleVM
@Test
public void testRemoveGlobalMultiVM() throws Throwable {
    // Commented the Test.As it is failing @ line no 145 : AssertionError
    SerializableRunnable createSimpleRegion = new CacheSerializableRunnable("create region with cache writer") {

        public void run2() throws CacheException {
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.GLOBAL);
            region = cache.createRegion("map", factory.create());
        }
    };
    SerializableRunnable createRegionWithWriter = new CacheSerializableRunnable("create region with capacity controller") {

        public void run2() throws CacheException {
            CacheWriter cw = new CacheWriterCallBack();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.GLOBAL);
            factory.setCacheWriter(cw);
            region = cache.createRegion("map", factory.create());
        }
    };
    vm0.invoke(createSimpleRegion);
    vm1.invoke(createRegionWithWriter);
    vm0.invoke(new CacheSerializableRunnable("put object") {

        public void run2() throws CacheException {
            for (int i = 1; i < 5; i++) {
                region.put(new Integer(i), java.lang.Integer.toString(i));
            }
        }
    });
    vm1.invoke(new CacheSerializableRunnable("get object") {

        public void run2() throws CacheException {
            for (int i = 1; i < 5; i++) {
                region.get(new Integer(i));
            }
        }
    });
    AsyncInvocation async = vm0.invokeAsync(new CacheSerializableRunnable("remove object") {

        public void run2() throws CacheException {
            region.remove(new Integer(2));
        }
    });
    vm1.invoke(new CacheSerializableRunnable("verify locking") {

        public void run2() throws CacheException {
            cache.setLockTimeout(5);
            synchronized (RemoveGlobalDUnitTest.class) {
                if (!lockedForRemove) {
                    try {
                        RemoveGlobalDUnitTest.class.wait();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            try {
                // getLogWriter().fine("11111111111111");
                region.put(new Integer(2), "newEntry");
                fail("Should have thrown TimeoutException");
            } catch (TimeoutException tme) {
            // pass
            }
        }
    });
    ThreadUtils.join(async, 30 * 1000);
    if (async.exceptionOccurred())
        throw async.getException();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) CacheWriter(org.apache.geode.cache.CacheWriter) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) TimeoutException(org.apache.geode.cache.TimeoutException) CacheException(org.apache.geode.cache.CacheException) TimeoutException(org.apache.geode.cache.TimeoutException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

TimeoutException (org.apache.geode.cache.TimeoutException)48 Test (org.junit.Test)24 CacheException (org.apache.geode.cache.CacheException)22 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)21 Host (org.apache.geode.test.dunit.Host)20 VM (org.apache.geode.test.dunit.VM)20 Region (org.apache.geode.cache.Region)18 AttributesFactory (org.apache.geode.cache.AttributesFactory)17 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)14 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)13 CacheWriterException (org.apache.geode.cache.CacheWriterException)10 LoaderHelper (org.apache.geode.cache.LoaderHelper)10 Lock (java.util.concurrent.locks.Lock)8 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)6 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 DLockTest (org.apache.geode.test.junit.categories.DLockTest)6 IOException (java.io.IOException)5 InternalGemFireError (org.apache.geode.InternalGemFireError)5 CacheWriter (org.apache.geode.cache.CacheWriter)5 StringId (org.apache.geode.i18n.StringId)5