@Test
  public void testCompactRangeIndexMemoryIndexStoreMaintenance() 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";
      final Portfolio p1 = new Portfolio(1);
      p1.status = "active";
      r.put("0", p0);

      DefaultQuery.testHook = new MemoryIndexStoreREToIndexElemTestHook();
      final CountDownLatch threadsDone = new CountDownLatch(2);

      Thread t1 = new Thread(() -> {
        r.put("1", p1);
        threadsDone.countDown();
      });
      t1.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(1, results.size());

      results = (SelectResults) qs
          .newQuery("Select * from " + SEPARATOR + "exampleRegion r where r.status!='inactive'")
          .execute();
      assertEquals(1, 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", 1, count);
    } finally {
      DefaultQuery.testHook = null;
    }
  }
Tests race condition where we possibly were missing remove calls due to transitioning to an
empty index elem before adding the entries the fix is to add the entries to the elem and then
transition to that elem
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/CompactRangeIndexJUnitTest.java