View Javadoc

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