1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.regionserver;
21
22 import java.io.IOException;
23
24 import junit.framework.TestCase;
25 import org.apache.hadoop.hbase.*;
26 import org.apache.hadoop.hbase.util.Bytes;
27 import org.junit.experimental.categories.Category;
28
29 @Category(SmallTests.class)
30 public class TestKeyValueScanFixture extends TestCase {
31
32
33 public void testKeyValueScanFixture() throws IOException {
34 KeyValue kvs[] = new KeyValue[]{
35 KeyValueTestUtil.create("RowA", "family", "qf1",
36 1, KeyValue.Type.Put, "value-1"),
37 KeyValueTestUtil.create("RowA", "family", "qf2",
38 1, KeyValue.Type.Put, "value-2"),
39 KeyValueTestUtil.create("RowB", "family", "qf1",
40 10, KeyValue.Type.Put, "value-10")
41 };
42 KeyValueScanner scan = new KeyValueScanFixture(
43 KeyValue.COMPARATOR, kvs);
44
45 KeyValue kv = KeyValue.createFirstOnRow(Bytes.toBytes("RowA"));
46
47 assertTrue(scan.seek(kv));
48 KeyValue res = scan.peek();
49 assertEquals(kvs[0], res);
50
51 kv = KeyValue.createFirstOnRow(Bytes.toBytes("RowB"));
52 assertTrue(scan.seek(kv));
53 res = scan.peek();
54 assertEquals(kvs[2], res);
55
56
57 kv = KeyValue.createFirstOnRow(Bytes.toBytes("RowA"));
58 assertTrue(scan.seek(kv));
59 assertEquals(kvs[0], scan.peek());
60 assertEquals(kvs[0], scan.next());
61 assertEquals(kvs[1], scan.peek());
62 assertEquals(kvs[1], scan.next());
63 assertEquals(kvs[2], scan.peek());
64 assertEquals(kvs[2], scan.next());
65 assertEquals(null, scan.peek());
66 assertEquals(null, scan.next());
67 }
68
69 }
70