You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ac...@apache.org on 2020/02/12 01:07:53 UTC
[hbase] branch branch-1 updated: HBASE-23825 Increment proto
conversion is broken
This is an automated email from the ASF dual-hosted git repository.
achouhan pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-1 by this push:
new b25071c HBASE-23825 Increment proto conversion is broken
b25071c is described below
commit b25071c6797d7f1bcecb353f4188b109e4a2652a
Author: Abhishek Singh Chouhan <ab...@gmail.com>
AuthorDate: Mon Feb 10 19:24:21 2020 -0800
HBASE-23825 Increment proto conversion is broken
---
.../google/protobuf/HBaseZeroCopyByteString.java | 2 +-
.../hadoop/hbase/protobuf/TestProtobufUtil.java | 45 +++++++++++++++++++++-
2 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/hbase-protocol/src/main/java/com/google/protobuf/HBaseZeroCopyByteString.java b/hbase-protocol/src/main/java/com/google/protobuf/HBaseZeroCopyByteString.java
index d0acd4c..7e7009f 100644
--- a/hbase-protocol/src/main/java/com/google/protobuf/HBaseZeroCopyByteString.java
+++ b/hbase-protocol/src/main/java/com/google/protobuf/HBaseZeroCopyByteString.java
@@ -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
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java
index 7710cc3..c3e6279 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java
@@ -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.
*