@Test
  @Parameters({"LOCAL", "REPLICATE", "PARTITION"})
  @TestCaseName("[{index}] {method}(RegionType:{0})")
  public void queriesInFlightExecutedByClientsShouldNotBeAffectedWhenMethodAuthorizerIsChanged(
      RegionShortcut regionShortcut) {
    String regionName = testName.getMethodName();
    createAndPopulateRegion(regionName, regionShortcut);
    String queryString =
        "<TRACE> SELECT object." + QueryObject.GET_NAME_METHOD + " FROM " + SEPARATOR + regionName
            + " object";

    // Set test query observer.
    server.invoke(() -> {
      TestQueryObserver queryObserver =
          new TestQueryObserver(RestrictedMethodAuthorizer.class.getName(), Collections.emptySet());
      QueryObserverHolder.setInstance(queryObserver);
    });

    // Execute query from the client.
    client.invoke(() -> {
      assertThat(ClusterStartupRule.getClientCache()).isNotNull();
      ClientCache clientCache = ClusterStartupRule.getClientCache();
      Query query = clientCache.getQueryService().newQuery(queryString);
      @SuppressWarnings("unchecked")
      SelectResults<QueryObject> result = (SelectResults<QueryObject>) query.execute();
      assertThat(result.size()).isEqualTo(ENTRIES);
    });

    // Execute query again, it should fail as the restricted authorizer has been installed.
    server.invoke(QueryObserverHolder::reset);
    client.invoke(() -> {
      assertThat(ClusterStartupRule.getClientCache()).isNotNull();
      ClientCache clientCache = ClusterStartupRule.getClientCache();
      Query newQuery = clientCache.getQueryService().newQuery(queryString);
      assertThatThrownBy(newQuery::execute)
          .isInstanceOf(ServerOperationException.class)
          .hasCauseInstanceOf(NotAuthorizedException.class)
          .hasStackTraceContaining(
              RestrictedMethodAuthorizer.UNAUTHORIZED_STRING + QueryObject.GET_NAME_METHOD);
    });
  }
The test registers a {@link QueryObserver} that changes the installed
{@link MethodInvocationAuthorizer} to the default one (denies everything) as soon as the query
starts, and makes sure the query succeeds (it is not affected by the authorizer change).
The query is executed from the client.
geode-core/src/distributedTest/java/org/apache/geode/cache/query/internal/QueryConfigurationServiceConstraintsDistributedTest.java