@Test
  public void testCompactMapIndexUsageManyKeysWithVariousValueTypes() throws Exception {
    QueryService qs = CacheUtils.getQueryService();
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    int ID = 1;
    for (; ID <= 30; ++ID) {
      TestObject object = new TestObject(ID);
      testRgn.put(ID, object);
    }
    String[] queries =
        {"SELECT DISTINCT * FROM " + SEPARATOR
            + "testRgn itr1  WHERE itr1.testFields['string'] = '1'",
            "SELECT DISTINCT * FROM " + SEPARATOR
                + "testRgn itr1  WHERE itr1.testFields['double'] > 1D",
            "SELECT DISTINCT * FROM " + SEPARATOR
                + "testRgn itr1  WHERE itr1.testFields['integer'] > 1",
            "SELECT DISTINCT * FROM " + SEPARATOR
                + "testRgn itr1  WHERE itr1.testFields['long'] > 1L"};
    String[] queriesIndexNotUsed =
        {"SELECT DISTINCT * FROM " + SEPARATOR
            + "testRgn itr1  WHERE itr1.testFields.get('string') = '1'",
            "SELECT DISTINCT * FROM " + SEPARATOR
                + "testRgn itr1  WHERE itr1.testFields.get('double') > 1D",
            "SELECT DISTINCT * FROM " + SEPARATOR
                + "testRgn itr1  WHERE itr1.testFields.get('integer') > 1",
            "SELECT DISTINCT * FROM " + SEPARATOR
                + "testRgn itr1  WHERE itr1.testFields.get('long') > 1L"};
    Object[][] r = new Object[queries.length][2];

    qs = CacheUtils.getQueryService();

    // Execute Queries without Indexes
    for (int i = 0; i < queries.length; i++) {
      Query q = CacheUtils.getQueryService().newQuery(queries[i]);
      CacheUtils.getLogger().info("Executing query: " + queries[i]);
      r[i][0] = q.execute();
      CacheUtils.log("Executed query: " + queries[i]);
    }

    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "itr1.testFields['string']",
        SEPARATOR + "testRgn itr1");
    Index i2 = qs.createIndex("Index2", IndexType.FUNCTIONAL, "itr1.testFields['double']",
        SEPARATOR + "testRgn itr1");
    Index i3 = qs.createIndex("Index3", IndexType.FUNCTIONAL, "itr1.testFields['integer']",
        SEPARATOR + "testRgn itr1");
    Index i4 =
        qs.createIndex("Index4", IndexType.FUNCTIONAL, "itr1.testFields['long']",
            SEPARATOR + "testRgn itr1");
    Index i5 = qs.createIndex("Index5", IndexType.FUNCTIONAL, "itr1.testFields['complex']",
        SEPARATOR + "testRgn itr1");

    assertTrue(i1 instanceof CompactRangeIndex);

    // Execute Queries with Indexes
    for (int i = 0; i < queries.length; i++) {
      Query q = CacheUtils.getQueryService().newQuery(queries[i]);
      CacheUtils.getLogger().info("Executing query: " + queries[i]);
      QueryObserverImpl observer = new QueryObserverImpl();
      QueryObserverHolder.setInstance(observer);
      r[i][1] = q.execute();
      CacheUtils.log("Executing query: " + queries[i] + " with index created");
      if (!observer.isIndexesUsed) {
        fail("Index is NOT uesd");
      }
      Iterator itr = observer.indexesUsed.iterator();
      assertTrue(itr.hasNext());
      String temp = itr.next().toString();
      assertEquals(temp, "Index" + (i + 1));
    }
    StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
    ssOrrs.CompareQueryResultsWithoutAndWithIndexes(r, queries.length, queries);

    // Test queries index not used
    for (final String s : queriesIndexNotUsed) {
      Query q = CacheUtils.getQueryService().newQuery(s);
      CacheUtils.getLogger().info("Executing query: " + s);
      QueryObserverImpl observer = new QueryObserverImpl();
      QueryObserverHolder.setInstance(observer);
      CacheUtils.log("Executing query: " + s + " with index created");
      q.execute();
      assertFalse(observer.isIndexesUsed);
      Iterator itr = observer.indexesUsed.iterator();
      assertFalse(itr.hasNext());
    }
  }
Test to check if Region short cut method is used for querying, the Primary key index
utilization occurs or not
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/IndexUseJUnitTest.java