@Test
  public void failedIndexCreationCorrectlyRemovesItself() throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    Cache cache = CacheUtils.getCache();
    cache.createRegionFactory(RegionShortcut.PARTITION).create("portfoliosInPartitionedRegion");
    Region region = CacheUtils.getCache().getRegion(SEPARATOR + "portfoliosInPartitionedRegion");
    IntStream.range(0, 3).forEach((i) -> {
      region.put(i, new Portfolio(i));
    });

    Index i1 = qs.createIndex("statusIndex", "secId",
        SEPARATOR + "portfoliosInPartitionedRegion p, p.positions pos, pos.secId secId");
    try {
      Index i2 =
          qs.createIndex("anotherIndex", "secId",
              SEPARATOR + "portfoliosInPartitionedRegion p, p.positions");
      // index should fail to create
      fail();
    } catch (IndexInvalidException ignored) {
    }
    qs.removeIndex(i1);
    // This test should not throw an exception if i2 was properly cleaned up.
    Index i3 = qs.createIndex("anotherIndex", "secType",
        SEPARATOR + "portfoliosInPartitionedRegion p, p.positions pos, pos.secType secType");
    assertNotNull(i3);
  }
Test for bug 46872, make sure we recover the index correctly if the cache.xml changes for a
persistent region.
geode-core/src/integrationTest/java/org/apache/geode/cache/query/functional/IndexCreationJUnitTest.java