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(KeyValue.COMPARATOR, kvs);
48  
49      KeyValue kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowA"));
50      // should seek to this:
51      assertTrue(scan.seek(kv));
52      Cell res = scan.peek();
53      assertEquals(kvs[0], res);
54  
55      kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowB"));
56      assertTrue(scan.seek(kv));
57      res = scan.peek();
58      assertEquals(kvs[2], res);
59  
60      // ensure we pull things out properly:
61      kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowA"));
62      assertTrue(scan.seek(kv));
63      assertEquals(kvs[0], scan.peek());
64      assertEquals(kvs[0], scan.next());
65      assertEquals(kvs[1], scan.peek());
66      assertEquals(kvs[1], scan.next());
67      assertEquals(kvs[2], scan.peek());
68      assertEquals(kvs[2], scan.next());
69      assertEquals(null, scan.peek());
70      assertEquals(null, scan.next());
71    }
72  
73  }
74