stoty commented on code in PR #6318: URL: https://github.com/apache/hbase/pull/6318#discussion_r1793614298
########## hbase-client/src/test/java/org/apache/hadoop/hbase/shaded/protobuf/TestProtobufUtil.java: ########## @@ -623,4 +631,140 @@ public void testSlowLogParamsMutateRequest() { assertTrue(slowLogParams.getParams() .contains(Bytes.toStringBinary(mutationProto.getRow().toByteArray()))); } + + @Test + public void testGetShortTextFormatNull() { + String actual = ProtobufUtil.getShortTextFormat(null); + assertNotNull(actual); + assertEquals("null", actual); + } + + @Test + public void testGetShortTextFormatScanRequest() { + ClientProtos.ScanRequest.Builder builder = ClientProtos.ScanRequest.newBuilder(); + builder.setRegion(REGION); + ClientProtos.ScanRequest scanRequest = builder.build(); + + String actual = ProtobufUtil.getShortTextFormat(scanRequest); + + assertNotNull(actual); + assertEquals("region { type: REGION_NAME value: \"test\" }", actual); + } + + @Test + public void testGetShortTextFormatRegionServerReportRequest() { + RegionServerStatusProtos.RegionServerReportRequest.Builder builder = + RegionServerStatusProtos.RegionServerReportRequest.newBuilder(); + builder.setServer(SERVER_NAME); + RegionServerStatusProtos.RegionServerReportRequest request = builder.build(); + + String actual = ProtobufUtil.getShortTextFormat(request); + + assertNotNull(actual); + assertEquals("server host_name: \"a.b.com\" load { numberOfRequests: 0 }", actual); + } + + @Test + public void testGetShortTextFormatRegionServerStartupRequest() { + RegionServerStatusProtos.RegionServerStartupRequest.Builder builder = + RegionServerStatusProtos.RegionServerStartupRequest.newBuilder(); + builder.setPort(8080); + builder.setServerCurrentTime(111111L); + builder.setServerStartCode(15L); + builder.setUseThisHostnameInstead("some-host-name"); + RegionServerStatusProtos.RegionServerStartupRequest regionServerStartupRequest = + builder.build(); + + String actual = ProtobufUtil.getShortTextFormat(regionServerStartupRequest); + + assertNotNull(actual); + assertEquals( + "port: 8080 server_start_code: 15 server_current_time: 111111 use_this_hostname_instead: \"some-host-name\"", + actual); + } + + @Test + public void testGetShortTextFormatMutationProto() { + MutationProto mutationProto = + ClientProtos.MutationProto.newBuilder().setRow(ByteString.copyFromUtf8("row123")).build(); + + String actual = ProtobufUtil.getShortTextFormat(mutationProto); + + assertNotNull(actual); + assertEquals("row=row123, type=APPEND", actual); + } + + @Test + public void testGetShortTextFormatGetRequest() throws IOException { + ClientProtos.GetRequest getRequest = ClientProtos.GetRequest.newBuilder().setRegion(REGION) + .setGet(ProtobufUtil.toGet(new Get(Bytes.toBytes("foo")))).build(); + + String actual = ProtobufUtil.getShortTextFormat(getRequest); + + assertNotNull(actual); + assertEquals("region= test, row=foo", actual); + } + + @Test + public void testGetShortTextFormatMultiRequest() throws IOException { + ClientProtos.Action action = ClientProtos.Action.newBuilder() + .setGet(ProtobufUtil.toGet(new Get(Bytes.toBytes("foo")))).build(); + ClientProtos.RegionAction regionAction = + ClientProtos.RegionAction.newBuilder().addAction(action).setRegion(REGION).build(); + + ClientProtos.MultiRequest multiRequest = + ClientProtos.MultiRequest.newBuilder().addRegionAction(regionAction).build(); + + String actual = ProtobufUtil.getShortTextFormat(multiRequest); + + assertNotNull(actual); + assertEquals("region= test, for 1 action(s) and 1st row key=foo", actual); + } + + @Test + public void testGetShortTextFormatMutateRequest() throws IOException { + ClientProtos.MutateRequest mutateRequest = ClientProtos.MutateRequest.newBuilder() + .setMutation( + ProtobufUtil.toMutation(MutationType.INCREMENT, new Increment(Bytes.toBytes("foo")))) + .setRegion(REGION).build(); + + String actual = ProtobufUtil.getShortTextFormat(mutateRequest); + + assertNotNull(actual); + assertEquals("region= test, row=foo", actual); + } + + @Test + public void testGetShortTextFormatCoprocessorServiceRequest() { + ClientProtos.CoprocessorServiceCall call = ClientProtos.CoprocessorServiceCall.newBuilder() + .setRow(UnsafeByteOperations.unsafeWrap(Bytes.toBytes("foo"))).setMethodName("awesomeMethod") Review Comment: However, for this simple test, ByteString.copyFrom() would be better. -- 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. To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org