private List<Cell> filterExpectedResults(Set<String> qualSet, byte[] startRow, byte[] endRow,
    int maxVersions) {
    final List<Cell> filteredKVs = new ArrayList<>();
    final Map<String, Integer> verCount = new HashMap<>();
    for (Cell kv : expectedKVs) {
      if (
        startRow.length > 0 && Bytes.compareTo(kv.getRowArray(), kv.getRowOffset(),
          kv.getRowLength(), startRow, 0, startRow.length) < 0
      ) {
        continue;
      }

      // In this unit test the end row is always inclusive.
      if (
        endRow.length > 0 && Bytes.compareTo(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(),
          endRow, 0, endRow.length) > 0
      ) {
        continue;
      }

      if (
        !qualSet.isEmpty() && (!CellUtil.matchingFamily(kv, FAMILY_BYTES)
          || !qualSet.contains(Bytes.toString(CellUtil.cloneQualifier(kv))))
      ) {
        continue;
      }

      final String rowColStr = Bytes.toStringBinary(CellUtil.cloneRow(kv)) + "/"
        + Bytes.toStringBinary(CellUtil.cloneFamily(kv)) + ":"
        + Bytes.toStringBinary(CellUtil.cloneQualifier(kv));
      final Integer curNumVer = verCount.get(rowColStr);
      final int newNumVer = curNumVer != null ? (curNumVer + 1) : 1;
      if (newNumVer <= maxVersions) {
        filteredKVs.add(kv);
        verCount.put(rowColStr, newNumVer);
      }
    }

    return filteredKVs;
  }
Disable this when this test fails hopelessly and you need to debug a simpler case.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSeekOptimizations.java