@Test
  public void testScannerSelection() throws IOException {
    Configuration conf = TEST_UTIL.getConfiguration();
    conf.setInt("hbase.hstore.compactionThreshold", 10000);
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TABLE)
      .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY_BYTES)
        .setBlockCacheEnabled(true).setBloomFilterType(bloomType).build())
      .build();

    RegionInfo info = RegionInfoBuilder.newBuilder(TABLE).build();
    HRegion region =
      HBaseTestingUtil.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(), conf, tableDescriptor);

    for (int iFile = 0; iFile < NUM_FILES; ++iFile) {
      for (int iRow = 0; iRow < NUM_ROWS; ++iRow) {
        Put put = new Put(Bytes.toBytes("row" + iRow));
        for (int iCol = 0; iCol < NUM_COLS_PER_ROW; ++iCol) {
          put.addColumn(FAMILY_BYTES, Bytes.toBytes("col" + iCol),
            Bytes.toBytes("value" + iFile + "_" + iRow + "_" + iCol));
        }
        region.put(put);
      }
      region.flush(true);
    }

    Scan scan = new Scan().withStartRow(Bytes.toBytes("aaa")).withStopRow(Bytes.toBytes("aaz"));
    BlockCache cache = BlockCacheFactory.createBlockCache(conf);
    InternalScanner scanner = region.getScanner(scan);
    List<Cell> results = new ArrayList<>();
    while (scanner.next(results)) {
    }
    scanner.close();
    assertEquals(0, results.size());
    if (cache instanceof LruBlockCache) {
      Set<String> accessedFiles = ((LruBlockCache) cache).getCachedFileNamesForTest();
      assertEquals(expectedCount, accessedFiles.size());
    }
    HBaseTestingUtil.closeRegionAndWAL(region);
  }
Test the optimization that does not scan files where all key ranges are excluded.
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestScannerSelectionUsingKeyRange.java