Search in sources :

Example 36 with CqAttributes

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

the class DeltaToRegionRelationCQRegistrationDUnitTest method registerCq.

/*
   * register cq
   */
public static void registerCq(String name, String Cquery, Boolean cqWithIR) {
    QueryService cqService = null;
    // get cq service
    try {
        cqService = cache.getQueryService();
    } catch (Exception cqe) {
        cqe.printStackTrace();
        fail("Failed to getCqService.");
    }
    // Create CQ Attributes.
    // do not attach any listiner lets see its response
    CqAttributesFactory cqf = new CqAttributesFactory();
    CqAttributes cqa = cqf.create();
    // Create and Execute CQ.
    try {
        CqQuery cq1 = cqService.newCq(name, Cquery, cqa);
        assertTrue("newCq() state mismatch", cq1.getState().isStopped());
        if (cqWithIR)
            cq1.executeWithInitialResults();
        else
            cq1.execute();
    } catch (Exception ex) {
        fail("Failed to create CQ " + cqName1, ex);
    }
    CqQuery cQuery = cqService.getCq(name);
    if (cQuery == null) {
        fail("Failed to get CqQuery for CQ : " + cqName1);
    }
}
Also used : QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery)

Example 37 with CqAttributes

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

the class DurableClientTestCase method createCq.

protected CqQuery createCq(String cqName, String cqQuery, boolean durable) throws CqException, CqExistsException {
    QueryService qs = CacheServerTestUtil.getCache().getQueryService();
    CqAttributesFactory cqf = new CqAttributesFactory();
    CqListener[] cqListeners = { new CacheServerTestUtil.ControlCqListener() };
    cqf.initCqListeners(cqListeners);
    CqAttributes cqa = cqf.create();
    return qs.newCq(cqName, cqQuery, cqa, durable);
}
Also used : QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqListener(org.apache.geode.cache.query.CqListener) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory)

Example 38 with CqAttributes

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

the class ClientToServerDeltaDUnitTest method createClientCache.

/*
   * create client cache
   */
