1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }