Search in sources :

Example 96 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRCountStarQueries.

public CacheSerializableRunnable getCacheSerializableRunnableForPRCountStarQueries(final String regionName, final String localRegion) {
    SerializableRunnable PrRegion = new CacheSerializableRunnable("PRCountStarQuery") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            // Querying the localRegion and the PR region
            String[] queries = new String[] { "select COUNT(*) from /" + regionName, "select COUNT(*) from /" + regionName + " where ID > 0", "select COUNT(*) from /" + regionName + " where ID > 0 AND status='active'", "select COUNT(*) from /" + regionName + " where ID > 0 OR status='active'", "select COUNT(*) from /" + regionName + " where ID > 0 AND status LIKE 'act%'", "select COUNT(*) from /" + regionName + " where ID > 0 OR status LIKE 'ina%'", "select COUNT(*) from /" + regionName + " where ID IN SET(1, 2, 3, 4, 5)", "select COUNT(*) from /" + regionName + " where NOT (ID > 5)", "select DISTINCT COUNT(*) from /" + regionName + " where ID > 0", "select DISTINCT COUNT(*) from /" + regionName + " where ID > 0 AND status='active'", "select DISTINCT COUNT(*) from /" + regionName + " where ID > 0 OR status='active'", "select DISTINCT COUNT(*) from /" + regionName + " where ID > 0 AND status LIKE 'act%'", "select DISTINCT COUNT(*) from /" + regionName + " where ID > 0 OR status LIKE 'ina%'", "select DISTINCT COUNT(*) from /" + regionName + " where ID IN SET(1, 2, 3, 4, 5)", "select DISTINCT COUNT(*) from /" + regionName + " where NOT (ID > 5)", "select COUNT(*) from /" + regionName + " p, p.positions.values pos where p.ID > 0 AND pos.secId = 'IBM'", "select DISTINCT COUNT(*) from /" + regionName + " p, p.positions.values pos where p.ID > 0 AND pos.secId = 'IBM'", "select COUNT(*) from /" + regionName + " p, p.positions.values pos where p.ID > 0 AND pos.secId = 'IBM' LIMIT 5", "select DISTINCT COUNT(*) from /" + regionName + " p, p.positions.values pos where p.ID > 0 AND pos.secId = 'IBM' ORDER BY p.ID", "select COUNT(*) from /" + regionName + " p, p.positions.values pos where p.ID > 0 AND p.status = 'active' AND pos.secId = 'IBM'", "select COUNT(*) from /" + regionName + " p, p.positions.values pos where p.ID > 0 AND p.status = 'active' OR pos.secId = 'IBM'", "select COUNT(*) from /" + regionName + " p, p.positions.values pos where p.ID > 0 OR p.status = 'active' OR pos.secId = 'IBM'", "select COUNT(*) from /" + regionName + " p, p.positions.values pos where p.ID > 0 OR p.status = 'active' OR pos.secId = 'IBM' LIMIT 150" };
            Object[][] r = new Object[queries.length][2];
            Region region = cache.getRegion(regionName);
            assertNotNull(region);
            final String[] expectedExceptions = new String[] { RegionDestroyedException.class.getName(), ReplyException.class.getName(), CacheClosedException.class.getName(), ForceReattemptException.class.getName(), QueryInvocationTargetException.class.getName() };
            for (final String expectedException : expectedExceptions) {
                getCache().getLogger().info("<ExpectedException action=add>" + expectedException + "</ExpectedException>");
            }
            QueryService qs = getCache().getQueryService();
            Object[] params;
            try {
                for (int j = 0; j < queries.length; j++) {
                    String qStr = null;
                    synchronized (region) {
                        // Execute on PR region.
                        qStr = queries[j];
                        SelectResults sr = (SelectResults) qs.newQuery(qStr).execute();
                        r[j][0] = sr;
                        // Execute on local region.
                        qStr = queries[j];
                        SelectResults srr = (SelectResults) qs.newQuery(qStr.replace(regionName, localRegion)).execute();
                        r[j][1] = srr;
                    }
                }
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully on Local region & PR Region");
                StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
                ssORrs.CompareCountStarQueryResultsWithoutAndWithIndexes(r, queries.length, true, queries);
            } catch (QueryInvocationTargetException e) {
                // not it's okay
                throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
            } catch (QueryException e) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().error("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught QueryException while querying" + e, e);
                throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
            } catch (RegionDestroyedException rde) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a RegionDestroyedException while querying as expected ", rde);
            } catch (CancelException cce) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a CancelException while querying as expected ", cce);
            } finally {
                for (final String expectedException : expectedExceptions) {
                    getCache().getLogger().info("<ExpectedException action=remove>" + expectedException + "</ExpectedException>");
                }
            }
        }
    };
    return (CacheSerializableRunnable) PrRegion;
}
Also used : StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) TestException(util.TestException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) QueryException(org.apache.geode.cache.query.QueryException) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) Cache(org.apache.geode.cache.Cache)

