Search in sources :

Example 1 with CqAttributes

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

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

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

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

Example 5 with CqAttributes

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

the class CqQueryDUnitTest method clearCQListenerEvents.

public void clearCQListenerEvents(VM vm, final String cqName) {
    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();
                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.getEventHistory();
        }
    });
}
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)

Aggregations

CqAttributes (org.apache.geode.cache.query.CqAttributes)40 QueryService (org.apache.geode.cache.query.QueryService)36 CqQuery (org.apache.geode.cache.query.CqQuery)35 CqAttributesFactory (org.apache.geode.cache.query.CqAttributesFactory)31 CacheException (org.apache.geode.cache.CacheException)25 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)23 CqExistsException (org.apache.geode.cache.query.CqExistsException)18 IOException (java.io.IOException)16 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)16 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)15 CqListener (org.apache.geode.cache.query.CqListener)14 Test (org.junit.Test)14 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)13 CqClosedException (org.apache.geode.cache.query.CqClosedException)12 Region (org.apache.geode.cache.Region)10 CqEvent (org.apache.geode.cache.query.CqEvent)8 Host (org.apache.geode.test.dunit.Host)8 VM (org.apache.geode.test.dunit.VM)8 SelectResults (org.apache.geode.cache.query.SelectResults)7 CqQueryTestListener (org.apache.geode.cache.query.cq.dunit.CqQueryTestListener)7