anoopsjohn commented on a change in pull request #2745:
URL: https://github.com/apache/hbase/pull/2745#discussion_r541831201
##########
File path:
hbase-client/src/test/java/org/apache/hadoop/hbase/shaded/protobuf/TestProtobufUtil.java
##########
@@ -479,4 +488,59 @@ public void testRegionLockInfo() {
+ "\"sharedLockCount\":0"
+ "}]", lockJson);
}
+
+ /**
+ * Test {@link ProtobufUtil#toCell(Cell, boolean)} and
+ * {@link ProtobufUtil#toCell(ExtendedCellBuilder, CellProtos.Cell,
boolean)} conversion
+ * methods when it contains tags and encode/decode tags is set to true.
+ */
+ @Test
+ public void testCellConversionWithTags() {
+
+ Cell cell = getCellWithTags();
+ CellProtos.Cell protoCell = ProtobufUtil.toCell(cell, true);
+ assertNotNull(protoCell);
+
+ Cell decodedCell = getCellFromProtoResult(protoCell, true);
+ List<Tag> decodedTags = PrivateCellUtil.getTags(decodedCell);
+ assertEquals(1, decodedTags.size());
+ Tag decodedTag = decodedTags.get(0);
+ assertEquals(TAG_TYPE, decodedTag.getType());
+ assertEquals(TAG_STR, Tag.getValueAsString(decodedTag));
+ }
+
+ private Cell getCellWithTags() {
+ Tag tag = new ArrayBackedTag(TAG_TYPE, TAG_STR);
+ ExtendedCellBuilder cellBuilder =
ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY);
+ cellBuilder.setRow(Bytes.toBytes("row1"));
+ cellBuilder.setFamily(Bytes.toBytes("f1"));
+ cellBuilder.setQualifier(Bytes.toBytes("q1"));
+ cellBuilder.setValue(Bytes.toBytes("value1"));
+ cellBuilder.setType(Cell.Type.Delete);
+ cellBuilder.setTags(Collections.singletonList(tag));
+ return cellBuilder.build();
+ }
+
+ private Cell getCellFromProtoResult(CellProtos.Cell protoCell, boolean
decodeTags) {
+ ExtendedCellBuilder decodedBuilder =
+ ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY);
+ return ProtobufUtil.toCell(decodedBuilder, protoCell, decodeTags);
+ }
+
+ /**
+ * Test {@link ProtobufUtil#toCell(Cell, boolean)} and
+ * {@link ProtobufUtil#toCell(ExtendedCellBuilder, CellProtos.Cell,
boolean)} conversion
+ * methods when it contains tags and encode/decode tags is set to false.
+ */
+ @Test
+ public void testCellConversionWithoutTags() {
+ Cell cell = getCellWithTags();
+ CellProtos.Cell protoCell =
+ ProtobufUtil.toCell(cell, false);
+ assertNotNull(protoCell);
+
+ Cell decodedCell = getCellFromProtoResult(protoCell, false);
Review comment:
One test is passing true while doing encoding and then passing true
while decoding and make sure tags come back
The other pass both as false and make sure no tags present in final decoded
cell. Good
What my request was to have a test case where the encode time will say
false. And then decode call pass true(if any tags in serialized form decode
that) and assert still no tags are present in final decoded Cell. The second
test case will pass even if tomorrow the encode logic changed to serialize tags
always (which we dont want to happen). So the new test case really assert that
while encoding if boolean param is false its not really serializing the tags.
You follow now? Sorry for not being clear in my earlier comment
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]