View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.codec.keyvalue;
20  
21  import java.nio.ByteBuffer;
22  import java.util.Collection;
23  import java.util.List;
24  
25  import org.apache.hadoop.hbase.KeyValue;
26  import org.apache.hadoop.hbase.KeyValueTestUtil;
27  import org.apache.hadoop.hbase.codec.prefixtree.row.TestRowData;
28  import org.apache.hadoop.hbase.codec.prefixtree.row.data.TestRowDataRandomKeyValuesWithTags;
29  import org.apache.hadoop.hbase.codec.prefixtree.row.data.TestRowDataTrivialWithTags;
30  import org.junit.Assert;
31  import org.junit.Test;
32  import org.junit.runner.RunWith;
33  import org.junit.runners.Parameterized;
34  import org.junit.runners.Parameterized.Parameters;
35  
36  @RunWith(Parameterized.class)
37  public class TestKeyValueTool {
38  
39    @Parameters
40    public static Collection<Object[]> parameters() {
41      return new TestRowData.InMemory().getAllAsObjectArray();
42    }
43  
44    private TestRowData rows;
45  
46    public TestKeyValueTool(TestRowData testRows) {
47      this.rows = testRows;
48    }
49  
50    @Test
51    public void testRoundTripToBytes() {
52      if(rows instanceof TestRowDataTrivialWithTags || rows instanceof TestRowDataRandomKeyValuesWithTags) {
53        return;
54      }
55      List<KeyValue> kvs = rows.getInputs();
56      ByteBuffer bb = KeyValueTestUtil.toByteBufferAndRewind(kvs, false);
57      List<KeyValue> roundTrippedKvs = KeyValueTestUtil.rewindThenToList(bb, false, false);
58      Assert.assertArrayEquals(kvs.toArray(), roundTrippedKvs.toArray());
59    }
60  }