Example 97 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class ReconnectDUnitTest method getRoleLossRunnable.

private CacheSerializableRunnable getRoleLossRunnable(final VM otherVM, final int locPort, final String regionName, final String myKey, final Object myValue, final String startupMessage) {
    return new CacheSerializableRunnable("roleloss runnable") {

        public void run2() {
            Thread t = null;
            try {
                // closeCache();
                // getSystem().disconnect();
                LogWriterUtils.getLogWriter().info(startupMessage);
                WaitCriterion ev = new WaitCriterion() {

                    public boolean done() {
                        return otherVM.invoke(() -> ReconnectDUnitTest.isInitialRolePlayerStarted()).booleanValue();
                    }

                    public String description() {
                        return null;
                    }
                };
                Wait.waitForCriterion(ev, 10 * 1000, 200, true);
                LogWriterUtils.getLogWriter().info("Starting the test and creating the cache and regions etc ...");
                locatorPort = locPort;
                Properties props = getDistributedSystemProperties();
                props.put(CACHE_XML_FILE, "RoleRegained.xml");
                props.put(MAX_WAIT_TIME_RECONNECT, "3000");
                props.put(MAX_NUM_RECONNECT_TRIES, "8");
                props.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
                getSystem(props);
                basicGetSystem().getLogWriter().info("<ExpectedException action=add>" + "CacheClosedException" + "</ExpectedException");
                try {
                    getCache();
                } catch (CancelException e) {
                    // can happen if RoleA goes away during initialization
                    LogWriterUtils.getLogWriter().info("cache threw CancelException while creating the cache");
                }
                initialized = true;
                addReconnectListener();
                ev = new WaitCriterion() {

                    public boolean done() {
                        LogWriterUtils.getLogWriter().info("ReconnectTries=" + reconnectTries);
                        return reconnectTries != 0;
                    }

                    public String description() {
                        return null;
                    }
                };
                Wait.waitForCriterion(ev, 30 * 1000, 200, true);
                // long startTime = System.currentTimeMillis();
                ev = new WaitCriterion() {

                    String excuse;

                    public boolean done() {
                        if (InternalDistributedSystem.getReconnectAttemptCounter() != 0) {
                            excuse = "reconnectCount is " + reconnectTries + " waiting for it to be zero";
                            return false;
                        }
                        Object key = null;
                        Object value = null;
                        Region.Entry keyValue = null;
                        try {
                            Cache cache = CacheFactory.getAnyInstance();
                            if (cache == null) {
                                excuse = "no cache";
                                return false;
                            }
                            Region myRegion = cache.getRegion(regionName);
                            if (myRegion == null) {
                                excuse = "no region";
                                return false;
                            }
                            Set keyValuePair = myRegion.entrySet();
                            Iterator it = keyValuePair.iterator();
                            while (it.hasNext()) {
                                keyValue = (Region.Entry) it.next();
                                key = keyValue.getKey();
                                value = keyValue.getValue();
                            }
                            if (key == null) {
                                excuse = "key is null";
                                return false;
                            }
                            if (!myKey.equals(key)) {
                                excuse = "key is wrong";
                                return false;
                            }
                            if (value == null) {
                                excuse = "value is null";
                                return false;
                            }
                            if (!myValue.equals(value)) {
                                excuse = "value is wrong";
                                return false;
                            }
                            LogWriterUtils.getLogWriter().info("All assertions passed");
                            LogWriterUtils.getLogWriter().info("MyKey : " + key + " and myvalue : " + value);
                            return true;
                        } catch (CancelException ecc) {
                        // ignor the exception because the cache can be closed/null some times
                        // while in reconnect.
                        } catch (RegionDestroyedException rex) {
                        } finally {
                            LogWriterUtils.getLogWriter().info("waiting for reconnect.  Current status is '" + excuse + "'");
                        }
                        return false;
                    }

                    public String description() {
                        return excuse;
                    }
                };
                // was 5 * 60 * 1000
                Wait.waitForCriterion(ev, 60 * 1000, 200, true);
                Cache cache = CacheFactory.getAnyInstance();
                if (cache != null) {
                    cache.getDistributedSystem().disconnect();
                }
            } catch (VirtualMachineError e) {
                SystemFailure.initiateFailure(e);
                throw e;
            } catch (Error th) {
                LogWriterUtils.getLogWriter().severe("DEBUG", th);
                throw th;
            } finally {
                if (t != null) {
                    ThreadUtils.join(t, 2 * 60 * 1000);
                }
                // greplogs won't care if you remove an exception that was never added,
                // and this ensures that it gets removed.
                basicGetSystem().getLogWriter().info("<ExpectedException action=remove>" + "CacheClosedException" + "</ExpectedException");
            }
        }
    };
// roleloss runnable
}
Also used : Set(java.util.Set) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Iterator(java.util.Iterator) CancelException(org.apache.geode.CancelException)

