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

    server.invoke(() -> {
      // Set test query observer.
      InternalCache internalCache = ClusterStartupRule.getCache();
      assertThat(internalCache).isNotNull();
      TestQueryObserver queryObserver =
          new TestQueryObserver(RestrictedMethodAuthorizer.class.getName(), Collections.emptySet());
      QueryObserverHolder.setInstance(queryObserver);

      // Execute query.
      Query query = internalCache.getQueryService().newQuery(queryString);
      @SuppressWarnings("unchecked")
      SelectResults<QueryObject> result = (SelectResults<QueryObject>) query.execute();
      assertThat(queryObserver.invocations.get()).isEqualTo(1);
      assertThat(result.size()).isEqualTo(ENTRIES);

      // Execute query again, it should fail as the restricted authorizer has been installed.
      QueryObserverHolder.reset();
      Query newQuery = internalCache.getQueryService().newQuery(queryString);
      assertThatThrownBy(newQuery::execute)
          .isInstanceOf(NotAuthorizedException.class)
          .hasMessage(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 server.
geode-core/src/distributedTest/java/org/apache/geode/cache/query/internal/QueryConfigurationServiceConstraintsDistributedTest.java