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.testclassification.SmallTests;
27 import org.apache.hadoop.hbase.util.Bytes;
28 import org.junit.experimental.categories.Category;
29
30 @Category(SmallTests.class)
31 public class TestKeyValueScanFixture extends TestCase {
32
33
34 public void testKeyValueScanFixture() throws IOException {
35 KeyValue kvs[] = new KeyValue[]{
36 KeyValueTestUtil.create("RowA", "family", "qf1",
37 1, KeyValue.Type.Put, "value-1"),
38 KeyValueTestUtil.create("RowA", "family", "qf2",
39 1, KeyValue.Type.Put, "value-2"),
40 KeyValueTestUtil.create("RowB", "family", "qf1",
41 10, KeyValue.Type.Put, "value-10")
42 };
43 KeyValueScanner scan = new KeyValueScanFixture(
44 KeyValue.COMPARATOR, kvs);
45
46 KeyValue kv = KeyValue.createFirstOnRow(Bytes.toBytes("RowA"));
47
48 assertTrue(scan.seek(kv));
49 KeyValue res = scan.peek();
50 assertEquals(kvs[0], res);
51
52 kv = KeyValue.createFirstOnRow(Bytes.toBytes("RowB"));
53 assertTrue(scan.seek(kv));
54 res = scan.peek();
55 assertEquals(kvs[2], res);
56
57
58 kv = KeyValue.createFirstOnRow(Bytes.toBytes("RowA"));
59 assertTrue(scan.seek(kv));
60 assertEquals(kvs[0], scan.peek());
61 assertEquals(kvs[0], scan.next());
62 assertEquals(kvs[1], scan.peek());
63 assertEquals(kvs[1], scan.next());
64 assertEquals(kvs[2], scan.peek());
65 assertEquals(kvs[2], scan.next());
66 assertEquals(null, scan.peek());
67 assertEquals(null, scan.next());
68 }
69
70 }
71