Search in sources :

Example 41 with CqQuery

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

the class CqQueryDUnitTest method waitForCqsConnected.

protected void waitForCqsConnected(VM vm, final String cqName, final int count) {
    vm.invoke(new CacheSerializableRunnable("validate cq connected count") {

        public void run2() throws CacheException {
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            CqQuery cQuery = cqService.getCq(cqName);
            if (cQuery == null) {
                fail("Failed to get CqQuery for CQ : " + cqName);
            }
            CqAttributes cqAttr = cQuery.getCqAttributes();
            CqListener[] cqListener = cqAttr.getCqListeners();
            CqQueryTestListener listener = (CqQueryTestListener) cqListener[0];
            listener.waitForCqsConnectedEvents(count);
        }
    });
}
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) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqQuery(org.apache.geode.cache.query.CqQuery) CqExistsException(org.apache.geode.cache.query.CqExistsException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 42 with CqQuery

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

the class CqQueryDUnitTest method stopCQ.

/* Stop/pause CQ */
public void stopCQ(VM vm, final String cqName) throws Exception {
    vm.invoke(new CacheSerializableRunnable("Stop CQ :" + cqName) {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Stop CQ. ###" + cqName);
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            // Stop CQ.
            CqQuery cq1 = null;
            try {
                cq1 = cqService.getCq(cqName);
                cq1.stop();
            } catch (Exception ex) {
                ex.printStackTrace();
                fail("Failed to stop CQ " + cqName + " . " + ex.getMessage());
            }
            assertTrue("Stop CQ state mismatch", cq1.getState().isStopped());
        }
    });
}
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) CqQuery(org.apache.geode.cache.query.CqQuery) CqExistsException(org.apache.geode.cache.query.CqExistsException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 43 with CqQuery

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

the class CqQueryDUnitTest method validateCQError.

private void validateCQError(VM vm, final String cqName, final int numError) {
    vm.invoke(new CacheSerializableRunnable("Validate CQs") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Validating CQ. ### " + cqName);
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            CqQuery cQuery = cqService.getCq(cqName);
            if (cQuery == null) {
                fail("Failed to get CqQuery for CQ : " + cqName);
            }
            CqAttributes cqAttr = cQuery.getCqAttributes();
            CqListener cqListener = cqAttr.getCqListener();
            CqQueryTestListener listener = (CqQueryTestListener) cqListener;
            listener.printInfo(false);
            // Check for totalEvents count.
            if (numError != noTest) {
                // Result size validation.
                listener.printInfo(true);
                assertEquals("Total Event Count mismatch", numError, listener.getErrorEventCount());
            }
        }
    });
}
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) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqListener(org.apache.geode.cache.query.CqListener) CqQuery(org.apache.geode.cache.query.CqQuery) CqExistsException(org.apache.geode.cache.query.CqExistsException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 44 with CqQuery

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

the class CqQueryDUnitTest method failIfCQExists.

/**
   * Throws AssertionError if the CQ can be found or if any other error occurs
   */
private void failIfCQExists(VM vm, final String cqName) {
    vm.invoke(new CacheSerializableRunnable("Fail if CQ exists") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Fail if CQ Exists. ### " + cqName);
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            CqQuery cQuery = cqService.getCq(cqName);
            if (cQuery != null) {
                fail("Unexpectedly found CqQuery for CQ : " + cqName);
            }
        }
    });
}
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) CqQuery(org.apache.geode.cache.query.CqQuery) CqExistsException(org.apache.geode.cache.query.CqExistsException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 45 with CqQuery

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

the class CqQueryDUnitTest method ensureCQExists.

private void ensureCQExists(VM server, final String regionName, final String cqName) {
    SerializableRunnable task = new CacheSerializableRunnable("check CQs") {

        public void run2() throws CacheException {
            CqQuery[] queries = getCache().getQueryService().getCqs();
            assertTrue("expected to find a CQ but found none", queries.length > 0);
            System.out.println("found query " + queries[0]);
            assertTrue("Couldn't find query " + cqName, queries[0].getName().startsWith(cqName));
            assertTrue("expected the CQ to be open: " + queries[0], !queries[0].isClosed());
        }
    };
    server.invoke(task);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CqQuery(org.apache.geode.cache.query.CqQuery)

Aggregations

CqQuery (org.apache.geode.cache.query.CqQuery)64 QueryService (org.apache.geode.cache.query.QueryService)49 CacheException (org.apache.geode.cache.CacheException)38 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)36 CqAttributes (org.apache.geode.cache.query.CqAttributes)35 CqAttributesFactory (org.apache.geode.cache.query.CqAttributesFactory)31 IOException (java.io.IOException)27 CqExistsException (org.apache.geode.cache.query.CqExistsException)26 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)24 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)22 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)21 Test (org.junit.Test)21 CqClosedException (org.apache.geode.cache.query.CqClosedException)20 Region (org.apache.geode.cache.Region)17 SelectResults (org.apache.geode.cache.query.SelectResults)17 Host (org.apache.geode.test.dunit.Host)14 VM (org.apache.geode.test.dunit.VM)14 CqListener (org.apache.geode.cache.query.CqListener)12 Struct (org.apache.geode.cache.query.Struct)11 CqEvent (org.apache.geode.cache.query.CqEvent)10