Search in sources :

Example 36 with QueryInvalidException

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

QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)36 Test (org.junit.Test)12 QueryService (org.apache.geode.cache.query.QueryService)11 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)11 List (java.util.List)7 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)7 ArrayList (java.util.ArrayList)6 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)6 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)6 Query (org.apache.geode.cache.query.Query)6 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)5 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)5 StringReader (java.io.StringReader)4 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)4 Region (org.apache.geode.cache.Region)4 SelectResults (org.apache.geode.cache.query.SelectResults)4 Portfolio (org.apache.geode.cache.query.data.Portfolio)4 Set (java.util.Set)3 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)3