Search in sources :

Example 1 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class CqQueryOptimizedExecuteDUnitTest method testCqExecuteWithoutQueryExecutionAndNoRSCaching.

@Test
public void testCqExecuteWithoutQueryExecutionAndNoRSCaching() throws Exception {
    final Host host = Host.getHost(0);
    final VM server = host.getVM(0);
    final VM client = host.getVM(1);
    final int numOfEntries = 10;
    final String cqName = "testCqExecuteWithoutQueryExecution_1";
    server.invoke(new CacheSerializableRunnable("execute cq") {

        public void run2() throws CacheException {
            CqServiceProvider.MAINTAIN_KEYS = false;
        }
    });
    createServer(server);
    // Create values.
    createValues(server, regions[0], numOfEntries);
    final int thePort = server.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    // Create client.
    createClient(client, thePort, host0);
    /* Create CQs. */
    createCQ(client, cqName, cqs[0]);
    validateCQCount(client, 1);
    executeCQ(client, cqName, false, null);
    server.invoke(new CacheSerializableRunnable("execute cq") {

        public void run2() throws CacheException {
            assertFalse("CqServiceImpl.EXECUTE_QUERY_DURING_INIT flag should be false ", CqServiceImpl.EXECUTE_QUERY_DURING_INIT);
            assertFalse(DistributionConfig.GEMFIRE_PREFIX + "cq.MAINTAIN_KEYS flag should be false ", CqServiceProvider.MAINTAIN_KEYS);
            int numOfQueryExecutions = (Integer) ((GemFireCacheImpl) getCache()).getCachePerfStats().getStats().get("queryExecutions");
            assertEquals("Number of query executions for cq.execute should be 0 ", 0, numOfQueryExecutions);
        }
    });
    // Create more values.
    server.invoke(new CacheSerializableRunnable("Create values") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regions[0]);
            for (int i = numOfEntries + 1; i <= numOfEntries * 2; i++) {
                region1.put(KEY + i, new Portfolio(i));
            }
            LogWriterUtils.getLogWriter().info("### Number of Entries in Region :" + region1.keySet().size());
        }
    });
    waitForCreated(client, cqName, KEY + numOfEntries * 2);
    validateCQ(client, cqName, /* resultSize: */
    noTest, /* creates: */
    numOfEntries, /* updates: */
    0, /* deletes; */
    0, /* queryInserts: */
    numOfEntries, /* queryUpdates: */
    0, /* queryDeletes: */
    0, /* totalEvents: */
    numOfEntries);
    // Update values.
    createValues(server, regions[0], 5);
    createValues(server, regions[0], 10);
    waitForUpdated(client, cqName, KEY + numOfEntries);
    // validate Update events.
    validateCQ(client, cqName, /* resultSize: */
    noTest, /* creates: */
    numOfEntries, /* updates: */
    15, /* deletes; */
    0, /* queryInserts: */
    numOfEntries, /* queryUpdates: */
    15, /* queryDeletes: */
    0, /* totalEvents: */
    numOfEntries + 15);
    // Validate delete events.
    deleteValues(server, regions[0], 5);
    waitForDestroyed(client, cqName, KEY + 5);
    validateCQ(client, cqName, /* resultSize: */
    noTest, /* creates: */
    numOfEntries, /* updates: */
    15, /* deletes; */
    5, /* queryInserts: */
    numOfEntries, /* queryUpdates: */
    15, /* queryDeletes: */
    5, /* totalEvents: */
    numOfEntries + 15 + 5);
    closeClient(client);
    closeServer(server);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) Portfolio(org.apache.geode.cache.query.data.Portfolio) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Region(org.apache.geode.cache.Region) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class CqQueryOptimizedExecuteDUnitTest method testCqExecuteWithoutQueryExecution.

