2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.regionserver
;
20 import java
.io
.IOException
;
21 import junit
.framework
.TestCase
;
22 import org
.apache
.hadoop
.hbase
.Cell
;
23 import org
.apache
.hadoop
.hbase
.CellComparator
;
24 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
25 import org
.apache
.hadoop
.hbase
.KeyValue
;
26 import org
.apache
.hadoop
.hbase
.KeyValueTestUtil
;
27 import org
.apache
.hadoop
.hbase
.KeyValueUtil
;
28 import org
.apache
.hadoop
.hbase
.testclassification
.RegionServerTests
;
29 import org
.apache
.hadoop
.hbase
.testclassification
.SmallTests
;
30 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
31 import org
.junit
.ClassRule
;
32 import org
.junit
.experimental
.categories
.Category
;
34 @Category({RegionServerTests
.class, SmallTests
.class})
35 public class TestKeyValueScanFixture
extends TestCase
{
38 public static final HBaseClassTestRule CLASS_RULE
=
39 HBaseClassTestRule
.forClass(TestKeyValueScanFixture
.class);
42 public void testKeyValueScanFixture() throws IOException
{
43 KeyValue kvs
[] = new KeyValue
[]{
44 KeyValueTestUtil
.create("RowA", "family", "qf1",
45 1, KeyValue
.Type
.Put
, "value-1"),
46 KeyValueTestUtil
.create("RowA", "family", "qf2",
47 1, KeyValue
.Type
.Put
, "value-2"),
48 KeyValueTestUtil
.create("RowB", "family", "qf1",
49 10, KeyValue
.Type
.Put
, "value-10")
51 KeyValueScanner scan
= new KeyValueScanFixture(CellComparator
.getInstance(), kvs
);
53 KeyValue kv
= KeyValueUtil
.createFirstOnRow(Bytes
.toBytes("RowA"));
54 // should seek to this:
55 assertTrue(scan
.seek(kv
));
56 Cell res
= scan
.peek();
57 assertEquals(kvs
[0], res
);
59 kv
= KeyValueUtil
.createFirstOnRow(Bytes
.toBytes("RowB"));
60 assertTrue(scan
.seek(kv
));
62 assertEquals(kvs
[2], res
);
64 // ensure we pull things out properly:
65 kv
= KeyValueUtil
.createFirstOnRow(Bytes
.toBytes("RowA"));
66 assertTrue(scan
.seek(kv
));
67 assertEquals(kvs
[0], scan
.peek());
68 assertEquals(kvs
[0], scan
.next());
69 assertEquals(kvs
[1], scan
.peek());
70 assertEquals(kvs
[1], scan
.next());
71 assertEquals(kvs
[2], scan
.peek());
72 assertEquals(kvs
[2], scan
.next());
73 assertEquals(null, scan
.peek());
74 assertEquals(null, scan
.next());