Example 98 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class ReconnectDUnitTest method testReconnectWithRoleLoss.

/**
   * Test the reconnect behavior when the required roles are missing. Reconnect is triggered as a
   * Reliability policy. The test is to see if the reconnect is triggered for the configured number
   * of times
   */
@Test
public void testReconnectWithRoleLoss() throws TimeoutException, RegionExistsException {
    final String rr1 = "RoleA";
    final String rr2 = "RoleB";
    final String[] requiredRoles = { rr1, rr2 };
    final int locPort = locatorPort;
    final String xmlFileLoc = (new File(".")).getAbsolutePath();
    beginCacheXml();
    locatorPort = locPort;
    Properties config = getDistributedSystemProperties();
    config.put(ROLES, "");
    config.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
    // config.put("log-file", "roleLossController.log");
    // creating the DS
    getSystem(config);
    MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.RECONNECT, ResumptionAction.NONE);
    AttributesFactory fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(Scope.DISTRIBUTED_ACK);
    RegionAttributes attr = fac.create();
    createRootRegion("MyRegion", attr);
    // writing the cachexml file.
    File file = new File("RoleReconnect-cache.xml");
    try {
        PrintWriter pw = new PrintWriter(new FileWriter(file), true);
        CacheXmlGenerator.generate(getCache(), pw);
        pw.close();
    } catch (IOException ex) {
        Assert.fail("IOException during cache.xml generation to " + file, ex);
    }
    closeCache();
    getSystem().disconnect();
    LogWriterUtils.getLogWriter().info("disconnected from the system...");
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    // Recreating from the cachexml.
    SerializableRunnable roleLoss = new CacheSerializableRunnable("ROLERECONNECTTESTS") {

        public void run2() throws RuntimeException {
            LogWriterUtils.getLogWriter().info("####### STARTING THE REAL TEST ##########");
            locatorPort = locPort;
            Properties props = getDistributedSystemProperties();
            props.put(CACHE_XML_FILE, xmlFileLoc + fileSeparator + "RoleReconnect-cache.xml");
            props.put(MAX_WAIT_TIME_RECONNECT, "200");
            final int timeReconnect = 3;
            props.put(MAX_NUM_RECONNECT_TRIES, "3");
            props.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            // props.put("log-file", "roleLossVM0.log");
            getSystem(props);
            addReconnectListener();
            basicGetSystem().getLogWriter().info("<ExpectedException action=add>" + "CacheClosedException" + "</ExpectedException");
            try {
                getCache();
                throw new RuntimeException("The test should throw a CancelException ");
            } catch (CancelException ignor) {
                // can be caused by role loss during intialization.
                LogWriterUtils.getLogWriter().info("Got Expected CancelException ");
            } finally {
                basicGetSystem().getLogWriter().info("<ExpectedException action=remove>" + "CacheClosedException" + "</ExpectedException");
            }
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    return reconnectTries >= timeReconnect;
                }

                public String description() {
                    return "Waiting for reconnect count " + timeReconnect + " currently " + reconnectTries;
                }
            };
            Wait.waitForCriterion(ev, 60 * 1000, 200, true);
            LogWriterUtils.getLogWriter().fine("roleLoss done Sleeping");
            assertEquals(timeReconnect, reconnectTries);
        }
    };
    vm0.invoke(roleLoss);
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CancelException(org.apache.geode.CancelException) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 99 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class FinishBackupRequest method send.

