HBASE-23825 Increment proto conversion is broken

This commit is contained in:
Abhishek Singh Chouhan 2020-02-10 19:24:21 -08:00
parent 942bb77d84
commit b25071c679
2 changed files with 44 additions and 3 deletions

View File

@ -65,7 +65,7 @@ public final class HBaseZeroCopyByteString extends LiteralByteString {
* @return byte[] representation
*/
public static byte[] zeroCopyGetBytes(final ByteString buf) {
if (buf instanceof LiteralByteString) {
if (buf.getClass().equals(LiteralByteString.class)) {
return ((LiteralByteString) buf).bytes;
}
// In case it's BoundedByteString

View File

@ -21,10 +21,12 @@ package org.apache.hadoop.hbase.protobuf;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import org.apache.hadoop.hbase.util.ByteStringer;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Append;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
@ -38,6 +40,8 @@ import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.Col
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.DeleteType;
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.MutationType;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameBytesPair;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ByteStringer;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@ -220,6 +224,43 @@ public class TestProtobufUtil {
ProtobufUtil.toMutation(increment, MutationProto.newBuilder(), HConstants.NO_NONCE));
}
@Test
public void testIncrementRequestConversion() throws Exception {
Increment inc = new Increment(Bytes.toBytes("row1"));
inc.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("q1"), 10);
inc.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("q2"), 20);
inc.addColumn(Bytes.toBytes("f2"), Bytes.toBytes("q3"), 30);
MutationProto proto =
ProtobufUtil.toMutation(inc, MutationProto.newBuilder(), HConstants.NO_NONCE);
Increment deSerializedIncrement = ProtobufUtil.toIncrement(proto, null);
List<Cell> cellList = deSerializedIncrement.getFamilyCellMap().get(Bytes.toBytes("f1"));
Collections.sort(cellList, KeyValue.COMPARATOR);
Cell cell0 = inc.getFamilyCellMap().get(Bytes.toBytes("f1")).get(0);
Cell cell1 = inc.getFamilyCellMap().get(Bytes.toBytes("f2")).get(0);
// We do not serialize TS for increment, hence need to compare parts of cell individually
// Compare cell0
assertEquals(Bytes.compareTo(cell0.getRowArray(), cell0.getRowOffset(), cell0.getRowLength(),
cellList.get(0).getRowArray(), cellList.get(0).getRowOffset(),
cellList.get(0).getRowLength()), 0);
assertEquals(Bytes.compareTo(cell0.getQualifierArray(), cell0.getQualifierOffset(),
cell0.getQualifierLength(), cellList.get(0).getQualifierArray(),
cellList.get(0).getQualifierOffset(), cellList.get(0).getQualifierLength()), 0);
assertEquals(Bytes.compareTo(cell0.getValueArray(), cell0.getValueOffset(),
cell0.getValueLength(), cellList.get(0).getValueArray(), cellList.get(0).getValueOffset(),
cellList.get(0).getValueLength()), 0);
// Compare cell1
Cell deSerCell = deSerializedIncrement.getFamilyCellMap().get(Bytes.toBytes("f2")).get(0);
assertEquals(Bytes.compareTo(cell1.getRowArray(), cell1.getRowOffset(), cell1.getRowLength(),
deSerCell.getRowArray(), deSerCell.getRowOffset(), deSerCell.getRowLength()), 0);
assertEquals(Bytes.compareTo(cell1.getQualifierArray(), cell1.getQualifierOffset(),
cell1.getQualifierLength(), deSerCell.getQualifierArray(), deSerCell.getQualifierOffset(),
deSerCell.getQualifierLength()), 0);
assertEquals(
Bytes.compareTo(cell1.getValueArray(), cell1.getValueOffset(), cell1.getValueLength(),
deSerCell.getValueArray(), deSerCell.getValueOffset(), deSerCell.getValueLength()),
0);
}
/**
* Test Put Mutate conversions.
*