Skip to content

Commit 7690250

Browse files
committed
add UT to confirm the PB exception message does not change in the future
1 parent 62bdff7 commit 7690250

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

hbase-client/src/test/java/org/apache/hadoop/hbase/shaded/protobuf/TestProtobufUtil.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.junit.Assert.assertTrue;
2323

2424
import java.io.IOException;
25+
import java.lang.reflect.Method;
2526
import java.nio.ByteBuffer;
2627
import java.util.Collections;
2728
import java.util.List;
@@ -53,6 +54,7 @@
5354
import org.apache.hbase.thirdparty.com.google.protobuf.Any;
5455
import org.apache.hbase.thirdparty.com.google.protobuf.ByteString;
5556
import org.apache.hbase.thirdparty.com.google.protobuf.BytesValue;
57+
import org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException;
5658

5759
import org.apache.hadoop.hbase.shaded.protobuf.generated.CellProtos;
5860
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos;
@@ -574,4 +576,21 @@ public void testTagEncodeTrueDecodeFalse() {
574576
List<Tag> decodedTags = PrivateCellUtil.getTags(decodedCell);
575577
assertEquals(0, decodedTags.size());
576578
}
579+
580+
/**
581+
* Used to confirm that we only consider truncatedMessage as EOF
582+
*/
583+
@Test
584+
public void testIsEOF() throws Exception {
585+
for (Method method : InvalidProtocolBufferException.class.getDeclaredMethods()) {
586+
if (
587+
method.getParameterCount() == 0
588+
&& method.getReturnType() == InvalidProtocolBufferException.class
589+
) {
590+
method.setAccessible(true);
591+
InvalidProtocolBufferException e = (InvalidProtocolBufferException) method.invoke(null);
592+
assertEquals(method.getName().equals("truncatedMessage"), ProtobufUtil.isEOF(e));
593+
}
594+
}
595+
}
577596
}

0 commit comments

Comments
 (0)