@SuppressWarnings("unchecked")
 public void checkRangeSearch(
     IIndexTestContext ctx,
     ITupleReference lowKey,
     ITupleReference highKey,
     boolean lowKeyInclusive,
     boolean highKeyInclusive)
     throws Exception {
   if (LOGGER.isLoggable(Level.INFO)) {
     LOGGER.info("Testing Range Search.");
   }
   MultiComparator lowKeyCmp =
       BTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), lowKey);
   MultiComparator highKeyCmp =
       BTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), highKey);
   IIndexCursor searchCursor = ctx.getIndexAccessor().createSearchCursor(false);
   RangePredicate rangePred =
       new RangePredicate(
           lowKey, highKey, lowKeyInclusive, highKeyInclusive, lowKeyCmp, highKeyCmp);
   ctx.getIndexAccessor().search(searchCursor, rangePred);
   // Get the subset of elements from the expected set within given key
   // range.
   CheckTuple lowKeyCheck =
       createCheckTupleFromTuple(lowKey, ctx.getFieldSerdes(), lowKeyCmp.getKeyFieldCount());
   CheckTuple highKeyCheck =
       createCheckTupleFromTuple(highKey, ctx.getFieldSerdes(), highKeyCmp.getKeyFieldCount());
   SortedSet<CheckTuple> expectedSubset = null;
   if (lowKeyCmp.getKeyFieldCount() < ctx.getKeyFieldCount()
       || highKeyCmp.getKeyFieldCount() < ctx.getKeyFieldCount()) {
     // Searching on a key prefix (low key or high key or both).
     expectedSubset =
         getPrefixExpectedSubset(
             (TreeSet<CheckTuple>) ctx.getCheckTuples(), lowKeyCheck, highKeyCheck);
   } else {
     // Searching on all key fields.
     expectedSubset =
         ((TreeSet<CheckTuple>) ctx.getCheckTuples())
             .subSet(lowKeyCheck, lowKeyInclusive, highKeyCheck, highKeyInclusive);
   }
   Iterator<CheckTuple> checkIter = expectedSubset.iterator();
   int actualCount = 0;
   try {
     while (searchCursor.hasNext()) {
       if (!checkIter.hasNext()) {
         fail(
             "Range search returned more answers than expected.\nExpected: "
                 + expectedSubset.size());
       }
       searchCursor.next();
       CheckTuple expectedTuple = checkIter.next();
       ITupleReference tuple = searchCursor.getTuple();
       compareActualAndExpected(tuple, expectedTuple, ctx.getFieldSerdes());
       actualCount++;
     }
     if (actualCount < expectedSubset.size()) {
       fail(
           "Range search returned fewer answers than expected.\nExpected: "
               + expectedSubset.size()
               + "\nActual  : "
               + actualCount);
     }
   } finally {
     searchCursor.close();
   }
 }