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