1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.io.hfile;
22
23 import java.io.IOException;
24 import java.net.URL;
25
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.fs.FileSystem;
28 import org.apache.hadoop.fs.Path;
29 import org.apache.hadoop.hbase.HBaseTestingUtility;
30 import org.apache.hadoop.hbase.util.Bytes;
31
32 import org.junit.Before;
33 import org.junit.Test;
34
35 import static org.junit.Assert.*;
36
37 public class TestHFileReaderV1 {
38
39 private static final HBaseTestingUtility TEST_UTIL =
40 new HBaseTestingUtility();
41
42 private Configuration conf;
43 private FileSystem fs;
44
45 private static final int N = 1000;
46
47 @Before
48 public void setUp() throws IOException {
49 conf = TEST_UTIL.getConfiguration();
50 fs = FileSystem.get(conf);
51 }
52
53 @Test
54 public void testReadingExistingVersion1HFile() throws IOException {
55 URL url = TestHFileReaderV1.class.getResource(
56 "8e8ab58dcf39412da19833fcd8f687ac");
57 Path existingHFilePath = new Path(url.getPath());
58 HFile.Reader reader =
59 HFile.createReader(fs, existingHFilePath, new CacheConfig(conf));
60 reader.loadFileInfo();
61 FixedFileTrailer trailer = reader.getTrailer();
62
63 assertEquals(N, reader.getEntries());
64 assertEquals(N, trailer.getEntryCount());
65 assertEquals(1, trailer.getVersion());
66 assertEquals(Compression.Algorithm.GZ, trailer.getCompressionCodec());
67
68 for (boolean pread : new boolean[] { false, true }) {
69 int totalDataSize = 0;
70 int n = 0;
71
72 HFileScanner scanner = reader.getScanner(false, pread);
73 assertTrue(scanner.seekTo());
74 do {
75 totalDataSize += scanner.getKey().limit() + scanner.getValue().limit()
76 + Bytes.SIZEOF_INT * 2;
77 ++n;
78 } while (scanner.next());
79
80
81 totalDataSize += 8 * trailer.getDataIndexCount();
82
83 assertEquals(N, n);
84 assertEquals(trailer.getTotalUncompressedBytes(), totalDataSize);
85 }
86 reader.close();
87 }
88
89 }