use of org.apache.geode.cache.query.CqQuery in project geode by apache.
the class CqServiceImpl method executeCqs.
@Override
public synchronized void executeCqs(Collection<? extends InternalCqQuery> cqs) throws CqException {
if (cqs == null) {
return;
}
String cqName = null;
for (InternalCqQuery internalCq : cqs) {
CqQuery cq = internalCq;
if (!cq.isClosed() && cq.isStopped()) {
try {
cqName = cq.getName();
cq.execute();
} catch (QueryException | CqClosedException e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to execute the CQ, CqName : {} Error : {}", cqName, e.getMessage());
}
}
}
}
}
use of org.apache.geode.cache.query.CqQuery 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());
}
}
use of org.apache.geode.cache.query.CqQuery in project geode by apache.
the class ClientCQPostAuthorizationDUnitTest method executeCQ.
private void executeCQ(final int num, final boolean[] initialResults, final int expectedResultsSize, final String[] expectedErr, final boolean[] postAuthzAllowed) throws RegionNotFoundException, CqException {
for (int i = 0; i < num; i++) {
try {
if (expectedErr[i] != null) {
getLogWriter().info("<ExpectedException action=add>" + expectedErr[i] + "</ExpectedException>");
}
CqQuery cq1 = null;
String cqName = "CQ_" + i;
// String queryStr = cqNameToQueryStrings.get(cqName) +
// getProxyCaches(i).getRegion(REGION_NAME).getFullPath();
QueryService cqService = getProxyCaches(i).getQueryService();
// Get CqQuery object.
cq1 = cqService.getCq(cqName);
if (cq1 == null) {
getLogWriter().info("Failed to get CqQuery object for CQ name: " + cqName);
fail("Failed to get CQ " + cqName);
} else {
getLogWriter().info("Obtained CQ, CQ name: " + cq1.getName());
assertTrue("newCq() state mismatch", cq1.getState().isStopped());
}
if (initialResults[i]) {
SelectResults cqResults = null;
try {
cqResults = cq1.executeWithInitialResults();
} catch (CqException ce) {
if (ce.getCause() instanceof NotAuthorizedException && !postAuthzAllowed[i]) {
getLogWriter().info("Got expected exception for CQ " + cqName);
} else {
getLogWriter().info("CqService is: " + cqService);
throw new AssertionError("Failed to execute CQ " + cqName, ce);
}
}
getLogWriter().info("initial result size = " + cqResults.size());
assertTrue("executeWithInitialResults() state mismatch", cq1.getState().isRunning());
if (expectedResultsSize >= 0) {
assertEquals("unexpected results size", expectedResultsSize, cqResults.size());
}
} else {
try {
cq1.execute();
} catch (CqException ce) {
if (ce.getCause() instanceof NotAuthorizedException && !postAuthzAllowed[i]) {
getLogWriter().info("Got expected exception for CQ " + cqName);
} else {
throw ce;
}
}
assertTrue("execute() state mismatch", cq1.getState().isRunning() == postAuthzAllowed[i]);
}
} finally {
if (expectedErr[i] != null) {
getLogWriter().info("<ExpectedException action=remove>" + expectedErr[i] + "</ExpectedException>");
}
}
}
}
use of org.apache.geode.cache.query.CqQuery in project geode by apache.
the class MultiUserAPIDUnitTest method verifyDisallowedOps.
private void verifyDisallowedOps(final boolean multiUserMode) throws Exception {
String op = "unknown";
boolean success = false;
if (!multiUserMode) {
success = false;
try {
// Attempt cache.createAuthenticatedCacheView() and expect an exception, fail otherwise
op = "Pool.createSecureUserCache()";
GemFireCacheImpl.getInstance().createAuthenticatedView(new Properties(), "testPool");
} catch (IllegalStateException uoe) {
getLogWriter().info(op + ": Got expected exception: " + uoe);
success = true;
}
if (!success) {
fail("Did not get exception while doing " + op);
}
} else {
// multiuser mode
Region realRegion = GemFireCacheImpl.getInstance().getRegion(SecurityTestUtils.REGION_NAME);
Region proxyRegion = SecurityTestUtils.getProxyCaches(0).getRegion(SecurityTestUtils.REGION_NAME);
Pool pool = PoolManagerImpl.getPMI().find("testPool");
for (int i = 0; i <= 27; i++) {
success = false;
try {
switch(i) {
// and expect an exception, fail otherwise.
case 0:
op = "Region.create()";
realRegion.create("key", "value");
break;
case 1:
op = "Region.put()";
realRegion.put("key", "value");
break;
case 2:
op = "Region.get()";
realRegion.get("key");
break;
case 3:
op = "Region.containsKeyOnServer()";
realRegion.containsKeyOnServer("key");
break;
case 4:
op = "Region.remove()";
realRegion.remove("key");
break;
case 5:
op = "Region.destroy()";
realRegion.destroy("key");
break;
case 6:
op = "Region.destroyRegion()";
realRegion.destroyRegion();
break;
case 7:
op = "Region.registerInterest()";
realRegion.registerInterest("key");
break;
// break;
case 8:
op = "Region.clear()";
realRegion.clear();
break;
// and expect an exception, fail otherwise.
case 9:
op = "ProxyRegion.createSubregion()";
proxyRegion.createSubregion("subregion", null);
break;
case 10:
op = "ProxyRegion.forceRolling()";
proxyRegion.forceRolling();
break;
case 11:
op = "ProxyRegion.getAttributesMutator()";
proxyRegion.getAttributesMutator();
break;
case 12:
op = "ProxyRegion.registerInterest()";
proxyRegion.registerInterest("key");
break;
case 13:
op = "ProxyRegion.loadSnapshot()";
proxyRegion.loadSnapshot(null);
break;
case 14:
op = "ProxyRegion.saveSnapshot()";
proxyRegion.saveSnapshot(null);
break;
case 15:
op = "ProxyRegion.setUserAttribute()";
proxyRegion.setUserAttribute(null);
break;
case 16:
op = "ProxyRegion.unregisterInterestRegex()";
proxyRegion.unregisterInterestRegex("*");
break;
// exception, fail otherwise.
case 17:
op = "FunctionService.onRegion()";
FunctionService.onRegion(realRegion);
break;
case 18:
op = "FunctionService.onServer(pool)";
FunctionService.onServer(pool);
break;
case 19:
op = "FunctionService.onServers(pool)";
FunctionService.onServers(pool);
break;
// QueryService.newQuery().execute()/newCq().execute/executeWithInitialResults()
case 20:
op = "QueryService.newQuery.execute()";
Query query = pool.getQueryService().newQuery("SELECT * FROM /" + SecurityTestUtils.REGION_NAME);
query.execute();
break;
case 21:
op = "QueryService.newCq.execute()";
CqQuery cqQuery = pool.getQueryService().newCq("SELECT * FROM /" + SecurityTestUtils.REGION_NAME, new CqAttributesFactory().create());
try {
cqQuery.execute();
} catch (CqException ce) {
throw (Exception) ce.getCause();
}
break;
case 22:
op = "QueryService.newCq.executeWithInitialResults()";
cqQuery = pool.getQueryService().newCq("SELECT * FROM /" + SecurityTestUtils.REGION_NAME, new CqAttributesFactory().create());
try {
cqQuery.executeWithInitialResults();
} catch (CqException ce) {
throw (Exception) ce.getCause();
}
break;
// expect an exception, fail otherwise.
case 23:
op = "ProxyQueryService().getIndexes()";
SecurityTestUtils.getProxyCaches(0).getQueryService().getIndexes(null);
break;
case 24:
op = "ProxyQueryService().createIndex()";
SecurityTestUtils.getProxyCaches(0).getQueryService().createIndex(null, null, null);
break;
case 25:
op = "ProxyQueryService().removeIndexes()";
SecurityTestUtils.getProxyCaches(0).getQueryService().removeIndexes();
break;
case 26:
op = "ProxyRegion.localDestroy()";
proxyRegion.localDestroy("key");
break;
case 27:
op = "ProxyRegion.localInvalidate()";
proxyRegion.localInvalidate("key");
break;
default:
fail("Unknown op code: " + i);
break;
}
} catch (UnsupportedOperationException uoe) {
getLogWriter().info(op + ": Got expected exception: " + uoe);
success = true;
}
if (!success) {
fail("Did not get exception while doing " + op);
}
}
}
}
Aggregations