@Test
  public void testMemoryIndexStoreMaintenanceTransitionFromElemArrayToTokenToConcurrentHashSet()
      throws Exception {
    try {
      index = utils.createIndex("compact range index", "p.status", SEPARATOR + "exampleRegion p");
      final Region r = utils.getCache().getRegion(SEPARATOR + "exampleRegion");
      Portfolio p0 = new Portfolio(0);
      p0.status = "active";
      Portfolio p1 = new Portfolio(1);
      p1.status = "active";
      final Portfolio p2 = new Portfolio(2);
      p2.status = "active";
      Portfolio p3 = new Portfolio(3);
      p3.status = "active";
      r.put("0", p0);
      r.put("1", p1);
      r.put("3", p3);

      // now we set the test hook. That way previous calls would not affect the test hooks
      DefaultQuery.testHook = new MemoryIndexStoreIndexElemToTokenToConcurrentHashSetTestHook();
      final CountDownLatch threadsDone = new CountDownLatch(2);
      Thread t2 = new Thread(() -> {
        r.put("2", p2);
        threadsDone.countDown();

      });
      t2.start();

      Thread t0 = new Thread(() -> {
        r.remove("0");
        threadsDone.countDown();
      });
      t0.start();

      threadsDone.await(90, TimeUnit.SECONDS);
      QueryService qs = utils.getCache().getQueryService();
      SelectResults results = (SelectResults) qs
          .newQuery("Select * from " + SEPARATOR + "exampleRegion r where r.status='active'")
          .execute();
      // the remove should have happened
      assertEquals(3, results.size());

      results = (SelectResults) qs
          .newQuery("Select * from " + SEPARATOR + "exampleRegion r where r.status!='inactive'")
          .execute();
      assertEquals(3, results.size());

      CompactRangeIndex cindex = (CompactRangeIndex) index;
      MemoryIndexStore indexStore = (MemoryIndexStore) cindex.getIndexStorage();
      CloseableIterator iterator = indexStore.get("active");
      int count = 0;
      while (iterator.hasNext()) {
        count++;
        iterator.next();
      }
      assertEquals("incorrect number of entries in collection", 3, count);
    } finally {
      DefaultQuery.testHook = null;
    }
  }
Tests race condition when we are transitioning index collection from elem array to concurrent
hash set The other thread could remove from the empty concurrent hash set. Instead we now set a
token, do all the puts into a collection and then unsets the token to the new collection
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/CompactRangeIndexJUnitTest.java