public void testGetGroupKeysDuringPrimaryOwnerChange()
      throws TimeoutException, InterruptedException, ExecutionException {
    /*
     * it tests multiple scenarios
     * 1) when the ownership changes (when we execute the query in the primary owner and a new one is elected)
     * 2) when the topology changes but the ownership doesn't (when we execute the query on the backup owner)
     * 3) when the ownership changes and the query is executed in a non-owner
     */
    final TestCache testCache = createTestCacheAndReset(GROUP, this.<GroupKey, String>caches());
    initCache(testCache.primaryOwner);
    final BlockCommandInterceptor interceptor =
        injectBlockCommandInterceptorIfAbsent(extractTargetCache(testCache));

    interceptor.open = false;
    Future<Map<GroupKey, String>> future =
        fork(
            new Callable<Map<GroupKey, String>>() {
              @Override
              public Map<GroupKey, String> call() throws Exception {
                return testCache.testCache.getGroup(GROUP);
              }
            });

    interceptor.awaitCommandBlock();

    addClusterEnabledCacheManager(createConfigurationBuilder());
    waitForClusterToForm();

    interceptor.unblockCommandAndOpen();

    Map<GroupKey, String> groupKeySet = future.get();
    Map<GroupKey, String> expectedGroupSet = createMap(0, 10);
    AssertJUnit.assertEquals(expectedGroupSet, groupKeySet);
  }
 private static BlockCommandInterceptor injectBlockCommandInterceptorIfAbsent(
     Cache<GroupKey, String> cache) {
   InterceptorChain chain = TestingUtil.extractComponent(cache, InterceptorChain.class);
   BlockCommandInterceptor interceptor;
   if (chain.containsInterceptorType(BlockCommandInterceptor.class)) {
     interceptor =
         (BlockCommandInterceptor)
             chain.getInterceptorsWithClass(BlockCommandInterceptor.class).get(0);
   } else {
     interceptor = new BlockCommandInterceptor();
     chain.addInterceptorAfter(interceptor, EntryWrappingInterceptor.class);
   }
   interceptor.reset();
   return interceptor;
 }