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 static org.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertTrue; 022 023import java.io.IOException; 024import org.apache.hadoop.hbase.Cell; 025import org.apache.hadoop.hbase.CellComparator; 026import org.apache.hadoop.hbase.KeyValue; 027import org.apache.hadoop.hbase.KeyValueTestUtil; 028import org.apache.hadoop.hbase.KeyValueUtil; 029import org.apache.hadoop.hbase.testclassification.RegionServerTests; 030import org.apache.hadoop.hbase.testclassification.SmallTests; 031import org.apache.hadoop.hbase.util.Bytes; 032import org.junit.jupiter.api.Tag; 033import org.junit.jupiter.api.Test; 034 035@Tag(RegionServerTests.TAG) 036@Tag(SmallTests.TAG) 037public class TestKeyValueScanFixture { 038 039 @Test 040 public void testKeyValueScanFixture() throws IOException { 041 KeyValue kvs[] = new KeyValue[] { 042 KeyValueTestUtil.create("RowA", "family", "qf1", 1, KeyValue.Type.Put, "value-1"), 043 KeyValueTestUtil.create("RowA", "family", "qf2", 1, KeyValue.Type.Put, "value-2"), 044 KeyValueTestUtil.create("RowB", "family", "qf1", 10, KeyValue.Type.Put, "value-10") }; 045 KeyValueScanner scan = new KeyValueScanFixture(CellComparator.getInstance(), kvs); 046 047 KeyValue kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowA")); 048 // should seek to this: 049 assertTrue(scan.seek(kv)); 050 Cell res = scan.peek(); 051 assertEquals(kvs[0], res); 052 053 kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowB")); 054 assertTrue(scan.seek(kv)); 055 res = scan.peek(); 056 assertEquals(kvs[2], res); 057 058 // ensure we pull things out properly: 059 kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowA")); 060 assertTrue(scan.seek(kv)); 061 assertEquals(kvs[0], scan.peek()); 062 assertEquals(kvs[0], scan.next()); 063 assertEquals(kvs[1], scan.peek()); 064 assertEquals(kvs[1], scan.next()); 065 assertEquals(kvs[2], scan.peek()); 066 assertEquals(kvs[2], scan.next()); 067 assertEquals(null, scan.peek()); 068 assertEquals(null, scan.next()); 069 } 070 071}