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);
}
}
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);
}
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();
}
}
}
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);
}
}
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());
}
}
Aggregations