Search in sources :

Example 66 with CacheSerializableRunnable

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

the class CqDataUsingPoolDUnitTest method testGetDurableCQsFromServerWithEmptyList.

@Test
public void testGetDurableCQsFromServerWithEmptyList() throws Exception {
    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client1 = host.getVM(1);
    /* Create Server and Client */
    cqDUnitTest.createServer(server);
    final int port = server.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    final String poolName1 = "pool1";
    cqDUnitTest.createPool(client1, poolName1, host0, port);
    client1.invoke(new CacheSerializableRunnable("test getDurableCQsFromServer for client1") {

        @Override
        public void run2() throws CacheException {
            QueryService queryService = null;
            try {
                queryService = (PoolManager.find(poolName1)).getQueryService();
            } catch (Exception cqe) {
                Assert.fail("Failed to getCQService.", cqe);
            }
            List<String> list = null;
            try {
                list = queryService.getAllDurableCqsFromServer();
            } catch (CqException e) {
                fail("failed", e);
            }
            assertEquals(0, list.size());
            assertFalse(list.contains("client1DCQ1"));
            assertFalse(list.contains("client1DCQ2"));
        }
    });
    cqDUnitTest.closeClient(client1);
    cqDUnitTest.closeServer(server);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) QueryService(org.apache.geode.cache.query.QueryService) CqException(org.apache.geode.cache.query.CqException) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) List(java.util.List) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CacheException(org.apache.geode.cache.CacheException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 67 with CacheSerializableRunnable

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

the class CqDataUsingPoolDUnitTest method cycleDurableClient.

private void cycleDurableClient(VM client, final String dcName, final int serverPort, final String regionName, final int durableClientTimeout) {
    client.invoke(new CacheSerializableRunnable("cycle client") {

        @Override
        public void run2() throws CacheException {
            CacheServerTestUtil.closeCache(true);
        }
    });
    client.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client.getHost()), serverPort), regionName, getDurableClientProperties(dcName, durableClientTimeout)));
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException)

Example 68 with CacheSerializableRunnable

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

the class CqDataUsingPoolDUnitTest method testGetDurableCqsFromServer.

@Test
public void testGetDurableCqsFromServer() {
    disconnectAllFromDS();
    final String regionName = "testGetAllDurableCqsFromServer";
    final String cq1Name = "testCq1";
    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client1 = host.getVM(1);
    VM client2 = host.getVM(2);
    // Start server 1
    final int server1Port = ((Integer) server.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
    // Start client 1
    client1.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client1.getHost()), server1Port), regionName));
    // Start client 2
    client2.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client2.getHost()), server1Port), regionName));
    createClient1CqsAndDurableCqs(client1, regionName);
    createClient2CqsAndDurableCqs(client2, regionName);
    client2.invoke(new CacheSerializableRunnable("check durable cqs for client 2") {

        @Override
        public void run2() throws CacheException {
            QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
            List<String> list = null;
            try {
                list = queryService.getAllDurableCqsFromServer();
            } catch (CqException e) {
                fail("failed", e);
            }
            assertEquals(4, list.size());
            assertTrue(list.contains("client2DCQ1"));
            assertTrue(list.contains("client2DCQ2"));
            assertTrue(list.contains("client2DCQ3"));
            assertTrue(list.contains("client2DCQ4"));
        }
    });
    client1.invoke(new CacheSerializableRunnable("check durable cqs for client 1") {

        @Override
        public void run2() throws CacheException {
            QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
            List<String> list = null;
            try {
                list = queryService.getAllDurableCqsFromServer();
            } catch (CqException e) {
                fail("failed", e);
            }
            assertEquals(2, list.size());
            assertTrue(list.contains("client1DCQ1"));
            assertTrue(list.contains("client1DCQ2"));
        }
    });
    client1.invoke(() -> CacheServerTestUtil.closeCache());
    client2.invoke(() -> CacheServerTestUtil.closeCache());
    server.invoke(() -> CacheServerTestUtil.closeCache());
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) QueryService(org.apache.geode.cache.query.QueryService) CqException(org.apache.geode.cache.query.CqException) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) List(java.util.List) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 69 with CacheSerializableRunnable

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

the class CqPerfDUnitTest method validateMatchingCqs.

