use of org.apache.geode.cache.query.NameResolutionException in project geode by apache.
the class ResourceManagerWithQueryMonitorDUnitTest method doCriticalMemoryHitTest.
private void doCriticalMemoryHitTest(final String regionName, boolean createPR, final int criticalThreshold, final boolean disabledQueryMonitorForLowMem, final int queryTimeout, final boolean hitCriticalThreshold) throws Exception {
// create region on the server
final Host host = Host.getHost(0);
final VM server = host.getVM(0);
final VM client = host.getVM(1);
final int numObjects = 200;
try {
final int port = AvailablePortHelper.getRandomAvailableTCPPort();
startCacheServer(server, port, criticalThreshold, disabledQueryMonitorForLowMem, queryTimeout, regionName, createPR, 0);
startClient(client, server, port, regionName);
populateData(server, regionName, numObjects);
doTestCriticalHeapAndQueryTimeout(server, client, regionName, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
// Pause for a second and then let's recover
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// Recover from critical heap
if (hitCriticalThreshold) {
vmRecoversFromCriticalHeap(server);
}
// Check to see if query execution is ok under "normal" or "healthy" conditions
client.invoke(new CacheSerializableRunnable("Executing query when system is 'Normal'") {
public void run2() {
try {
QueryService qs = getCache().getQueryService();
Query query = qs.newQuery("Select * From /" + regionName);
SelectResults results = (SelectResults) query.execute();
assertEquals(numObjects, results.size());
} catch (QueryInvocationTargetException e) {
assertFalse(true);
} catch (NameResolutionException e) {
assertFalse(true);
} catch (TypeMismatchException e) {
assertFalse(true);
} catch (FunctionDomainException e) {
assertFalse(true);
}
}
});
// Execute a critical heap event/ query timeout test again
doTestCriticalHeapAndQueryTimeout(server, client, regionName, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
// Recover from critical heap
if (hitCriticalThreshold) {
vmRecoversFromCriticalHeap(server);
}
} finally {
stopServer(server);
}
}
use of org.apache.geode.cache.query.NameResolutionException in project geode by apache.
the class ResourceManagerWithQueryMonitorDUnitTest method doCriticalMemoryHitTestOnServer.
// Executes the query on the server with the RM and QM configured
private void doCriticalMemoryHitTestOnServer(final String regionName, boolean createPR, final int criticalThreshold, final boolean disabledQueryMonitorForLowMem, final int queryTimeout, final boolean hitCriticalThreshold) throws Exception {
// create region on the server
final Host host = Host.getHost(0);
final VM server = host.getVM(0);
final VM client = host.getVM(1);
final int numObjects = 200;
try {
final int port = AvailablePortHelper.getRandomAvailableTCPPort();
startCacheServer(server, port, criticalThreshold, disabledQueryMonitorForLowMem, queryTimeout, regionName, createPR, 0);
// startPeerClient(client, server, port, regionName);
populateData(server, regionName, numObjects);
doTestCriticalHeapAndQueryTimeout(server, server, regionName, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
// Pause for a second and then let's recover
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// Recover from critical heap
if (hitCriticalThreshold) {
vmRecoversFromCriticalHeap(server);
}
// Check to see if query execution is ok under "normal" or "healthy" conditions
server.invoke(new CacheSerializableRunnable("Executing query when system is 'Normal'") {
public void run2() {
try {
QueryService qs = getCache().getQueryService();
Query query = qs.newQuery("Select * From /" + regionName);
SelectResults results = (SelectResults) query.execute();
assertEquals(numObjects, results.size());
} catch (QueryInvocationTargetException e) {
assertFalse(true);
} catch (NameResolutionException e) {
assertFalse(true);
} catch (TypeMismatchException e) {
assertFalse(true);
} catch (FunctionDomainException e) {
assertFalse(true);
}
}
});
// Execute a critical heap event/ query timeout test again
doTestCriticalHeapAndQueryTimeout(server, server, regionName, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
// Recover from critical heap
if (hitCriticalThreshold) {
vmRecoversFromCriticalHeap(server);
}
} finally {
stopServer(server);
}
}
use of org.apache.geode.cache.query.NameResolutionException in project geode by apache.
the class LocalRegion method query.
@Override
public SelectResults query(String predicate) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
if (predicate == null) {
throw new IllegalArgumentException("The input query predicate is null. A null predicate is not allowed.");
}
predicate = predicate.trim();
SelectResults results;
if (hasServerProxy()) {
// Trim whitespace
String queryString = constructRegionQueryString(predicate.trim());
try {
results = getServerProxy().query(queryString, null);
} catch (Exception e) {
Throwable cause = e.getCause();
if (cause == null) {
cause = e;
}
throw new QueryInvocationTargetException(e.getMessage(), cause);
}
} else {
// TODO: params size is always zero so this whole block is wasted
Object[] params = new Object[0];
QueryService qs = getGemFireCache().getLocalQueryService();
String queryStr = constructRegionQueryString(predicate.trim());
DefaultQuery query = (DefaultQuery) qs.newQuery(queryStr);
if (query.getRegionsInQuery(params).size() != 1) {
throw new QueryInvalidException("Prevent multiple region query from being executed through region.query()");
}
results = (SelectResults) query.execute(params);
}
return results;
}
use of org.apache.geode.cache.query.NameResolutionException in project geode by apache.
the class DataCommandFunction method select.
@SuppressWarnings("rawtypes")
private DataCommandResult select(Object principal, String queryString) {
InternalCache cache = getCache();
AtomicInteger nestedObjectCount = new AtomicInteger(0);
if (StringUtils.isEmpty(queryString)) {
return DataCommandResult.createSelectInfoResult(null, null, -1, null, CliStrings.QUERY__MSG__QUERY_EMPTY, false);
}
QueryService qs = cache.getQueryService();
// TODO : Find out if is this optimised use. Can you have something equivalent of parsed
// queries with names where name can be retrieved to avoid parsing every-time
Query query = qs.newQuery(queryString);
DefaultQuery tracedQuery = (DefaultQuery) query;
WrappedIndexTrackingQueryObserver queryObserver = null;
String queryVerboseMsg = null;
long startTime = -1;
if (tracedQuery.isTraced()) {
startTime = NanoTimer.getTime();
queryObserver = new WrappedIndexTrackingQueryObserver();
QueryObserverHolder.setInstance(queryObserver);
}
List<SelectResultRow> list = new ArrayList<>();
try {
Object results = query.execute();
if (tracedQuery.isTraced()) {
queryVerboseMsg = getLogMessage(queryObserver, startTime, queryString);
queryObserver.reset2();
}
if (results instanceof SelectResults) {
select_SelectResults((SelectResults) results, principal, list, nestedObjectCount);
} else {
select_NonSelectResults(results, list);
}
return DataCommandResult.createSelectResult(queryString, list, queryVerboseMsg, null, null, true);
} catch (FunctionDomainException | GfJsonException | QueryInvocationTargetException | NameResolutionException | TypeMismatchException e) {
logger.warn(e.getMessage(), e);
return DataCommandResult.createSelectResult(queryString, null, queryVerboseMsg, e, e.getMessage(), false);
} finally {
if (queryObserver != null) {
QueryObserverHolder.reset();
}
}
}
use of org.apache.geode.cache.query.NameResolutionException in project geode by apache.
the class GroupByQueryDUnitTest method runQuery.
private void runQuery(VM queryVM) throws Exception {
// createIndex(vm0, "compactRangeIndex", "entry.value",
// "/region.entrySet entry");
// Do Puts
queryVM.invoke(new SerializableRunnable("putting data") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("portfolio");
for (int i = 1; i < 200; ++i) {
Portfolio pf = new Portfolio(i);
pf.shortID = (short) ((short) i / 5);
region.put("" + i, pf);
}
}
});
queryVM.invoke(new SerializableRunnable("query") {
public void run() {
try {
QueryService qs = getCache().getQueryService();
String queryStr = "select p.shortID as short_id from /portfolio p where p.ID >= 0 group by short_id ";
Query query = qs.newQuery(queryStr);
SelectResults<Struct> results = (SelectResults<Struct>) query.execute();
Iterator<Struct> iter = results.iterator();
int counter = 0;
while (iter.hasNext()) {
Struct str = iter.next();
assertEquals(counter++, ((Short) str.get("short_id")).intValue());
}
assertEquals(39, counter - 1);
} catch (QueryInvocationTargetException e) {
fail(e.toString());
} catch (NameResolutionException e) {
fail(e.toString());
} catch (TypeMismatchException e) {
fail(e.toString());
} catch (FunctionDomainException e) {
fail(e.toString());
}
}
});
}
Aggregations