public static Map<DistributedMember, Set<PersistentID>> send(DM dm, Set recipients, File targetDir, File baselineDir, boolean abort) {
    FinishBackupRequest request = new FinishBackupRequest(targetDir, baselineDir, abort);
    request.setRecipients(recipients);
    FinishBackupReplyProcessor replyProcessor = new FinishBackupReplyProcessor(dm, recipients);
    request.msgId = replyProcessor.getProcessorId();
    dm.putOutgoing(request);
    try {
        replyProcessor.waitForReplies();
    } catch (ReplyException e) {
        if (!(e.getCause() instanceof CancelException)) {
            throw e;
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    AdminResponse response = request.createResponse((DistributionManager) dm);
    response.setSender(dm.getDistributionManagerId());
    replyProcessor.process(response);
    return replyProcessor.results;
}
Also used : AdminResponse(org.apache.geode.internal.admin.remote.AdminResponse) CancelException(org.apache.geode.CancelException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 100 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class FlushToDiskRequest method send.

public static void send(DM dm, Set recipients) {
    FlushToDiskRequest request = new FlushToDiskRequest();
    request.setRecipients(recipients);
    FlushToDiskProcessor replyProcessor = new FlushToDiskProcessor(dm, recipients);
    request.msgId = replyProcessor.getProcessorId();
    dm.putOutgoing(request);
    try {
        replyProcessor.waitForReplies();
    } catch (ReplyException e) {
        if (!(e.getCause() instanceof CancelException)) {
            throw e;
        }
    } catch (InterruptedException e) {
        logger.debug(e);
    }
    AdminResponse response = request.createResponse((DistributionManager) dm);
    response.setSender(dm.getDistributionManagerId());
    replyProcessor.process(response);
}
Also used : AdminResponse(org.apache.geode.internal.admin.remote.AdminResponse) CancelException(org.apache.geode.CancelException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Aggregations

CancelException (org.apache.geode.CancelException)135 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)46 IOException (java.io.IOException)40 ReplyException (org.apache.geode.distributed.internal.ReplyException)30 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)25 CacheClosedException (org.apache.geode.cache.CacheClosedException)23 Region (org.apache.geode.cache.Region)22 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)21 LocalRegion (org.apache.geode.internal.cache.LocalRegion)18 Set (java.util.Set)16 Cache (org.apache.geode.cache.Cache)16 CacheException (org.apache.geode.cache.CacheException)16 HashSet (java.util.HashSet)15 Iterator (java.util.Iterator)15 QueryException (org.apache.geode.cache.query.QueryException)15 ArrayList (java.util.ArrayList)13 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)13 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)13 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)13 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)13