Example #1
0
  @Test
  public void testReadingExistingVersion1HFile() throws IOException {
    URL url = TestHFileReaderV1.class.getResource("8e8ab58dcf39412da19833fcd8f687ac");
    Path existingHFilePath = new Path(url.getPath());
    HFile.Reader reader = HFile.createReader(fs, existingHFilePath, new CacheConfig(conf));
    reader.loadFileInfo();
    FixedFileTrailer trailer = reader.getTrailer();

    assertEquals(N, reader.getEntries());
    assertEquals(N, trailer.getEntryCount());
    assertEquals(1, trailer.getMajorVersion());
    assertEquals(Compression.Algorithm.GZ, trailer.getCompressionCodec());

    for (boolean pread : new boolean[] {false, true}) {
      int totalDataSize = 0;
      int n = 0;

      HFileScanner scanner = reader.getScanner(false, pread);
      assertTrue(scanner.seekTo());
      do {
        totalDataSize +=
            scanner.getKey().limit() + scanner.getValue().limit() + Bytes.SIZEOF_INT * 2;
        ++n;
      } while (scanner.next());

      // Add magic record sizes, one per data block.
      totalDataSize += 8 * trailer.getDataIndexCount();

      assertEquals(N, n);
      assertEquals(trailer.getTotalUncompressedBytes(), totalDataSize);
    }
    reader.close();
  }