Search in sources :

Example 21 with CompiledValue

use of org.apache.geode.cache.query.internal.CompiledValue in project geode by apache.

the class GemfireDataCommandsDUnitTest method doQueryRegionsAssociatedMembers.

private void doQueryRegionsAssociatedMembers(String queryTemplate, int expectedMembers, boolean returnAll, String... regions) {
    InternalCache cache = getCache();
    String query = queryTemplate;
    int i = 1;
    for (String r : regions) {
        query = query.replace("?" + i, r);
        i++;
    }
    getLogWriter().info("Checking members for query : " + query);
    QCompiler compiler = new QCompiler();
    Set<String> regionsInQuery = null;
    try {
        CompiledValue compiledQuery = compiler.compileQuery(query);
        Set regionSet = new HashSet();
        // GFSH ENV VARIBLES
        compiledQuery.getRegionsInQuery(regionSet, null);
        regionsInQuery = Collections.unmodifiableSet(regionSet);
        getLogWriter().info("Region in query : " + regionsInQuery);
        if (regionsInQuery.size() > 0) {
            Set<DistributedMember> members = DataCommands.getQueryRegionsAssociatedMembers(regionsInQuery, cache, returnAll);
            getLogWriter().info("Members for Region in query : " + members);
            if (expectedMembers != -1) {
                assertNotNull(members);
                assertEquals(expectedMembers, members.size());
            } else
                assertEquals(0, members.size());
        } else {
            // Regions do not exist at all
            assertEquals(-1, expectedMembers);
        }
    } catch (QueryInvalidException qe) {
        fail("Invalid Query", qe);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) QCompiler(org.apache.geode.cache.query.internal.QCompiler) CompiledValue(org.apache.geode.cache.query.internal.CompiledValue) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) HashSet(java.util.HashSet)

Aggregations

CompiledValue (org.apache.geode.cache.query.internal.CompiledValue)21 HashSet (java.util.HashSet)7 List (java.util.List)6 Set (java.util.Set)6 Region (org.apache.geode.cache.Region)5 SelectResults (org.apache.geode.cache.query.SelectResults)5 QueryObserverAdapter (org.apache.geode.cache.query.internal.QueryObserverAdapter)5 RuntimeIterator (org.apache.geode.cache.query.internal.RuntimeIterator)5 LocalRegion (org.apache.geode.internal.cache.LocalRegion)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 IndexInvalidException (org.apache.geode.cache.query.IndexInvalidException)4 Query (org.apache.geode.cache.query.Query)4 Portfolio (org.apache.geode.cache.query.data.Portfolio)4 CompiledIteratorDef (org.apache.geode.cache.query.internal.CompiledIteratorDef)4 CompiledPath (org.apache.geode.cache.query.internal.CompiledPath)4 QueryObserver (org.apache.geode.cache.query.internal.QueryObserver)4 AmbiguousNameException (org.apache.geode.cache.query.AmbiguousNameException)3 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)3