public void validateMatchingCqs(VM server, final int mapSize, final String query, final int numCqSize) {
    server.invoke(new CacheSerializableRunnable("validateMatchingCqs") {

        public void run2() throws CacheException {
            CqServiceImpl cqService = null;
            try {
                cqService = (CqServiceImpl) ((DefaultQueryService) getCache().getQueryService()).getCqService();
            } catch (Exception ex) {
                LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
                Assert.fail("Failed to get the internal CqService.", ex);
            }
            Map matchedCqMap = cqService.getMatchingCqMap();
            assertEquals("The number of matched cq is not as expected.", mapSize, matchedCqMap.size());
            if (query != null) {
                if (!matchedCqMap.containsKey(query)) {
                    fail("Query not found in the matched cq map. Query:" + query);
                }
                Collection cqs = (Collection) matchedCqMap.get(query);
                assertEquals("Number of matched cqs are not equal to the expected matched cqs", numCqSize, cqs.size());
            }
        }
    });
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) CacheException(org.apache.geode.cache.CacheException) CqServiceImpl(org.apache.geode.cache.query.internal.cq.CqServiceImpl)

Example 70 with CacheSerializableRunnable

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

the class CqPerfDUnitTest method testKeyMaintainance.

/**
   * Test for maintaining keys for update optimization.
   * 
   * @throws Exception
   */
