Search in sources :

Example 6 with QueryExecutionTimeoutException

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

the class QueryMonitorDUnitTest method testCacheOpAfterQueryCancel.

/**
   * Tests cache operation right after query cancellation.
   */
@Test
public void testCacheOpAfterQueryCancel() throws Exception {
    setup(4);
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM server3 = host.getVM(2);
    VM server4 = host.getVM(3);
    final int numberOfEntries = 1000;
    // Start server
    server1.invoke("Create BridgeServer", () -> configServer(5, "testQueryExecutionLocally"));
    server1.invoke("Create Partition Regions", () -> createPRRegion());
    server2.invoke("Create BridgeServer", () -> configServer(5, "testQueryExecutionLocally"));
    server2.invoke("Create Partition Regions", () -> createPRRegion());
    server3.invoke("Create BridgeServer", () -> configServer(5, "testQueryExecutionLocally"));
    server3.invoke("Create Partition Regions", () -> createPRRegion());
    server4.invoke("Create BridgeServer", () -> configServer(5, "testQueryExecutionLocally"));
    server4.invoke("Create Partition Regions", () -> createPRRegion());
    server1.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            try {
                QueryService queryService = GemFireCacheImpl.getInstance().getQueryService();
                queryService.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/root/exampleRegion");
                queryService.createIndex("secIdIndex", IndexType.FUNCTIONAL, "pos.secId", "/root/exampleRegion p, p.positions.values pos");
            } catch (Exception ex) {
                fail("Failed to create index.");
            }
            Region exampleRegion = getRootRegion().getSubregion(exampleRegionName);
            for (int i = 100; i <= (numberOfEntries); i++) {
                exampleRegion.put("" + i, new Portfolio(i));
            }
        }
    });
    // Initialize server regions.
    AsyncInvocation ai1 = server1.invokeAsync(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Region exampleRegion = getRootRegion().getSubregion(exampleRegionName);
            for (int j = 0; j < 5; j++) {
                for (int i = 1; i <= (numberOfEntries + 1000); i++) {
                    exampleRegion.put("" + i, new Portfolio(i));
                }
            }
            LogWriterUtils.getLogWriter().info("### Completed updates in server1 in testCacheOpAfterQueryCancel");
        }
    });
    AsyncInvocation ai2 = server2.invokeAsync(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Region exampleRegion = getRootRegion().getSubregion(exampleRegionName);
            for (int j = 0; j < 5; j++) {
                for (int i = (1 + 1000); i <= (numberOfEntries + 2000); i++) {
                    exampleRegion.put("" + i, new Portfolio(i));
                }
            }
            LogWriterUtils.getLogWriter().info("### Completed updates in server2 in testCacheOpAfterQueryCancel");
        }
    });
    // Execute server queries
    SerializableRunnable executeQuery = new CacheSerializableRunnable("Execute queries") {

        public void run2() throws CacheException {
            try {
                Region exampleRegion = getRootRegion().getSubregion(exampleRegionName);
                QueryService queryService = GemFireCacheImpl.getInstance().getQueryService();
                String qStr = "SELECT DISTINCT * FROM /root/exampleRegion p, p.positions.values pos1, p.positions.values pos" + " where p.ID < pos.sharesOutstanding OR p.ID > 0 OR p.position1.mktValue > 0 " + " OR pos.secId in SET ('SUN', 'IBM', 'YHOO', 'GOOG', 'MSFT', " + " 'AOL', 'APPL', 'ORCL', 'SAP', 'DELL', 'RHAT', 'NOVL', 'HP')" + " order by p.status, p.ID desc";
                for (int i = 0; i < 500; i++) {
                    try {
                        GemFireCacheImpl.getInstance().getLogger().info("Executing query :" + qStr);
                        Query query = queryService.newQuery(qStr);
                        query.execute();
                    } catch (QueryExecutionTimeoutException qet) {
                        LogWriterUtils.getLogWriter().info("### Got Expected QueryExecutionTimeout exception. " + qet.getMessage());
                        if (qet.getMessage().contains("cancelled after exceeding max execution")) {
                            LogWriterUtils.getLogWriter().info("### Doing a put operation");
                            exampleRegion.put("" + i, new Portfolio(i));
                        }
                    } catch (Exception e) {
                        fail("Exception executing query." + e.getMessage());
                    }
                }
                LogWriterUtils.getLogWriter().info("### Completed Executing queries in testCacheOpAfterQueryCancel");
            } catch (Exception ex) {
                Assert.fail("Exception creating the query service", ex);
            }
        }
    };
    AsyncInvocation ai3 = server3.invokeAsync(executeQuery);
    AsyncInvocation ai4 = server4.invokeAsync(executeQuery);
    LogWriterUtils.getLogWriter().info("### Waiting for async threads to join in testCacheOpAfterQueryCancel");
    try {
        ThreadUtils.join(ai1, 5 * 60 * 1000);
        ThreadUtils.join(ai2, 5 * 60 * 1000);
        ThreadUtils.join(ai3, 5 * 60 * 1000);
        ThreadUtils.join(ai4, 5 * 60 * 1000);
    } catch (Exception ex) {
        fail("Async thread join failure");
    }
    LogWriterUtils.getLogWriter().info("### DONE Waiting for async threads to join in testCacheOpAfterQueryCancel");
    validateQueryMonitorThreadCnt(server1, 0, 1000);
    validateQueryMonitorThreadCnt(server2, 0, 1000);
    validateQueryMonitorThreadCnt(server3, 0, 1000);
    validateQueryMonitorThreadCnt(server4, 0, 1000);
    LogWriterUtils.getLogWriter().info("### DONE validating query monitor threads testCacheOpAfterQueryCancel");
    stopServer(server1);
    stopServer(server2);
    stopServer(server3);
    stopServer(server4);
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) CacheException(org.apache.geode.cache.CacheException) Portfolio(org.apache.geode.cache.query.data.Portfolio) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) CqQueryDUnitTest(org.apache.geode.cache.query.cq.dunit.CqQueryDUnitTest) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

QueryExecutionTimeoutException (org.apache.geode.cache.query.QueryExecutionTimeoutException)6 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)3 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)3 Query (org.apache.geode.cache.query.Query)3 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)3 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)3 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 QueryExecutionLowMemoryException (org.apache.geode.cache.query.QueryExecutionLowMemoryException)2 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)2 GemfireRestException (org.apache.geode.rest.internal.web.exception.GemfireRestException)2 ResourceNotFoundException (org.apache.geode.rest.internal.web.exception.ResourceNotFoundException)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 IOException (java.io.IOException)1 CacheException (org.apache.geode.cache.CacheException)1 Region (org.apache.geode.cache.Region)1