Search in sources :

Example 6 with QCompiler

use of org.apache.geode.cache.query.internal.QCompiler 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

QCompiler (org.apache.geode.cache.query.internal.QCompiler)6 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)4 List (java.util.List)3 HashSet (java.util.HashSet)2 CompiledIteratorDef (org.apache.geode.cache.query.internal.CompiledIteratorDef)2 CompiledValue (org.apache.geode.cache.query.internal.CompiledValue)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 InternalGemFireException (org.apache.geode.InternalGemFireException)1 Entry (org.apache.geode.cache.Region.Entry)1 FunctionException (org.apache.geode.cache.execute.FunctionException)1 CompiledID (org.apache.geode.cache.query.internal.CompiledID)1 CompiledPath (org.apache.geode.cache.query.internal.CompiledPath)1 RuntimeIterator (org.apache.geode.cache.query.internal.RuntimeIterator)1 IndexCreationData (org.apache.geode.cache.query.internal.index.IndexCreationData)1 PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)1