@Test
public void testKeyMaintainance() throws Exception {
    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client = host.getVM(1);
    cqDUnitTest.createServer(server);
    final int port = server.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    cqDUnitTest.createClient(client, port, host0);
    // HashSet for caching purpose will be created for cqs.
    final int cqSize = 2;
    // Cq1
    cqDUnitTest.createCQ(client, "testKeyMaintainance_0", cqDUnitTest.cqs[0]);
    cqDUnitTest.executeCQ(client, "testKeyMaintainance_0", false, null);
    // Cq2
    cqDUnitTest.createCQ(client, "testKeyMaintainance_1", cqDUnitTest.cqs[10]);
    cqDUnitTest.executeCQ(client, "testKeyMaintainance_1", false, null);
    cqDUnitTest.createValues(server, cqDUnitTest.regions[0], 1);
    cqDUnitTest.waitForCreated(client, "testKeyMaintainance_0", CqQueryDUnitTest.KEY + 1);
    // Entry is made into the CQs cache hashset.
    // testKeyMaintainance_0 with 1 entry and testKeyMaintainance_1 with 0
    server.invoke(new CacheSerializableRunnable("LookForCachedEventKeys1") {

        public void run2() throws CacheException {
            CqService cqService = null;
            try {
                cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
            } catch (Exception ex) {
                LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
                Assert.fail("Failed to get the internal CqService.", ex);
            }
            Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
            for (InternalCqQuery cq : cqs) {
                ServerCQImpl cqQuery = (ServerCQImpl) cq;
                String serverCqName = (String) cqQuery.getServerCqName();
                if (serverCqName.startsWith("testKeyMaintainance_0")) {
                    assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 1, cqQuery.getCqResultKeysSize());
                } else if (serverCqName.startsWith("testKeyMaintainance_1")) {
                    assertEquals("The number of keys cached for cq testKeyMaintainance_1 is wrong.", 0, cqQuery.getCqResultKeysSize());
                }
            }
        }
    });
    // Update 1.
    cqDUnitTest.createValues(server, cqDUnitTest.regions[0], 10);
    cqDUnitTest.waitForCreated(client, "testKeyMaintainance_0", CqQueryDUnitTest.KEY + 10);
    // Entry/check is made into the CQs cache hashset.
    // testKeyMaintainance_0 with 1 entry and testKeyMaintainance_1 with 1
    server.invoke(new CacheSerializableRunnable("LookForCachedEventKeysAfterUpdate1") {

        public void run2() throws CacheException {
            CqService cqService = null;
            try {
                cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
            } catch (Exception ex) {
                LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
                Assert.fail("Failed to get the internal CqService.", ex);
            }
            Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
            for (InternalCqQuery cq : cqs) {
                ServerCQImpl cqQuery = (ServerCQImpl) cq;
                String serverCqName = (String) cqQuery.getServerCqName();
                if (serverCqName.startsWith("testKeyMaintainance_0")) {
                    assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 10, cqQuery.getCqResultKeysSize());
                } else if (serverCqName.startsWith("testKeyMaintainance_1")) {
                    assertEquals("The number of keys cached for cq testKeyMaintainance_1 is wrong.", 5, cqQuery.getCqResultKeysSize());
                }
            }
        }
    });
    // Update.
    cqDUnitTest.createValues(server, cqDUnitTest.regions[0], 12);
    cqDUnitTest.waitForCreated(client, "testKeyMaintainance_0", CqQueryDUnitTest.KEY + 12);
    // Entry/check is made into the CQs cache hashset.
    // testKeyMaintainance_0 with 1 entry and testKeyMaintainance_1 with 1
    server.invoke(new CacheSerializableRunnable("LookForCachedEventKeysAfterUpdate2") {

        public void run2() throws CacheException {
            CqService cqService = null;
            try {
                cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
            } catch (Exception ex) {
                LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
                Assert.fail("Failed to get the internal CqService.", ex);
            }
            Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
            for (InternalCqQuery cq : cqs) {
                ServerCQImpl cqQuery = (ServerCQImpl) cq;
                String serverCqName = (String) cqQuery.getServerCqName();
                if (serverCqName.startsWith("testKeyMaintainance_0")) {
                    assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 12, cqQuery.getCqResultKeysSize());
                } else if (serverCqName.startsWith("testKeyMaintainance_1")) {
                    assertEquals("The number of keys cached for cq testKeyMaintainance_1 is wrong.", 6, cqQuery.getCqResultKeysSize());
                }
            }
        }
    });
    // Delete.
    cqDUnitTest.deleteValues(server, cqDUnitTest.regions[0], 6);
    cqDUnitTest.waitForDestroyed(client, "testKeyMaintainance_0", CqQueryDUnitTest.KEY + 6);
    // Entry/check is made into the CQs cache hashset.
    // testKeyMaintainance_0 with 1 entry and testKeyMaintainance_1 with 1
    server.invoke(new CacheSerializableRunnable("LookForCachedEventKeysAfterUpdate2") {

        public void run2() throws CacheException {
            CqService cqService = null;
            try {
                cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
            } catch (Exception ex) {
                LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
                Assert.fail("Failed to get the internal CqService.", ex);
            }
            Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
            for (InternalCqQuery cq : cqs) {
                ServerCQImpl cqQuery = (ServerCQImpl) cq;
                String serverCqName = (String) cqQuery.getServerCqName();
                if (serverCqName.startsWith("testKeyMaintainance_0")) {
                    assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 6, cqQuery.getCqResultKeysSize());
                } else if (serverCqName.startsWith("testKeyMaintainance_1")) {
                    assertEquals("The number of keys cached for cq testKeyMaintainance_1 is wrong.", 3, cqQuery.getCqResultKeysSize());
                }
            }
        }
    });
    // Stop CQ.
    // This should still needs to process the events so that Results are up-to-date.
    cqDUnitTest.stopCQ(client, "testKeyMaintainance_1");
    cqDUnitTest.createValues(server, cqDUnitTest.regions[0], 12);
    server.invoke(new CacheSerializableRunnable("LookForCachedEventKeysAfterUpdate2") {

        public void run2() throws CacheException {
            CqService cqService = null;
            try {
                cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
            } catch (Exception ex) {
                LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
                Assert.fail("Failed to get the internal CqService.", ex);
            }
            Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
            for (InternalCqQuery cq : cqs) {
                ServerCQImpl cqQuery = (ServerCQImpl) cq;
                String serverCqName = (String) cqQuery.getServerCqName();
                if (serverCqName.startsWith("testKeyMaintainance_0")) {
                    assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 12, cqQuery.getCqResultKeysSize());
                } else if (serverCqName.startsWith("testKeyMaintainance_1")) {
                    assertEquals("The number of keys cached for cq testKeyMaintainance_1 is wrong.", 6, cqQuery.getCqResultKeysSize());
                }
            }
        }
    });
    // re-start the CQ.
    cqDUnitTest.executeCQ(client, "testKeyMaintainance_1", false, null);
    // This will remove the caching for this CQ.
    cqDUnitTest.closeCQ(client, "testKeyMaintainance_1");
    server.invoke(new CacheSerializableRunnable("LookForCachedEventKeysAfterUpdate2") {

        public void run2() throws CacheException {
            CqService cqService = null;
            try {
                cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
            } catch (Exception ex) {
                LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
                Assert.fail("Failed to get the internal CqService.", ex);
            }
            Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
            for (InternalCqQuery cq : cqs) {
                ServerCQImpl cqQuery = (ServerCQImpl) cq;
                String serverCqName = (String) cqQuery.getServerCqName();
                if (serverCqName.startsWith("testKeyMaintainance_0")) {
                    assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 12, cqQuery.getCqResultKeysSize());
                } else if (serverCqName.startsWith("testKeyMaintainance_1")) {
                    fail("The key maintainance should not be present for this CQ.");
                }
            }
        }
    });
    // Close.
    cqDUnitTest.closeClient(client);
    cqDUnitTest.closeServer(server);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) Collection(java.util.Collection) Host(org.apache.geode.test.dunit.Host) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqService(org.apache.geode.cache.query.internal.cq.CqService) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) ServerCQImpl(org.apache.geode.cache.query.internal.cq.ServerCQImpl) CacheException(org.apache.geode.cache.CacheException) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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