@Test
public void testCqExecuteWithoutQueryExecution() throws Exception {
    final Host host = Host.getHost(0);
    final VM server = host.getVM(0);
    final VM client = host.getVM(1);
    final int numOfEntries = 10;
    final String cqName = "testCqExecuteWithoutQueryExecution_1";
    createServer(server);
    // Create values.
    createValues(server, regions[0], numOfEntries);
    final int thePort = server.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    // Create client.
    createClient(client, thePort, host0);
    /* Create CQs. */
    createCQ(client, cqName, cqs[0]);
    validateCQCount(client, 1);
    executeCQ(client, cqName, false, null);
    server.invoke(new CacheSerializableRunnable("execute cq") {

        public void run2() throws CacheException {
            assertFalse("CqServiceImpl.EXECUTE_QUERY_DURING_INIT flag should be false ", CqServiceImpl.EXECUTE_QUERY_DURING_INIT);
            int numOfQueryExecutions = (Integer) ((GemFireCacheImpl) getCache()).getCachePerfStats().getStats().get("queryExecutions");
            assertEquals("Number of query executions for cq.execute should be 0 ", 0, numOfQueryExecutions);
        }
    });
    // Create more values.
    server.invoke(new CacheSerializableRunnable("Create values") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regions[0]);
            for (int i = numOfEntries + 1; i <= numOfEntries * 2; i++) {
                region1.put(KEY + i, new Portfolio(i));
            }
            LogWriterUtils.getLogWriter().info("### Number of Entries in Region :" + region1.keySet().size());
        }
    });
    waitForCreated(client, cqName, KEY + numOfEntries * 2);
    validateCQ(client, cqName, /* resultSize: */
    noTest, /* creates: */
    numOfEntries, /* updates: */
    0, /* deletes; */
    0, /* queryInserts: */
    numOfEntries, /* queryUpdates: */
    0, /* queryDeletes: */
    0, /* totalEvents: */
    numOfEntries);
    // Update values.
    createValues(server, regions[0], 5);
    createValues(server, regions[0], 10);
    waitForUpdated(client, cqName, KEY + numOfEntries);
    // validate Update events.
    validateCQ(client, cqName, /* resultSize: */
    noTest, /* creates: */
    numOfEntries, /* updates: */
    15, /* deletes; */
    0, /* queryInserts: */
    numOfEntries, /* queryUpdates: */
    15, /* queryDeletes: */
    0, /* totalEvents: */
    numOfEntries + 15);
    // Validate delete events.
    deleteValues(server, regions[0], 5);
    waitForDestroyed(client, cqName, KEY + 5);
    validateCQ(client, cqName, /* resultSize: */
    noTest, /* creates: */
    numOfEntries, /* updates: */
    15, /* deletes; */
    5, /* queryInserts: */
    numOfEntries, /* queryUpdates: */
    15, /* queryDeletes: */
    5, /* totalEvents: */
    numOfEntries + 15 + 5);
    closeClient(client);
    closeServer(server);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) Portfolio(org.apache.geode.cache.query.data.Portfolio) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Region(org.apache.geode.cache.Region) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 3 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class QueryMonitorDUnitTest method configServer.

private int configServer(final int queryMonitorTime, final String testName) {
    int port = 0;
    try {
        port = startBridgeServer(0, false);
    } catch (Exception ex) {
        Assert.fail("While starting CacheServer", ex);
    }
    Cache cache = getCache();
    GemFireCacheImpl.getInstance().testMaxQueryExecutionTime = queryMonitorTime;
    cache.getLogger().fine("#### RUNNING TEST : " + testName);
    DefaultQuery.testHook = new QueryTimeoutHook(queryMonitorTime);
    // ((GemFireCache)cache).testMaxQueryExecutionTime = queryMonitorTime;
    System.out.println("MAX_QUERY_EXECUTION_TIME is set to: " + ((GemFireCacheImpl) cache).testMaxQueryExecutionTime);
    return port;
}
Also used : GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache)

Example 4 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class QueryMonitorDUnitTest method validateQueryMonitorThreadCnt.

private void validateQueryMonitorThreadCnt(VM vm, final int threadCount, final int waitTime) {
    SerializableRunnable validateThreadCnt = new CacheSerializableRunnable("validateQueryMonitorThreadCnt") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            QueryMonitor qm = ((GemFireCacheImpl) cache).getQueryMonitor();
            if (qm == null) {
                fail("Didn't found query monitor.");
            }
            int waited = 0;
            while (true) {
                if (qm.getQueryMonitorThreadCount() != threadCount) {
                    if (waited <= waitTime) {
                        Wait.pause(10);
                        waited += 10;
                        continue;
                    } else {
                        fail("Didn't found expected monitoring thread. Expected: " + threadCount + " found :" + qm.getQueryMonitorThreadCount());
                    }
                }
                break;
            }
        // ((GemFireCache)cache).testMaxQueryExecutionTime = queryMonitorTime;
        }
    };
    vm.invoke(validateThreadCnt);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryMonitor(org.apache.geode.cache.query.internal.QueryMonitor) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache)

Example 5 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class QueryMonitorDUnitTest method stopServer.

// Stop server
private void stopServer(VM server) {
    SerializableRunnable stopServer = new SerializableRunnable("Stop CacheServer") {

        public void run() {
            // Reset the test flag.
            Cache cache = getCache();
            DefaultQuery.testHook = null;
            GemFireCacheImpl.getInstance().testMaxQueryExecutionTime = -1;
            stopBridgeServer(getCache());
            System.out.println("MAX_QUERY_EXECUTION_TIME is set to: " + ((GemFireCacheImpl) cache).testMaxQueryExecutionTime);
        }
    };
    server.invoke(stopServer);
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache)

Aggregations

GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)213 Test (org.junit.Test)127 Region (org.apache.geode.cache.Region)86 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 LocalRegion (org.apache.geode.internal.cache.LocalRegion)54 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)51 VM (org.apache.geode.test.dunit.VM)49 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)47 Host (org.apache.geode.test.dunit.Host)42 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)40 RegionAttributes (org.apache.geode.cache.RegionAttributes)39 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)35 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)33 CacheException (org.apache.geode.cache.CacheException)32 RegionCreation (org.apache.geode.internal.cache.xmlcache.RegionCreation)32 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)31 Properties (java.util.Properties)24 AttributesFactory (org.apache.geode.cache.AttributesFactory)24 Cache (org.apache.geode.cache.Cache)23 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)23