public static void createClientCache(String host, Integer port, Boolean attachListener, Boolean isEmpty, Boolean isCq, String[] cqQueryString, Boolean registerInterestAll, Boolean enableSubscription) throws Exception {
    updates = 0;
    create = 0;
    firstUpdate = null;
    secondUpdate = null;
    error = false;
    lastKeyReceived = false;
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new ClientToServerDeltaDUnitTest().createCache(props);
    pool = (PoolImpl) PoolManager.createFactory().addServer(host, port.intValue()).setThreadLocalConnections(true).setMinConnections(2).setSubscriptionEnabled(enableSubscription).setSubscriptionRedundancy(0).setReadTimeout(10000).setPingInterval(1000).setSocketBufferSize(32768).create("ClientToServerDeltaDunitTestPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setConcurrencyChecksEnabled(true);
    if (isEmpty) {
        factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
        factory.setDataPolicy(DataPolicy.EMPTY);
    } else {
        factory.setDataPolicy(DataPolicy.NORMAL);
    }
    factory.setPoolName(pool.getName());
    factory.setCloningEnabled(false);
    // region with empty data policy
    RegionAttributes attrs = factory.create();
    region = cache.createRegion(REGION_NAME, attrs);
    if (attachListener) {
        region.getAttributesMutator().addCacheListener(new CacheListenerAdapter() {

            @Override
            public void afterCreate(EntryEvent event) {
                create++;
                if (LAST_KEY.equals(event.getKey())) {
                    lastKeyReceived = true;
                }
                ;
            }

            @Override
            public void afterUpdate(EntryEvent event) {
                switch(updates) {
                    case 0:
                        // first delta
                        validateUpdates(event, firstUpdate, "FIRST");
                        updates++;
                        break;
                    case 1:
                        // combine delta
                        validateUpdates(event, firstUpdate, "FIRST");
                        validateUpdates(event, secondUpdate, "SECOND");
                        updates++;
                        break;
                    default:
                        break;
                }
            }
        });
    }
    if (registerInterestAll) {
        region.registerInterest("ALL_KEYS");
    }
    if (isCq) {
        CqAttributesFactory cqf = new CqAttributesFactory();
        CqListenerAdapter cqlist = new CqListenerAdapter() {

            @Override
            public void onEvent(CqEvent cqEvent) {
                Object key = cqEvent.getKey();
                if (LAST_KEY.equals(key)) {
                    lastKeyReceived = true;
                }
                logger.fine("CQ event received for (key, value): (" + key + ", " + cqEvent.getNewValue() + ")");
            }

            @Override
            public void onError(CqEvent cqEvent) {
                logger.fine("CQ error received for key: " + cqEvent.getKey());
            }
        };
        cqf.addCqListener(cqlist);
        CqAttributes cqa = cqf.create();
        for (int i = 0; i < cqQueryString.length; i++) {
            CqQuery cq = cache.getQueryService().newCq("Delta_Query_" + i, cqQueryString[i], cqa);
            cq.execute();
        }
    }
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) Properties(java.util.Properties) CqListenerAdapter(org.apache.geode.cache.util.CqListenerAdapter) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) CqEvent(org.apache.geode.cache.query.CqEvent) CqAttributes(org.apache.geode.cache.query.CqAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 39 with CqAttributes

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

the class CQListGIIDUnitTest method createCQ.

/* Register CQs */
public static void createCQ(String cqName, String queryStr) {
    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("### Create CQ. ###" + cqName);
    // Get CQ Service.
    QueryService cqService = null;
    try {
        cqService = cache.getQueryService();
    } catch (Exception cqe) {
        Assert.fail("Failed to getCQService.", cqe);
    }
    // Create CQ Attributes.
    CqAttributesFactory cqf = new CqAttributesFactory();
    CqListener[] cqListeners = { new CqQueryTestListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()) };
    ((CqQueryTestListener) cqListeners[0]).cqName = cqName;
    cqf.initCqListeners(cqListeners);
    CqAttributes cqa = cqf.create();
    // Create CQ.
    try {
        CqQuery cq1 = cqService.newCq(cqName, queryStr, cqa);
        assertTrue("newCq() state mismatch", cq1.getState().isStopped());
    } catch (Exception ex) {
        fail("Failed to create CQ " + cqName + " . ", ex);
    }
}
Also used : CqQueryTestListener(org.apache.geode.cache.query.cq.dunit.CqQueryTestListener) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqListener(org.apache.geode.cache.query.CqListener) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 40 with CqAttributes

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

the class ClientCQPostAuthorizationDUnitTest method createCQ.

private void createCQ(final int num) throws CqException, CqExistsException {
    for (int i = 0; i < num; i++) {
        QueryService cqService = getProxyCaches(i).getQueryService();
        String cqName = "CQ_" + i;
        String queryStr = cqNameToQueryStrings.get(cqName) + getProxyCaches(i).getRegion(REGION_NAME).getFullPath();
        // Create CQ Attributes.
        CqAttributesFactory cqf = new CqAttributesFactory();
        CqListener[] cqListeners = { new CqQueryTestListener(getLogWriter()) };
        ((CqQueryTestListener) cqListeners[0]).cqName = cqName;
        cqf.initCqListeners(cqListeners);
        CqAttributes cqa = cqf.create();
        // Create CQ.
        CqQuery cq1 = cqService.newCq(cqName, queryStr, cqa);
        assertTrue("newCq() state mismatch", cq1.getState().isStopped());
    }
}
Also used : CqQueryTestListener(org.apache.geode.cache.query.cq.dunit.CqQueryTestListener) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqListener(org.apache.geode.cache.query.CqListener) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqQuery(org.apache.geode.cache.query.CqQuery)

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