@Override
      public void run2() throws CacheException {
        Set filter = new HashSet();
        ResultCollector rcollector = null;
        filter.addAll(getFilter(6, 9));

        for (final String query : queries) {

          try {
            function = new TestQueryFunction("queryFunction");

            rcollector = FunctionService
                .onRegion(CacheFactory.getAnyInstance().getRegion(PartitionedRegionName1))
                .setArguments(query).withFilter(filter).execute(function);

            // Should not come here, an exception is expected from above function call.
            fail("Function call did not fail for query with function context");
          } catch (FunctionException ex) {
            if (!((ex.getCause() instanceof QueryInvocationTargetException)
                || (ex.getCause() instanceof ServerConnectivityException))) {
              if (ex.getCause() instanceof FunctionException) {
                FunctionException fe = (FunctionException) ex.getCause();
                if (!fe.getMessage().startsWith("IOException")) {
                  fail("Should have received an QueryInvocationTargetException but received"
                      + ex.getMessage());
                }
              } else {
                fail("Should have received an QueryInvocationTargetException but received"
                    + ex.getMessage());
              }
            }
          }
        } // For loop ends here.
      }
Test on PR on one server only using filter.
geode-core/src/distributedTest/java/org/apache/geode/cache/query/dunit/QueryUsingFunctionContextDUnitTest.java