Search in sources :

Example 1 with CqAttributesMutator

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

the class CqQueryDUnitTest method mutateCQAttributes.

// Exercise CQ attributes mutator functions
private void mutateCQAttributes(VM vm, final String cqName, final int mutator_function) throws Exception {
    vm.invoke(new CacheSerializableRunnable("Stop CQ :" + cqName) {

        public void run2() throws CacheException {
            CqQuery cq1 = null;
            LogWriterUtils.getLogWriter().info("### CQ attributes mutator for ###" + cqName);
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            // Get CQ.
            try {
                cq1 = cqService.getCq(cqName);
            } catch (Exception ex) {
                ex.printStackTrace();
                fail("Failed to get CQ " + cqName + " . " + ex.getMessage());
            }
            CqAttributesMutator cqAttrMutator = cq1.getCqAttributesMutator();
            CqAttributes cqAttr = cq1.getCqAttributes();
            CqListener[] cqListeners;
            switch(mutator_function) {
                case CREATE:
                    // Reinitialize with 2 CQ Listeners
                    CqListener[] cqListenersArray = { new CqQueryTestListener(getCache().getLogger()), new CqQueryTestListener(getCache().getLogger()) };
                    cqAttrMutator.initCqListeners(cqListenersArray);
                    cqListeners = cqAttr.getCqListeners();
                    assertEquals("CqListener count mismatch", cqListeners.length, 2);
                    break;
                case UPDATE:
                    // Add 2 new CQ Listeners
                    CqListener newListener1 = new CqQueryTestListener(getCache().getLogger());
                    CqListener newListener2 = new CqQueryTestListener(getCache().getLogger());
                    cqAttrMutator.addCqListener(newListener1);
                    cqAttrMutator.addCqListener(newListener2);
                    cqListeners = cqAttr.getCqListeners();
                    assertEquals("CqListener count mismatch", cqListeners.length, 3);
                    break;
                case DESTROY:
                    cqListeners = cqAttr.getCqListeners();
                    cqAttrMutator.removeCqListener(cqListeners[0]);
                    cqListeners = cqAttr.getCqListeners();
                    assertEquals("CqListener count mismatch", cqListeners.length, 2);
                    // Remove a listener and validate
                    cqAttrMutator.removeCqListener(cqListeners[0]);
                    cqListeners = cqAttr.getCqListeners();
                    assertEquals("CqListener count mismatch", cqListeners.length, 1);
                    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) CqListener(org.apache.geode.cache.query.CqListener) CqQuery(org.apache.geode.cache.query.CqQuery) CqAttributesMutator(org.apache.geode.cache.query.CqAttributesMutator) 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

IOException (java.io.IOException)1 CacheException (org.apache.geode.cache.CacheException)1 CqAttributes (org.apache.geode.cache.query.CqAttributes)1 CqAttributesMutator (org.apache.geode.cache.query.CqAttributesMutator)1 CqClosedException (org.apache.geode.cache.query.CqClosedException)1 CqExistsException (org.apache.geode.cache.query.CqExistsException)1 CqListener (org.apache.geode.cache.query.CqListener)1 CqQuery (org.apache.geode.cache.query.CqQuery)1 QueryService (org.apache.geode.cache.query.QueryService)1 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)1 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)1 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)1