Search in sources :

Example 1 with CqQuery

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

the class CqQueryDUnitTest method validateCQ.

public void validateCQ(VM vm, final String cqName, final int resultSize, final int creates, final int updates, final int deletes, final int queryInserts, final int queryUpdates, final int queryDeletes, final int totalEvents) {
    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[] cqListeners = cqAttr.getCqListeners();
            CqQueryTestListener listener = (CqQueryTestListener) cqListeners[0];
            listener.printInfo(false);
            // Check for totalEvents count.
            if (totalEvents != noTest) {
                // Result size validation.
                listener.printInfo(true);
                assertEquals("Total Event Count mismatch", totalEvents, listener.getTotalEventCount());
            }
            if (resultSize != noTest) {
                // SelectResults results = cQuery.getCqResults();
                // getLogWriter().info("### CQ Result Size is :" + results.size());
                // Result size validation.
                // Since ResultSet is not maintained for this release.
                // Instead of resultSize its been validated with total number of events.
                fail("test for event counts instead of results size");
            // assertIndexDetailsEquals("Result Size mismatch", resultSize,
            // listener.getTotalEventCount());
            }
            // Check for create count.
            if (creates != noTest) {
                // Result size validation.
                listener.printInfo(true);
                assertEquals("Create Event mismatch", creates, listener.getCreateEventCount());
            }
            // Check for update count.
            if (updates != noTest) {
                // Result size validation.
                listener.printInfo(true);
                assertEquals("Update Event mismatch", updates, listener.getUpdateEventCount());
            }
            // Check for delete count.
            if (deletes != noTest) {
                // Result size validation.
                listener.printInfo(true);
                assertEquals("Delete Event mismatch", deletes, listener.getDeleteEventCount());
            }
            // Check for queryInsert count.
            if (queryInserts != noTest) {
                // Result size validation.
                listener.printInfo(true);
                assertEquals("Query Insert Event mismatch", queryInserts, listener.getQueryInsertEventCount());
            }
            // Check for queryUpdate count.
            if (queryUpdates != noTest) {
                // Result size validation.
                listener.printInfo(true);
                assertEquals("Query Update Event mismatch", queryUpdates, listener.getQueryUpdateEventCount());
            }
            // Check for queryDelete count.
            if (queryDeletes != noTest) {
                // Result size validation.
                listener.printInfo(true);
                assertEquals("Query Delete Event mismatch", queryDeletes, listener.getQueryDeleteEventCount());
            }
        }
    });
}
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 2 with CqQuery

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

the class CqQueryDUnitTest method waitForCqsDisconnected.

protected void waitForCqsDisconnected(VM vm, final String cqName, final int count) {
    vm.invoke(new CacheSerializableRunnable("validate cq disconnected 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.waitForCqsDisconnectedEvents(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 3 with CqQuery

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

the class CqQueryDUnitTest method closeCQ.

/* UnRegister CQs */
public void closeCQ(VM vm, final String cqName) throws Exception {
    vm.invoke(new CacheSerializableRunnable("Close CQ :" + cqName) {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Close CQ. ###" + cqName);
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCqService.");
            }
            // Close CQ.
            CqQuery cq1 = null;
            try {
                cq1 = cqService.getCq(cqName);
                cq1.close();
            } catch (Exception ex) {
                ex.printStackTrace();
                fail("Failed to close CQ " + cqName + " . " + ex.getMessage());
            }
            assertTrue("Close CQ state mismatch", cq1.getState().isClosed());
        }
    });
}
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 4 with CqQuery

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

the class CqQueryDUnitTest method waitForEvent.

private void waitForEvent(VM vm, final int event, final String cqName, final String key) {
    vm.invoke(new CacheSerializableRunnable("validate cq count") {

        public void run2() throws CacheException {
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                Assert.fail("Failed to getCQService.", cqe);
            }
            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];
            switch(event) {
                case CREATE:
                    listener.waitForCreated(key);
                    break;
                case UPDATE:
                    listener.waitForUpdated(key);
                    break;
                case DESTROY:
                    listener.waitForDestroyed(key);
                    break;
                case INVALIDATE:
                    listener.waitForInvalidated(key);
                    break;
                case CLOSE:
                    listener.waitForClose();
                    break;
                case REGION_CLEAR:
                    listener.waitForRegionClear();
                    break;
                case REGION_INVALIDATE:
                    listener.waitForRegionInvalidate();
                    break;
            }
        }
    });
}
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 5 with CqQuery

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

the class CqQueryDUnitTest method executeAndCloseAndExecuteIRMultipleTimes.

// helps test case where executeIR is called multiple times as well as after close
public void executeAndCloseAndExecuteIRMultipleTimes(VM vm, final String cqName, final String queryStr) {
    vm.invoke(new CacheSerializableRunnable("Create CQ :" + cqName) {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create CQ. ###" + cqName);
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            // Create CQ Attributes.
            CqAttributesFactory cqf = new CqAttributesFactory();
            CqListener[] cqListeners = { new CqQueryTestListener(LogWriterUtils.getLogWriter()) };
            cqf.initCqListeners(cqListeners);
            CqAttributes cqa = cqf.create();
            CqQuery cq1;
            // Create CQ.
            try {
                cq1 = cqService.newCq(cqName, queryStr, cqa);
                assertTrue("newCq() state mismatch", cq1.getState().isStopped());
            } catch (Exception ex) {
                AssertionError err = new AssertionError("Failed to create CQ " + cqName + " . ");
                err.initCause(ex);
                LogWriterUtils.getLogWriter().info("CqService is :" + cqService, err);
                throw err;
            }
            try {
                cq1.executeWithInitialResults();
                try {
                    cq1.executeWithInitialResults();
                } catch (IllegalStateException e) {
                // expected
                }
                cq1.close();
                try {
                    cq1.executeWithInitialResults();
                } catch (CqClosedException e) {
                    // expected
                    return;
                }
                fail("should have received cqClosedException");
            } catch (Exception e) {
                fail("exception not expected here " + e);
            }
        }
    });
}
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) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqClosedException(org.apache.geode.cache.query.CqClosedException) 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)

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