Search in sources :

Example 21 with CqService

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

the class CacheServerManagementDUnitTest method verifyClosedCQ.

/**
   * Verify the closed CQ which is closed from Managing Node
   *
   * @param vm
   */
@SuppressWarnings("serial")
protected void verifyClosedCQ(final VM vm) throws Exception {
    SerializableRunnable verifyClosedCQ = new SerializableRunnable("Verify Closed CQ") {

        public void run() {
            CqService cqService = GemFireCacheImpl.getInstance().getCqService();
            if (cqService != null) {
                assertNull(cqService.getCq(queryName));
            }
        }
    };
    vm.invoke(verifyClosedCQ);
}
Also used : CqService(org.apache.geode.cache.query.internal.cq.CqService)

Example 22 with CqService

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

the class CqResultSetUsingPoolDUnitTest method testCqResultsCaching.

/**
   * Tests CQ Result Set.
   * 
   * @throws Exception
   */
@Test
public void testCqResultsCaching() 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(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    String poolName = "testCqResults";
    final String cqName = "testCqResultsP_0";
    cqDUnitTest.createPool(client, poolName, host0, port);
    // Create client.
    cqDUnitTest.createClient(client, port, host0);
    // create CQ.
    cqDUnitTest.createCQ(client, poolName, cqName, cqDUnitTest.cqs[0]);
    final int numObjects = 300;
    final int totalObjects = 500;
    // initialize Region.
    server.invoke(new CacheSerializableRunnable("Update Region") {

        public void run2() throws CacheException {
            Region region = getCache().getRegion("/root/" + cqDUnitTest.regions[0]);
            for (int i = 1; i <= numObjects; i++) {
                Portfolio p = new Portfolio(i);
                region.put("" + i, p);
            }
        }
    });
    // Keep updating region (async invocation).
    server.invokeAsync(new CacheSerializableRunnable("Update Region") {

        public void run2() throws CacheException {
            Region region = getCache().getRegion("/root/" + cqDUnitTest.regions[0]);
            // Update (totalObjects - 1) entries.
            for (int i = 1; i < totalObjects; i++) {
                // Destroy entries.
                if (i > 25 && i < 201) {
                    region.destroy("" + i);
                    continue;
                }
                Portfolio p = new Portfolio(i);
                region.put("" + i, p);
            }
            // recreate destroyed entries.
            for (int j = 26; j < 201; j++) {
                Portfolio p = new Portfolio(j);
                region.put("" + j, p);
            }
            // Add the last key.
            Portfolio p = new Portfolio(totalObjects);
            region.put("" + totalObjects, p);
        }
    });
    // Execute CQ.
    // While region operation is in progress execute CQ.
    cqDUnitTest.executeCQ(client, cqName, true, null);
    // Verify CQ Cache results.
    server.invoke(new CacheSerializableRunnable("Verify CQ Cache results") {

        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);
            }
            // Wait till all the region update is performed.
            Region region = getCache().getRegion("/root/" + cqDUnitTest.regions[0]);
            while (true) {
                if (region.get("" + totalObjects) == null) {
                    try {
                        Thread.sleep(50);
                    } catch (Exception ex) {
                    // ignore.
                    }
                    continue;
                }
                break;
            }
            Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
            for (InternalCqQuery cq : cqs) {
                ServerCQImpl cqQuery = (ServerCQImpl) cq;
                if (cqQuery.getName().equals(cqName)) {
                    int size = cqQuery.getCqResultKeysSize();
                    if (size != totalObjects) {
                        LogWriterUtils.getLogWriter().info("The number of Cached events " + size + " is not equal to the expected size " + totalObjects);
                        HashSet expectedKeys = new HashSet();
                        for (int i = 1; i < totalObjects; i++) {
                            expectedKeys.add("" + i);
                        }
                        Set cachedKeys = cqQuery.getCqResultKeyCache();
                        expectedKeys.removeAll(cachedKeys);
                        LogWriterUtils.getLogWriter().info("Missing keys from the Cache : " + expectedKeys);
                    }
                    assertEquals("The number of keys cached for cq " + cqName + " is wrong.", totalObjects, cqQuery.getCqResultKeysSize());
                }
            }
        }
    });
    // Close.
    cqDUnitTest.closeClient(client);
    cqDUnitTest.closeServer(server);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) CacheException(org.apache.geode.cache.CacheException) Portfolio(org.apache.geode.cache.query.data.Portfolio) Host(org.apache.geode.test.dunit.Host) CqService(org.apache.geode.cache.query.internal.cq.CqService) ServerCQImpl(org.apache.geode.cache.query.internal.cq.ServerCQImpl) CacheException(org.apache.geode.cache.CacheException) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Collection(java.util.Collection) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) HashSet(java.util.HashSet) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 23 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService 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)

Example 24 with CqService

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

the class DefaultQueryService method getCqService.

/**
   * @return CqService
   */
public CqService getCqService() throws CqException {
    CqService service = cache.getCqService();
    service.start();
    return service;
}
Also used : CqService(org.apache.geode.cache.query.internal.cq.CqService)

Example 25 with CqService

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

the class FilterProfile method getFilterRoutingInfoPart1.

/**
   * Compute the full routing information for the given set of peers. This will not include local
   * routing information from interest processing. That is done by getFilterRoutingInfoPart2
   */
public FilterRoutingInfo getFilterRoutingInfoPart1(CacheEvent event, Profile[] peerProfiles, Set cacheOpRecipients) {
    // early out if there are no cache servers in the system
    boolean anyServers = false;
    for (int i = 0; i < peerProfiles.length; i++) {
        if (((CacheProfile) peerProfiles[i]).hasCacheServer) {
            anyServers = true;
            break;
        }
    }
    if (!anyServers && !this.localProfile.hasCacheServer) {
        return null;
    }
    FilterRoutingInfo frInfo = null;
    CqService cqService = getCqService(event.getRegion());
    if (cqService.isRunning()) {
        frInfo = new FilterRoutingInfo();
        // bug #50809 - local routing for transactional ops must be done here
        // because the event isn't available later and we lose the old value for the entry
        final boolean processLocalProfile = event.getOperation().isEntry() && ((EntryEvent) event).getTransactionId() != null;
        fillInCQRoutingInfo(event, processLocalProfile, peerProfiles, frInfo);
    }
    // Process InterestList.
    // return fillInInterestRoutingInfo(event, peerProfiles, frInfo, cacheOpRecipients);
    frInfo = fillInInterestRoutingInfo(event, peerProfiles, frInfo, cacheOpRecipients);
    if (frInfo == null || !frInfo.hasMemberWithFilterInfo()) {
        return null;
    } else {
        return frInfo;
    }
}
Also used : CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile) EntryEvent(org.apache.geode.cache.EntryEvent) CqService(org.apache.geode.cache.query.internal.cq.CqService)

Aggregations

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