Search in sources :

Example 1 with CqStatistics

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

the class CqStatsDUnitTest method validateCQStats.

public 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 = 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 != CqQueryDUnitTest.noTest) {
                // Result size validation.
                assertEquals("Total Event Count mismatch", totalEvents, cqStats.numEvents());
            }
            // Check for create count.
            if (creates != CqQueryDUnitTest.noTest) {
                assertEquals("Create Event mismatch", creates, cqStats.numInserts());
            }
            // Check for update count.
            if (updates != CqQueryDUnitTest.noTest) {
                assertEquals("Update Event mismatch", updates, cqStats.numUpdates());
            }
            // Check for delete count.
            if (deletes != CqQueryDUnitTest.noTest) {
                assertEquals("Delete Event mismatch", deletes, cqStats.numDeletes());
            }
            // Check for CQ listener invocations.
            if (cqListenerInvocations != CqQueryDUnitTest.noTest) {
                assertEquals("CQ Listener invocations mismatch", cqListenerInvocations, cqVsdStats.getNumCqListenerInvocations());
            }
        //// Check for initial results time.
        // if (initialResultsTime != CqQueryDUnitTest.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)

Example 2 with CqStatistics

use of org.apache.geode.cache.query.CqStatistics 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

Collection (java.util.Collection)2 CacheException (org.apache.geode.cache.CacheException)2 CqException (org.apache.geode.cache.query.CqException)2 CqStatistics (org.apache.geode.cache.query.CqStatistics)2 QueryService (org.apache.geode.cache.query.QueryService)2 CqQueryVsdStats (org.apache.geode.cache.query.internal.CqQueryVsdStats)2 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)2 CqQueryImpl (org.apache.geode.cache.query.internal.cq.CqQueryImpl)2 CqService (org.apache.geode.cache.query.internal.cq.CqService)2 InternalCqQuery (org.apache.geode.cache.query.internal.cq.InternalCqQuery)2 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)2