Search in sources :

Example 36 with QueryInvocationTargetException

use of org.apache.geode.cache.query.QueryInvocationTargetException in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRAndRRQueryAndCompareResults.

public SerializableRunnableIF getCacheSerializableRunnableForPRAndRRQueryAndCompareResults(final String name, final String coloName, final String localName, final String coloLocalName) {
    SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            // Querying the PR region
            String[] queries = new String[] { "r1.ID = r2.id", "r1.ID = r2.id AND r1.ID > 5", "r1.ID = r2.id AND r1.status = 'active'", // "r1.ID = r2.id LIMIT 10",
            "r1.ID = r2.id ORDER BY r1.ID", "r1.ID = r2.id ORDER BY r2.id", "r1.ID = r2.id ORDER BY r2.status", "r1.ID = r2.id AND r1.status != r2.status", "r1.ID = r2.id AND r1.status = r2.status", "r1.ID = r2.id AND r1.positions.size = r2.positions.size", "r1.ID = r2.id AND r1.positions.size > r2.positions.size", "r1.ID = r2.id AND r1.positions.size < r2.positions.size", "r1.ID = r2.id AND r1.positions.size = r2.positions.size AND r2.positions.size > 0", "r1.ID = r2.id AND (r1.positions.size > r2.positions.size OR r2.positions.size > 0)", "r1.ID = r2.id AND (r1.positions.size < r2.positions.size OR r1.positions.size > 0)" };
            Object[][] r = new Object[queries.length][2];
            Region region = null;
            region = cache.getRegion(name);
            assertNotNull(region);
            region = cache.getRegion(coloName);
            assertNotNull(region);
            region = cache.getRegion(localName);
            assertNotNull(region);
            region = cache.getRegion(coloLocalName);
            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++) {
                    getCache().getLogger().info("About to execute local query: " + queries[j]);
                    Function func = new TestQueryFunction("testfunction");
                    Object funcResult = FunctionService.onRegion((getCache().getRegion(name) instanceof PartitionedRegion) ? getCache().getRegion(name) : getCache().getRegion(coloName)).setArguments("<trace> Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + name + " r1, /" + coloName + " r2, r2.positions.values pos2 where " + queries[j]).execute(func).getResult();
                    r[j][0] = ((ArrayList) funcResult).get(0);
                    getCache().getLogger().info("About to execute local query: " + queries[j]);
                    SelectResults r2 = (SelectResults) qs.newQuery("Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + localName + " r1, /" + coloLocalName + " r2, r2.positions.values pos2 where " + queries[j]).execute();
                    r[j][1] = r2.asList();
                }
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully on Local region & PR Region");
                // compareTwoQueryResults(r, queries.length);
                StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
                ssORrs.CompareQueryResultsAsListWithoutAndWithIndexes(r, queries.length, false, false, queries);
            } catch (QueryInvocationTargetException e) {
                // cause and see whether or 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) Function(org.apache.geode.cache.execute.Function) 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) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) 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 37 with QueryInvocationTargetException

use of org.apache.geode.cache.query.QueryInvocationTargetException in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRQueryAndCompareResults.

public CacheSerializableRunnable getCacheSerializableRunnableForPRQueryAndCompareResults(final String regionName, final String localRegion, final boolean fullQueryOnPortfolioPositions) {
    SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            // Querying the localRegion and the PR region
            String[] queries;
            if (fullQueryOnPortfolioPositions) {
                queries = new String[] { "import org.apache.geode.cache.\"query\".data.Position;" + "select distinct r.ID, status, mktValue " + "from $1 r, r.positions.values pVal TYPE Position " + "where r.status = 'active' AND pVal.mktValue >= 25.00", "import org.apache.geode.cache.\"query\".data.Position;" + "select distinct * " + "from $1 r, r.positions.values pVal TYPE Position " + "where r.status = 'active' AND pVal.mktValue >= 25.00", "import org.apache.geode.cache.\"query\".data.Position;" + "select distinct ID " + "from $1 r, r.positions.values pVal TYPE Position " + "where r.status = 'active' AND pVal.mktValue >= 25.00", "select distinct * " + "from $1 " + "where status = 'active'", "import org.apache.geode.cache.\"query\".data.Position;" + "select distinct r from $1 r, " + "r.positions.values pVal TYPE Position where pVal.mktValue < $2", "select p.positions.get('acc') from $1 p" };
            } else {
                queries = new String[] { "ID = 0 OR ID = 1", "ID > 4 AND ID < 9", "ID = 5", "ID < 5 ", "ID <= 5" };
            }
            Object[][] r = new Object[queries.length][2];
            Region local = cache.getRegion(localRegion);
            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 (int i = 0; i < expectedExceptions.length; i++) {
                getCache().getLogger().info("<ExpectedException action=add>" + expectedExceptions[i] + "</ExpectedException>");
            }
            QueryService qs = getCache().getQueryService();
            Object[] params;
            try {
                for (int j = 0; j < queries.length; j++) {
                    synchronized (region) {
                        if (fullQueryOnPortfolioPositions) {
                            params = new Object[] { local, new Double((j % 25) * 1.0 + 1) };
                            r[j][0] = qs.newQuery(queries[j]).execute(params);
                        } else {
                            r[j][0] = local.query(queries[j]);
                        }
                        if (fullQueryOnPortfolioPositions) {
                            params = new Object[] { region, new Double((j % 25) * 1.0 + 1) };
                            r[j][1] = qs.newQuery(queries[j]).execute(params);
                        } else {
                            r[j][1] = region.query(queries[j]);
                        }
                    }
                }
                compareTwoQueryResults(r, queries.length);
            } catch (QueryInvocationTargetException e) {
                // If cause is RegionDestroyedException then its ok
                Throwable cause = e.getCause();
                if (!(cause instanceof RegionDestroyedException)) {
                    // or 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 : 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) 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 38 with QueryInvocationTargetException

use of org.apache.geode.cache.query.QueryInvocationTargetException in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPROrderByQueryAndVerifyOrder.

public CacheSerializableRunnable getCacheSerializableRunnableForPROrderByQueryAndVerifyOrder(final String regionName, final String localRegion) {
    SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            // Querying the localRegion and the PR region
            String[] queries = new String[] { "p.status from /REGION_NAME p order by p.status", "status, ID from /REGION_NAME order by status, ID", "p.status, p.ID from /REGION_NAME p order by p.status, p.ID", "key.ID from /REGION_NAME.keys key order by key.ID", "key.ID, key.status from /REGION_NAME.keys key order by key.status, key.ID", "key.ID, key.status from /REGION_NAME.keys key order by key.status desc, key.ID", "key.ID, key.status from /REGION_NAME.keys key order by key.status, key.ID desc", "p.status, p.ID from /REGION_NAME p order by p.status asc, p.ID", "p.ID, p.status from /REGION_NAME p order by p.ID desc, p.status asc", "p.ID from /REGION_NAME p, p.positions.values order by p.ID", "p.ID, p.status from /REGION_NAME p, p.positions.values order by p.status, p.ID", "pos.secId from /REGION_NAME p, p.positions.values pos order by pos.secId", "p.ID, pos.secId from /REGION_NAME p, p.positions.values pos order by pos.secId, p.ID", "p.iD from /REGION_NAME p order by p.iD", "p.iD, p.status from /REGION_NAME p order by p.iD", "iD, status from /REGION_NAME order by iD", "p.getID() from /REGION_NAME p order by p.getID()", "p.names[1] from /REGION_NAME p order by p.names[1]", "p.position1.secId, p.ID from /REGION_NAME p order by p.position1.secId desc, p.ID", "p.ID, p.position1.secId from /REGION_NAME p order by p.position1.secId, p.ID", "e.key.ID from /REGION_NAME.entries e order by e.key.ID", "e.key.ID, e.value.status from /REGION_NAME.entries e order by e.key.ID", "e.key.ID, e.value.status from /REGION_NAME.entrySet e order by e.key.ID desc , e.value.status desc", "e.key, e.value from /REGION_NAME.entrySet e order by e.key.ID, e.value.status desc", "e.key from /REGION_NAME.entrySet e order by e.key.ID desc, e.key.pkid desc", "p.ID, pos.secId from /REGION_NAME p, p.positions.values pos order by p.ID, pos.secId", "p.ID, pos.secId from /REGION_NAME p, p.positions.values pos order by p.ID desc, pos.secId desc", "p.ID, pos.secId from /REGION_NAME p, p.positions.values pos order by p.ID desc, pos.secId" };
            Object[][] r = new Object[1][2];
            Region local = cache.getRegion(localRegion);
            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>");
            }
            String distinct = "SELECT DISTINCT ";
            QueryService qs = getCache().getQueryService();
            Object[] params;
            StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
            try {
                for (final String query : queries) {
                    String qStr = null;
                    synchronized (region) {
                        // Execute on local region.
                        qStr = (distinct + query.replace("REGION_NAME", localRegion));
                        r[0][0] = qs.newQuery(qStr).execute();
                        // Execute on remote region.
                        qStr = (distinct + query.replace("REGION_NAME", regionName));
                        r[0][1] = qs.newQuery(qStr).execute();
                        ssORrs.CompareQueryResultsWithoutAndWithIndexes(r, 1, true, queries);
                    }
                }
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully on Local region & PR Region");
            } 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) 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 39 with QueryInvocationTargetException

use of org.apache.geode.cache.query.QueryInvocationTargetException in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForRRAndPRQueryAndCompareResults.

public SerializableRunnableIF getCacheSerializableRunnableForRRAndPRQueryAndCompareResults(final String name, final String coloName, final String localName, final String coloLocalName) {
    SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            // Querying the PR region
            String[] queries = new String[] { "r1.ID = r2.id", "r1.ID = r2.id AND r1.ID > 5", "r1.ID = r2.id AND r1.status = 'active'", // "r1.ID = r2.id LIMIT 10",
            "r1.ID = r2.id ORDER BY r1.ID", "r1.ID = r2.id ORDER BY r2.id", "r1.ID = r2.id ORDER BY r2.status", "r1.ID = r2.id AND r1.status != r2.status", "r1.ID = r2.id AND r1.status = r2.status", "r1.ID = r2.id AND r1.positions.size = r2.positions.size", "r1.ID = r2.id AND r1.positions.size > r2.positions.size", "r1.ID = r2.id AND r1.positions.size < r2.positions.size", "r1.ID = r2.id AND r1.positions.size = r2.positions.size AND r2.positions.size > 0", "r1.ID = r2.id AND (r1.positions.size > r2.positions.size OR r2.positions.size > 0)", "r1.ID = r2.id AND (r1.positions.size < r2.positions.size OR r1.positions.size > 0)" };
            Object[][] r = new Object[queries.length][2];
            Region region = null;
            region = cache.getRegion(name);
            assertNotNull(region);
            region = cache.getRegion(coloName);
            assertNotNull(region);
            region = cache.getRegion(localName);
            assertNotNull(region);
            region = cache.getRegion(coloLocalName);
            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++) {
                    getCache().getLogger().info("About to execute local query: " + queries[j]);
                    Function func = new TestQueryFunction("testfunction");
                    Object funcResult = FunctionService.onRegion((getCache().getRegion(name) instanceof PartitionedRegion) ? getCache().getRegion(name) : getCache().getRegion(coloName)).setArguments("<trace> Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + name + " r1, r1.positions.values pos1, /" + coloName + " r2 where " + queries[j]).execute(func).getResult();
                    r[j][0] = ((ArrayList) funcResult).get(0);
                    getCache().getLogger().info("About to execute local query: " + queries[j]);
                    SelectResults r2 = (SelectResults) qs.newQuery("Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + localName + " r1, r1.positions.values pos1, /" + coloLocalName + " r2 where " + queries[j]).execute();
                    r[j][1] = r2.asList();
                }
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully on Local region & PR Region");
                StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
                ssORrs.CompareQueryResultsAsListWithoutAndWithIndexes(r, queries.length, false, false, queries);
            } catch (QueryInvocationTargetException e) {
                // cause and see whether or 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) Function(org.apache.geode.cache.execute.Function) 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) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) 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 40 with QueryInvocationTargetException

use of org.apache.geode.cache.query.QueryInvocationTargetException in project geode by apache.

the class SecurityTestUtils method doQueriesP.

private static void doQueriesP(final int multiUserIndex, final int expectedResult, final int expectedValue) {
    Region region = null;
    try {
        if (multiUserAuthMode) {
            region = proxyCaches[multiUserIndex].getRegion(REGION_NAME);
        } else {
            region = getCache().getRegion(REGION_NAME);
        }
        assertNotNull(region);
    } catch (Exception ex) {
        if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when doing queries: " + ex);
        } else {
            fail("Got unexpected exception when doing queries", ex);
        }
    }
    String queryStr = "SELECT DISTINCT * FROM " + region.getFullPath();
    try {
        SelectResults queryResults = region.query(queryStr);
        Set resultSet = queryResults.asSet();
        assertEquals(expectedValue, resultSet.size());
        if (expectedResult != NO_EXCEPTION) {
            fail("Expected a NotAuthorizedException while doing queries");
        }
    } catch (NoAvailableServersException ex) {
        if (expectedResult == NO_AVAILABLE_SERVERS) {
            getLogWriter().info("Got expected NoAvailableServers when doing queries: " + ex.getCause());
        } else {
            fail("Got unexpected exception when doing queries", ex);
        }
    } catch (ServerConnectivityException ex) {
        if ((expectedResult == NOTAUTHZ_EXCEPTION) && (ex.getCause() instanceof NotAuthorizedException)) {
            getLogWriter().info("Got expected NotAuthorizedException when doing queries: " + ex.getCause());
        } else if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when doing queries: " + ex);
        } else {
            fail("Got unexpected exception when doing queries", ex);
        }
    } catch (QueryInvocationTargetException qite) {
        if ((expectedResult == NOTAUTHZ_EXCEPTION) && (qite.getCause() instanceof NotAuthorizedException)) {
            getLogWriter().info("Got expected NotAuthorizedException when doing queries: " + qite.getCause());
        } else if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when doing queries: " + qite);
        } else {
            fail("Got unexpected exception when doing queries", qite);
        }
    } catch (Exception ex) {
        if (expectedResult == OTHER_EXCEPTION) {
            getLogWriter().info("Got expected exception when doing queries: " + ex);
        } else {
            fail("Got unexpected exception when doing queries", ex);
        }
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) SelectResults(org.apache.geode.cache.query.SelectResults) Set(java.util.Set) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) Region(org.apache.geode.cache.Region) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException)

Aggregations

QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)42 Region (org.apache.geode.cache.Region)23 SelectResults (org.apache.geode.cache.query.SelectResults)22 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)21 QueryService (org.apache.geode.cache.query.QueryService)20 QueryException (org.apache.geode.cache.query.QueryException)16 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)16 Cache (org.apache.geode.cache.Cache)15 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)15 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)15 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)15 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)14 Query (org.apache.geode.cache.query.Query)13 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)13 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)12 CancelException (org.apache.geode.CancelException)10 StructSetOrResultsSet (org.apache.geode.cache.query.functional.StructSetOrResultsSet)10 LocalRegion (org.apache.geode.internal.cache.LocalRegion)10 Host (org.apache.geode.test.dunit.Host)10 VM (org.apache.geode.test.dunit.VM)10