Search in sources :

Example 6 with NameResolutionException

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);
    }
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) VM(org.apache.geode.test.dunit.VM) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Host(org.apache.geode.test.dunit.Host) NameResolutionException(org.apache.geode.cache.query.NameResolutionException)

Example 7 with NameResolutionException

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);
    }
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) VM(org.apache.geode.test.dunit.VM) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Host(org.apache.geode.test.dunit.Host) NameResolutionException(org.apache.geode.cache.query.NameResolutionException)

Example 8 with NameResolutionException

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;
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) StoredObject(org.apache.geode.internal.offheap.StoredObject) TimeoutException(org.apache.geode.cache.TimeoutException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) StatisticsDisabledException(org.apache.geode.cache.StatisticsDisabledException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) FailedSynchronizationException(org.apache.geode.cache.FailedSynchronizationException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) RedundancyAlreadyMetException(org.apache.geode.internal.cache.partitioned.RedundancyAlreadyMetException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) SystemException(javax.transaction.SystemException) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) TransactionException(org.apache.geode.cache.TransactionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RollbackException(javax.transaction.RollbackException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) DeltaSerializationException(org.apache.geode.DeltaSerializationException)

Example 9 with NameResolutionException

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();
        }
    }
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) ArrayList(java.util.ArrayList) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) InternalCache(org.apache.geode.internal.cache.InternalCache) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) SelectResults(org.apache.geode.cache.query.SelectResults) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) SelectResultRow(org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject)

Example 10 with NameResolutionException

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());
            }
        }
    });
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) Struct(org.apache.geode.cache.query.Struct) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Aggregations

NameResolutionException (org.apache.geode.cache.query.NameResolutionException)17 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)16 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)16 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)15 Query (org.apache.geode.cache.query.Query)11 SelectResults (org.apache.geode.cache.query.SelectResults)11 QueryService (org.apache.geode.cache.query.QueryService)9 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)9 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)6 Host (org.apache.geode.test.dunit.Host)6 VM (org.apache.geode.test.dunit.VM)6 QueryException (org.apache.geode.cache.query.QueryException)5 QueryExecutionTimeoutException (org.apache.geode.cache.query.QueryExecutionTimeoutException)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 QueryExecutionLowMemoryException (org.apache.geode.cache.query.QueryExecutionLowMemoryException)4 Cache (org.apache.geode.cache.Cache)3 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 CacheException (org.apache.geode.cache.CacheException)3 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)3