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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org
.apache
.hadoop
.hbase
.wal
;
20 import static org
.junit
.Assert
.assertEquals
;
21 import static org
.junit
.Assert
.assertTrue
;
23 import java
.util
.Arrays
;
24 import java
.util
.List
;
25 import java
.util
.NavigableMap
;
26 import java
.util
.TreeMap
;
27 import org
.apache
.hadoop
.fs
.Path
;
28 import org
.apache
.hadoop
.hbase
.Cell
;
29 import org
.apache
.hadoop
.hbase
.HBaseTestingUtil
;
30 import org
.apache
.hadoop
.hbase
.KeyValue
;
31 import org
.apache
.hadoop
.hbase
.TableName
;
32 import org
.apache
.hadoop
.hbase
.client
.RegionInfo
;
33 import org
.apache
.hadoop
.hbase
.client
.RegionInfoBuilder
;
34 import org
.apache
.hadoop
.hbase
.regionserver
.MultiVersionConcurrencyControl
;
35 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
37 @SuppressWarnings("checkstyle:innerassignment")
38 public class CompressedWALTestBase
{
40 protected final static HBaseTestingUtil TEST_UTIL
= new HBaseTestingUtil();
42 static final byte[] VALUE
;
44 // 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597
45 VALUE
= new byte[1+1+2+3+5+8+13+21+34+55+89+144+233+377+610+987+1597];
47 Arrays
.fill(VALUE
, off
, (off
+=1), (byte)'A');
48 Arrays
.fill(VALUE
, off
, (off
+=1), (byte)'B');
49 Arrays
.fill(VALUE
, off
, (off
+=2), (byte)'C');
50 Arrays
.fill(VALUE
, off
, (off
+=3), (byte)'D');
51 Arrays
.fill(VALUE
, off
, (off
+=5), (byte)'E');
52 Arrays
.fill(VALUE
, off
, (off
+=8), (byte)'F');
53 Arrays
.fill(VALUE
, off
, (off
+=13), (byte)'G');
54 Arrays
.fill(VALUE
, off
, (off
+=21), (byte)'H');
55 Arrays
.fill(VALUE
, off
, (off
+=34), (byte)'I');
56 Arrays
.fill(VALUE
, off
, (off
+=55), (byte)'J');
57 Arrays
.fill(VALUE
, off
, (off
+=89), (byte)'K');
58 Arrays
.fill(VALUE
, off
, (off
+=144), (byte)'L');
59 Arrays
.fill(VALUE
, off
, (off
+=233), (byte)'M');
60 Arrays
.fill(VALUE
, off
, (off
+=377), (byte)'N');
61 Arrays
.fill(VALUE
, off
, (off
+=610), (byte)'O');
62 Arrays
.fill(VALUE
, off
, (off
+=987), (byte)'P');
63 Arrays
.fill(VALUE
, off
, (off
+=1597), (byte)'Q');
66 public void doTest(TableName tableName
) throws Exception
{
67 NavigableMap
<byte[], Integer
> scopes
= new TreeMap
<>(Bytes
.BYTES_COMPARATOR
);
68 scopes
.put(tableName
.getName(), 0);
69 RegionInfo regionInfo
= RegionInfoBuilder
.newBuilder(tableName
).build();
70 final int total
= 1000;
71 final byte[] row
= Bytes
.toBytes("row");
72 final byte[] family
= Bytes
.toBytes("family");
73 final byte[] value
= VALUE
;
74 final WALFactory wals
=
75 new WALFactory(TEST_UTIL
.getConfiguration(), tableName
.getNameAsString());
78 final WAL wal
= wals
.getWAL(regionInfo
);
80 MultiVersionConcurrencyControl mvcc
= new MultiVersionConcurrencyControl();
82 for (int i
= 0; i
< total
; i
++) {
83 WALEdit kvs
= new WALEdit();
84 kvs
.add(new KeyValue(row
, family
, Bytes
.toBytes(i
), value
));
85 wal
.appendData(regionInfo
, new WALKeyImpl(regionInfo
.getEncodedNameAsBytes(), tableName
,
86 System
.currentTimeMillis(), mvcc
, scopes
), kvs
);
89 final Path walPath
= AbstractFSWALProvider
.getCurrentFileName(wal
);
92 // Confirm the WAL can be read back
93 WAL
.Reader reader
= wals
.createReader(TEST_UTIL
.getTestFileSystem(), walPath
);
95 WAL
.Entry entry
= new WAL
.Entry();
96 while (reader
.next(entry
) != null) {
98 List
<Cell
> cells
= entry
.getEdit().getCells();
99 assertTrue("Should be one KV per WALEdit", cells
.size() == 1);
100 for (Cell cell
: cells
) {
101 assertTrue("Incorrect row", Bytes
.equals(cell
.getRowArray(), cell
.getRowOffset(),
102 cell
.getRowLength(), row
, 0, row
.length
));
103 assertTrue("Incorrect family", Bytes
.equals(cell
.getFamilyArray(), cell
.getFamilyOffset(),
104 cell
.getFamilyLength(), family
, 0, family
.length
));
105 assertTrue("Incorrect value", Bytes
.equals(cell
.getValueArray(), cell
.getValueOffset(),
106 cell
.getValueLength(), value
, 0, value
.length
));
109 assertEquals("Should have read back as many KVs as written", total
, count
);