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  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      // should seek to this:
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      // ensure we pull things out properly:
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