|
45 | 45 | import org.apache.hadoop.fs.FileSystem; |
46 | 46 | import org.apache.hadoop.fs.Path; |
47 | 47 | import org.apache.hadoop.hbase.ArrayBackedTag; |
| 48 | +import org.apache.hadoop.hbase.ByteBufferKeyValue; |
48 | 49 | import org.apache.hadoop.hbase.Cell; |
49 | 50 | import org.apache.hadoop.hbase.CellComparatorImpl; |
50 | 51 | import org.apache.hadoop.hbase.CellUtil; |
|
60 | 61 | import org.apache.hadoop.hbase.Tag; |
61 | 62 | import org.apache.hadoop.hbase.io.ByteBuffAllocator; |
62 | 63 | import org.apache.hadoop.hbase.io.compress.Compression; |
| 64 | +import org.apache.hadoop.hbase.io.encoding.DataBlockEncoder; |
| 65 | +import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding; |
63 | 66 | import org.apache.hadoop.hbase.io.hfile.HFile.Reader; |
64 | 67 | import org.apache.hadoop.hbase.io.hfile.HFile.Writer; |
65 | 68 | import org.apache.hadoop.hbase.nio.ByteBuff; |
66 | 69 | import org.apache.hadoop.hbase.regionserver.StoreFileWriter; |
67 | 70 | import org.apache.hadoop.hbase.testclassification.IOTests; |
68 | 71 | import org.apache.hadoop.hbase.testclassification.SmallTests; |
| 72 | +import org.apache.hadoop.hbase.util.ByteBufferUtils; |
69 | 73 | import org.apache.hadoop.hbase.util.Bytes; |
70 | 74 | import org.apache.hadoop.io.Writable; |
71 | 75 | import org.junit.Assert; |
@@ -760,5 +764,40 @@ public void testGetShortMidpoint() { |
760 | 764 | 0, expectedArray.length); |
761 | 765 | } |
762 | 766 |
|
| 767 | + @Test |
| 768 | + public void testDBEShipped() throws IOException { |
| 769 | + for (DataBlockEncoding encoding : DataBlockEncoding.values()) { |
| 770 | + DataBlockEncoder encoder = encoding.getEncoder(); |
| 771 | + if (encoder == null) { |
| 772 | + continue; |
| 773 | + } |
| 774 | + Path f = new Path(ROOT_DIR, testName.getMethodName() + "_" + encoding); |
| 775 | + HFileContext context = new HFileContextBuilder() |
| 776 | + .withIncludesTags(false) |
| 777 | + .withDataBlockEncoding(encoding).build(); |
| 778 | + HFileWriterImpl writer = (HFileWriterImpl) HFile.getWriterFactory(conf, cacheConf) |
| 779 | + .withPath(fs, f).withFileContext(context).create(); |
| 780 | + |
| 781 | + KeyValue kv = new KeyValue(Bytes.toBytes("testkey1"), Bytes.toBytes("family"), |
| 782 | + Bytes.toBytes("qual"), Bytes.toBytes("testvalue")); |
| 783 | + KeyValue kv2 = new KeyValue(Bytes.toBytes("testkey2"), Bytes.toBytes("family"), |
| 784 | + Bytes.toBytes("qual"), Bytes.toBytes("testvalue")); |
| 785 | + KeyValue kv3 = new KeyValue(Bytes.toBytes("testkey3"), Bytes.toBytes("family"), |
| 786 | + Bytes.toBytes("qual"), Bytes.toBytes("testvalue")); |
| 787 | + |
| 788 | + ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer()); |
| 789 | + ByteBuffer buffer2 = ByteBuffer.wrap(kv2.getBuffer()); |
| 790 | + ByteBuffer buffer3 = ByteBuffer.wrap(kv3.getBuffer()); |
| 791 | + |
| 792 | + writer.append(new ByteBufferKeyValue(buffer, 0, buffer.remaining())); |
| 793 | + writer.beforeShipped(); |
| 794 | + |
| 795 | + // pollute first cell's backing ByteBuffer |
| 796 | + ByteBufferUtils.copyFromBufferToBuffer(buffer3, buffer); |
| 797 | + |
| 798 | + // write another cell, if DBE not Shipped, test will fail |
| 799 | + writer.append(new ByteBufferKeyValue(buffer2, 0, buffer2.remaining())); |
| 800 | + writer.close(); |
| 801 | + } |
| 802 | + } |
763 | 803 | } |
764 | | - |
|
0 commit comments