Search in sources :

Example 41 with CacheSerializableRunnable

use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.

the class QueryMonitorDUnitTest method testQueryMonitorRegionWithEviction.

/**
   * Tests query execution from client to server (multiple server) with eviction to disk.
   */
@Ignore("TODO:BUG46770WORKAROUND: test is disabled")
@Test
public void testQueryMonitorRegionWithEviction() throws CacheException {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM client1 = host.getVM(2);
    VM client2 = host.getVM(3);
    final int numberOfEntries = 100;
    String serverHostName = NetworkUtils.getServerHostName(host);
    // Start server
    int serverPort1 = server1.invoke("Create BridgeServer", // All the queries taking more
    () -> configServer(20, "testQueryMonitorRegionWithEviction"));
    // than 20ms should be
    // canceled by Query monitor.
    server1.invoke("createRegion", () -> createRegion(true, "server1_testQueryMonitorRegionWithEviction"));
    int serverPort2 = server2.invoke("Create BridgeServer", // All the queries taking more
    () -> configServer(20, "testQueryMonitorRegionWithEviction"));
    // than 20ms should be
    // canceled by Query monitor.
    server2.invoke("createRegion", () -> createRegion(true, "server2_testQueryMonitorRegionWithEviction"));
    // Initialize server regions.
    server1.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            bulkInsertPorfolio(101, numberOfEntries);
        }
    });
    // Initialize server regions.
    server2.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            bulkInsertPorfolio((numberOfEntries + 100), (numberOfEntries + numberOfEntries + 100));
        }
    });
    // Initialize Client1 and create client regions.
    client1.invoke("Init client", () -> configClient(serverHostName, serverPort1));
    client1.invoke("createRegion", () -> createRegion());
    // Initialize Client2 and create client regions.
    client2.invoke("Init client", () -> configClient(serverHostName, serverPort2));
    client2.invoke("createRegion", () -> createRegion());
    // Execute client queries
    client1.invoke("Execute Queries", () -> executeQueriesFromClient(20));
    client2.invoke("Execute Queries", () -> executeQueriesFromClient(20));
    stopServer(server1);
    stopServer(server2);
}
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) Ignore(org.junit.Ignore) 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)

Example 42 with CacheSerializableRunnable

use of org.apache.geode.cache30.CacheSerializableRunnable 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 43 with CacheSerializableRunnable

use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.

the class QueryIndexUpdateRIDUnitTest method getSRClearRegion.

private SerializableRunnable getSRClearRegion(final String regionName) {
    SerializableRunnable sr = new CacheSerializableRunnable("Destroy entries") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Clearing Region. ###");
            Region region1;
            if (!"root".equals(regionName)) {
                region1 = getRootRegion().getSubregion(regionName);
            } else {
                region1 = getRootRegion();
            }
            region1.clear();
            LogWriterUtils.getLogWriter().info("### Number of Entries in Region :" + region1.keySet().size());
        }
    };
    return sr;
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Region(org.apache.geode.cache.Region)

Example 44 with CacheSerializableRunnable

use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.

the class QueryIndexUpdateRIDUnitTest method getSRRegisterInterestList.

private SerializableRunnable getSRRegisterInterestList(final String regionName, final int keySize, final int policy, final int start) {
    SerializableRunnable sr = new CacheSerializableRunnable("Register InterestList") {

        public void run2() throws CacheException {
            // Get Query Service.
            Region region = null;
            try {
                if ("root".equals(regionName)) {
                    region = getRootRegion();
                } else {
                    region = getRootRegion().getSubregion(regionName);
                }
                region.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
            } catch (Exception cqe) {
                AssertionError err = new AssertionError("Failed to get Region.");
                err.initCause(cqe);
                throw err;
            }
            try {
                switch(policy) {
                    case REGEX:
                        region.registerInterestRegex(REGULAR_EXPRESSION);
                        break;
                    case KEYS:
                        List list = new ArrayList();
                        for (int i = start != 0 ? start : 1; i <= keySize; i++) {
                            list.add(KEY + i);
                        }
                        region.registerInterest(list);
                        break;
                    default:
                        region.registerInterest("ALL_KEYS");
                }
            } catch (Exception ex) {
                AssertionError err = new AssertionError("Failed to Register InterestList");
                err.initCause(ex);
                throw err;
            }
        }
    };
    return sr;
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CertifiableTestCacheListener(org.apache.geode.cache30.CertifiableTestCacheListener) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) ArrayList(java.util.ArrayList) Region(org.apache.geode.cache.Region) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 45 with CacheSerializableRunnable

use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.

the class QueryIndexUpdateRIDUnitTest method createClient.

/* Create Client */
public void createClient(VM client, final int[] serverPorts, final String serverHost, final String redundancyLevel, final String poolName) {
    SerializableRunnable createQService = new CacheSerializableRunnable("Create Client") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create Client. ###");
            // Initialize CQ Service.
            try {
                getCache().getQueryService();
            } catch (Exception cqe) {
                Assert.fail("Failed to getCQService.", cqe);
            }
            AttributesFactory regionFactory = new AttributesFactory();
            regionFactory.setScope(Scope.LOCAL);
            if (poolName != null) {
                regionFactory.setPoolName(poolName);
            } else {
                if (redundancyLevel != null) {
                    ClientServerTestCase.configureConnectionPool(regionFactory, serverHost, serverPorts, true, Integer.parseInt(redundancyLevel), -1, null);
                } else {
                    ClientServerTestCase.configureConnectionPool(regionFactory, serverHost, serverPorts, true, -1, -1, null);
                }
            }
            createRootRegion(regionFactory.createRegionAttributes());
            LogWriterUtils.getLogWriter().info("### Successfully Created Root Region on Client");
        }
    };
    client.invoke(createQService);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Aggregations

CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)595 CacheException (org.apache.geode.cache.CacheException)415 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)369 Test (org.junit.Test)369 Region (org.apache.geode.cache.Region)307 VM (org.apache.geode.test.dunit.VM)279 Host (org.apache.geode.test.dunit.Host)274 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)179 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)165 AttributesFactory (org.apache.geode.cache.AttributesFactory)145 IOException (java.io.IOException)135 Cache (org.apache.geode.cache.Cache)124 QueryService (org.apache.geode.cache.query.QueryService)118 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)107 LocalRegion (org.apache.geode.internal.cache.LocalRegion)106 SelectResults (org.apache.geode.cache.query.SelectResults)85 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)75 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)71 IgnoredException (org.apache.geode.test.dunit.IgnoredException)65 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)61