Search in sources :

Example 21 with DefaultQueryService

use of org.apache.geode.cache.query.internal.DefaultQueryService in project geode by apache.

the class CqStatsDUnitTest method validateCQServiceStats.

private void validateCQServiceStats(VM vm, final int created, final int activated, final int stopped, final int closed, final int cqsOnClient, final int cqsOnRegion, final int clientsWithCqs) {
    vm.invoke(new CacheSerializableRunnable("Validate CQ Service Stats") {

        @Override
        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Validating CQ Service Stats. ### ");
            // Get CQ Service.
            QueryService qService = null;
            try {
                qService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            CqServiceStatistics cqServiceStats = null;
            cqServiceStats = qService.getCqStatistics();
            CqServiceVsdStats cqServiceVsdStats = null;
            try {
                cqServiceVsdStats = ((CqServiceImpl) ((DefaultQueryService) qService).getCqService()).stats();
            } catch (CqException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (cqServiceStats == null) {
                fail("Failed to get CQ Service Stats");
            }
            getCache().getLogger().info("#### CQ Service stats: " + " CQs created: " + cqServiceStats.numCqsCreated() + " CQs active: " + cqServiceStats.numCqsActive() + " CQs stopped: " + cqServiceStats.numCqsStopped() + " CQs closed: " + cqServiceStats.numCqsClosed() + " CQs on Client: " + cqServiceStats.numCqsOnClient() + " CQs on region /root/regionA : " + cqServiceVsdStats.numCqsOnRegion(GemFireCacheImpl.getInstance(), "/root/regionA") + " Clients with CQs: " + cqServiceVsdStats.getNumClientsWithCqs());
            // Check for created count.
            if (created != CqQueryDUnitTest.noTest) {
                assertEquals("Number of CQs created mismatch", created, cqServiceStats.numCqsCreated());
            }
            // Check for activated count.
            if (activated != CqQueryDUnitTest.noTest) {
                assertEquals("Number of CQs activated mismatch", activated, cqServiceStats.numCqsActive());
            }
            // Check for stopped count.
            if (stopped != CqQueryDUnitTest.noTest) {
                assertEquals("Number of CQs stopped mismatch", stopped, cqServiceStats.numCqsStopped());
            }
            // Check for closed count.
            if (closed != CqQueryDUnitTest.noTest) {
                assertEquals("Number of CQs closed mismatch", closed, cqServiceStats.numCqsClosed());
            }
            // Check for CQs on client count.
            if (cqsOnClient != CqQueryDUnitTest.noTest) {
                assertEquals("Number of CQs on client mismatch", cqsOnClient, cqServiceStats.numCqsOnClient());
            }
            // Check for CQs on region.
            if (cqsOnRegion != CqQueryDUnitTest.noTest) {
                assertEquals("Number of CQs on region /root/regionA mismatch", cqsOnRegion, cqServiceVsdStats.numCqsOnRegion(GemFireCacheImpl.getInstance(), "/root/regionA"));
            }
            // Check for clients with CQs count.
            if (clientsWithCqs != CqQueryDUnitTest.noTest) {
                assertEquals("Clints with CQs mismatch", clientsWithCqs, cqServiceVsdStats.getNumClientsWithCqs());
            }
        }
    });
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) CqServiceVsdStats(org.apache.geode.cache.query.internal.cq.CqServiceVsdStats) CqException(org.apache.geode.cache.query.CqException) CqException(org.apache.geode.cache.query.CqException) CacheException(org.apache.geode.cache.CacheException) CqServiceStatistics(org.apache.geode.cache.query.CqServiceStatistics) CqServiceImpl(org.apache.geode.cache.query.internal.cq.CqServiceImpl)

Example 22 with DefaultQueryService

use of org.apache.geode.cache.query.internal.DefaultQueryService in project geode by apache.

the class CqStatsUsingPoolDUnitTest method validateCQStats.

private void validateCQStats(VM vm, final String cqName, final int creates, final int updates, final int deletes, final int totalEvents, final int cqListenerInvocations) {
    vm.invoke(new CacheSerializableRunnable("Validate CQs") {

        @Override
        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Validating CQ Stats. ### " + cqName);
            // Get CQ Service.
            QueryService qService = null;
            try {
                qService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to get query service.");
            }
            CqService cqService = null;
            try {
                cqService = ((DefaultQueryService) qService).getCqService();
            } catch (CqException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                fail("Failed to get CqService, CQ : " + cqName);
            }
            Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
            if (cqs.size() == 0) {
                fail("Failed to get CqQuery for CQ : " + cqName);
            }
            CqQueryImpl cQuery = (CqQueryImpl) cqs.iterator().next();
            CqStatistics cqStats = cQuery.getStatistics();
            CqQueryVsdStats cqVsdStats = ((CqQueryImpl) cQuery).getVsdStats();
            if (cqStats == null || cqVsdStats == null) {
                fail("Failed to get CqQuery Stats for CQ : " + cqName);
            }
            getCache().getLogger().info("#### CQ stats for " + cQuery.getName() + ": " + " Events Total: " + cqStats.numEvents() + " Events Created: " + cqStats.numInserts() + " Events Updated: " + cqStats.numUpdates() + " Events Deleted: " + cqStats.numDeletes() + " CQ Listener invocations: " + cqVsdStats.getNumCqListenerInvocations() + " Initial results time (nano sec): " + cqVsdStats.getCqInitialResultsTime());
            // Check for totalEvents count.
            if (totalEvents != CqQueryUsingPoolDUnitTest.noTest) {
                // Result size validation.
                assertEquals("Total Event Count mismatch", totalEvents, cqStats.numEvents());
            }
            // Check for create count.
            if (creates != CqQueryUsingPoolDUnitTest.noTest) {
                assertEquals("Create Event mismatch", creates, cqStats.numInserts());
            }
            // Check for update count.
            if (updates != CqQueryUsingPoolDUnitTest.noTest) {
                assertEquals("Update Event mismatch", updates, cqStats.numUpdates());
            }
            // Check for delete count.
            if (deletes != CqQueryUsingPoolDUnitTest.noTest) {
                assertEquals("Delete Event mismatch", deletes, cqStats.numDeletes());
            }
            // Check for CQ listener invocations.
            if (cqListenerInvocations != CqQueryUsingPoolDUnitTest.noTest) {
                assertEquals("CQ Listener invocations mismatch", cqListenerInvocations, cqVsdStats.getNumCqListenerInvocations());
            }
        //// Check for initial results time.
        // if (initialResultsTime != CqQueryUsingPoolDUnitTest.noTest &&
        //// cqVsdStats.getCqInitialResultsTime() <= 0) {
        // assertIndexDetailsEquals("Initial results time mismatch", initialResultsTime,
        //// cqVsdStats.getCqInitialResultsTime());
        // }
        }
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) CqException(org.apache.geode.cache.query.CqException) CqService(org.apache.geode.cache.query.internal.cq.CqService) CqException(org.apache.geode.cache.query.CqException) CacheException(org.apache.geode.cache.CacheException) CqStatistics(org.apache.geode.cache.query.CqStatistics) CqQueryVsdStats(org.apache.geode.cache.query.internal.CqQueryVsdStats) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) Collection(java.util.Collection) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqQueryImpl(org.apache.geode.cache.query.internal.cq.CqQueryImpl) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService)

Aggregations

DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)22 CacheException (org.apache.geode.cache.CacheException)15 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)14 CqService (org.apache.geode.cache.query.internal.cq.CqService)11 Collection (java.util.Collection)10 InternalCqQuery (org.apache.geode.cache.query.internal.cq.InternalCqQuery)9 Test (org.junit.Test)9 CqException (org.apache.geode.cache.query.CqException)8 ServerCQImpl (org.apache.geode.cache.query.internal.cq.ServerCQImpl)8 Host (org.apache.geode.test.dunit.Host)8 VM (org.apache.geode.test.dunit.VM)8 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 IOException (java.io.IOException)7 Portfolio (org.apache.geode.cache.query.data.Portfolio)6 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 Set (java.util.Set)5 Region (org.apache.geode.cache.Region)5 QueryService (org.apache.geode.cache.query.QueryService)5 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)3