@Test
  public void testIndexXmlCreation() throws Exception {
    CacheCreation cache = new CacheCreation();
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setScope(Scope.DISTRIBUTED_ACK);
    attrs.setDataPolicy(DataPolicy.REPLICATE);
    cache.createRegion("replicated", attrs);

    cache.getQueryService().createIndex("crIndex", "CR_ID", SEPARATOR + "replicated");
    cache.getQueryService().createHashIndex("hashIndex", "HASH_ID", SEPARATOR + "replicated");
    cache.getQueryService().createKeyIndex("primaryKeyIndex", "ID", SEPARATOR + "replicated");

    testXml(cache);

    Cache c = getCache();
    assertNotNull(c);
    QueryService qs = c.getQueryService();
    Collection<Index> indexes = qs.getIndexes();
    assertEquals(3, indexes.size());
    c.getQueryService().createIndex("crIndex2", "r.CR_ID_2", SEPARATOR + "replicated r");
    c.getQueryService().createIndex("rIndex", "r.R_ID",
        SEPARATOR + "replicated r, r.positions.values rv");

    File dir = new File(temporaryFolder.getRoot(), "XML_" + getGemFireVersion());
    dir.mkdirs();
    File file = new File(dir, "actual-" + getUniqueName() + ".xml");

    PrintWriter pw = new PrintWriter(new FileWriter(file), true);
    CacheXmlGenerator.generate(c, pw, getUseSchema(), getGemFireVersion());
    pw.close();

    // Get index info before closing cache.
    indexes = qs.getIndexes();

    c.close();
    GemFireCacheImpl.testCacheXml = file;
    assertTrue(c.isClosed());

    c = getCache();
    qs = c.getQueryService();
    Collection<Index> newIndexes = qs.getIndexes();
    assertEquals(5, newIndexes.size());

    Region r = c.getRegion(SEPARATOR + "replicated");
    for (int i = 0; i < 5; i++) {
      r.put(i, new TestObject(i));
    }

    // Validate to see, newly created indexes match the initial configuration
    for (Index index : indexes) {
      Index newIndex = qs.getIndex(r, index.getName());
      assertEquals("Index from clause is not same for index " + index.getName(),
          newIndex.getFromClause(), index.getFromClause());
      assertEquals("Index expression is not same for index " + index.getName(),
          newIndex.getIndexedExpression(), index.getIndexedExpression());
    }

    QueryObserverImpl observer = new QueryObserverImpl();
    QueryObserverHolder.setInstance(observer);
    SelectResults results =
        (SelectResults) qs.newQuery("select * from " + SEPARATOR + "replicated r where r.ID = 1")
            .execute();
    assertEquals(1, results.size());
    assertTrue(checkIndexUsed(observer, "primaryKeyIndex"));
    observer.reset();

    results =
        (SelectResults) qs.newQuery("select * from " + SEPARATOR + "replicated r where r.CR_ID = 1")
            .execute();
    assertEquals(2, results.size());
    assertTrue(checkIndexUsed(observer, "crIndex"));
    observer.reset();

    results =
        (SelectResults) qs
            .newQuery("select * from " + SEPARATOR + "replicated r where r.CR_ID_2 = 1").execute();
    assertEquals(2, results.size());
    assertTrue(checkIndexUsed(observer, "crIndex2"));
    observer.reset();

    results = (SelectResults) qs
        .newQuery(
            "select * from " + SEPARATOR + "replicated r, r.positions.values rv where r.R_ID > 1")
        .execute();
    assertEquals(3, results.size());
    assertTrue(checkIndexUsed(observer, "rIndex"));
    observer.reset();

    results =
        (SelectResults) qs
            .newQuery("select * from " + SEPARATOR + "replicated r where r.HASH_ID = 1").execute();
    assertEquals(1, results.size());
    assertTrue(checkIndexUsed(observer, "hashIndex"));
    observer.reset();
  }
Tests xml creation for indexes First creates 3 indexes and makes sure the cache creates all 3
Creates a 4th through the api and writes out the xml Restarts the cache with the new xml Makes
sure the new cache has the 4 indexes
geode-core/src/distributedTest/java/org/apache/geode/cache30/CacheXml80DUnitTest.java