001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.regionserver; 019 020import java.io.IOException; 021import junit.framework.TestCase; 022import org.apache.hadoop.hbase.Cell; 023import org.apache.hadoop.hbase.CellComparator; 024import org.apache.hadoop.hbase.HBaseClassTestRule; 025import org.apache.hadoop.hbase.KeyValue; 026import org.apache.hadoop.hbase.KeyValueTestUtil; 027import org.apache.hadoop.hbase.KeyValueUtil; 028import org.apache.hadoop.hbase.testclassification.RegionServerTests; 029import org.apache.hadoop.hbase.testclassification.SmallTests; 030import org.apache.hadoop.hbase.util.Bytes; 031import org.junit.ClassRule; 032import org.junit.experimental.categories.Category; 033 034@Category({RegionServerTests.class, SmallTests.class}) 035public class TestKeyValueScanFixture extends TestCase { 036 037 @ClassRule 038 public static final HBaseClassTestRule CLASS_RULE = 039 HBaseClassTestRule.forClass(TestKeyValueScanFixture.class); 040 041 042 public void testKeyValueScanFixture() throws IOException { 043 KeyValue kvs[] = new KeyValue[]{ 044 KeyValueTestUtil.create("RowA", "family", "qf1", 045 1, KeyValue.Type.Put, "value-1"), 046 KeyValueTestUtil.create("RowA", "family", "qf2", 047 1, KeyValue.Type.Put, "value-2"), 048 KeyValueTestUtil.create("RowB", "family", "qf1", 049 10, KeyValue.Type.Put, "value-10") 050 }; 051 KeyValueScanner scan = new KeyValueScanFixture(CellComparator.getInstance(), kvs); 052 053 KeyValue kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowA")); 054 // should seek to this: 055 assertTrue(scan.seek(kv)); 056 Cell res = scan.peek(); 057 assertEquals(kvs[0], res); 058 059 kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowB")); 060 assertTrue(scan.seek(kv)); 061 res = scan.peek(); 062 assertEquals(kvs[2], res); 063 064 // ensure we pull things out properly: 065 kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowA")); 066 assertTrue(scan.seek(kv)); 067 assertEquals(kvs[0], scan.peek()); 068 assertEquals(kvs[0], scan.next()); 069 assertEquals(kvs[1], scan.peek()); 070 assertEquals(kvs[1], scan.next()); 071 assertEquals(kvs[2], scan.peek()); 072 assertEquals(kvs[2], scan.next()); 073 assertEquals(null, scan.peek()); 074 assertEquals(null, scan.next()); 075 } 076 077} 078