69
69
import org .apache .hadoop .hbase .shaded .protobuf .generated .HBaseProtos ;
70
70
import org .apache .hadoop .hbase .shaded .protobuf .generated .HBaseProtos .NameBytesPair ;
71
71
import org .apache .hadoop .hbase .shaded .protobuf .generated .LockServiceProtos ;
72
+ import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos ;
72
73
import org .apache .hadoop .hbase .shaded .protobuf .generated .ProcedureProtos ;
74
+ import org .apache .hadoop .hbase .shaded .protobuf .generated .RegionServerStatusProtos ;
73
75
74
76
@ Category (SmallTests .class )
75
77
public class TestProtobufUtil {
@@ -78,6 +80,11 @@ public class TestProtobufUtil {
78
80
HBaseClassTestRule .forClass (TestProtobufUtil .class );
79
81
private static final String TAG_STR = "tag-1" ;
80
82
private static final byte TAG_TYPE = (byte ) 10 ;
83
+ private static final HBaseProtos .ServerName SERVER_NAME =
84
+ HBaseProtos .ServerName .newBuilder ().setHostName ("a.b.com" ).build ();
85
+ private static final HBaseProtos .RegionSpecifier REGION =
86
+ HBaseProtos .RegionSpecifier .newBuilder ().setValue (ByteString .copyFromUtf8 ("test" ))
87
+ .setType (HBaseProtos .RegionSpecifier .RegionSpecifierType .REGION_NAME ).build ();
81
88
82
89
public TestProtobufUtil () {
83
90
}
@@ -623,4 +630,139 @@ public void testSlowLogParamsMutateRequest() {
623
630
assertTrue (slowLogParams .getParams ()
624
631
.contains (Bytes .toStringBinary (mutationProto .getRow ().toByteArray ())));
625
632
}
633
+
634
+ @ Test
635
+ public void testGetShortTextFormatNull () {
636
+ String actual = ProtobufUtil .getShortTextFormat (null );
637
+ assertNotNull (actual );
638
+ assertEquals ("null" , actual );
639
+ }
640
+
641
+ @ Test
642
+ public void testGetShortTextFormatScanRequest () {
643
+ ClientProtos .ScanRequest .Builder builder = ClientProtos .ScanRequest .newBuilder ();
644
+ builder .setRegion (REGION );
645
+ ClientProtos .ScanRequest scanRequest = builder .build ();
646
+
647
+ String actual = ProtobufUtil .getShortTextFormat (scanRequest );
648
+
649
+ assertNotNull (actual );
650
+ assertEquals ("region { type: REGION_NAME value: \" test\" }" , actual );
651
+ }
652
+
653
+ @ Test
654
+ public void testGetShortTextFormatRegionServerReportRequest () {
655
+ RegionServerStatusProtos .RegionServerReportRequest .Builder builder =
656
+ RegionServerStatusProtos .RegionServerReportRequest .newBuilder ();
657
+ builder .setServer (SERVER_NAME );
658
+ RegionServerStatusProtos .RegionServerReportRequest request = builder .build ();
659
+
660
+ String actual = ProtobufUtil .getShortTextFormat (request );
661
+
662
+ assertNotNull (actual );
663
+ assertEquals ("server host_name: \" a.b.com\" load { numberOfRequests: 0 }" , actual );
664
+ }
665
+
666
+ @ Test
667
+ public void testGetShortTextFormatRegionServerStartupRequest () {
668
+ RegionServerStatusProtos .RegionServerStartupRequest .Builder builder =
669
+ RegionServerStatusProtos .RegionServerStartupRequest .newBuilder ();
670
+ builder .setPort (8080 );
671
+ builder .setServerCurrentTime (111111L );
672
+ builder .setServerStartCode (15L );
673
+ builder .setUseThisHostnameInstead ("some-host-name" );
674
+ RegionServerStatusProtos .RegionServerStartupRequest regionServerStartupRequest =
675
+ builder .build ();
676
+
677
+ String actual = ProtobufUtil .getShortTextFormat (regionServerStartupRequest );
678
+
679
+ assertNotNull (actual );
680
+ assertEquals ("port: 8080 server_start_code: 15 server_current_time: 111111"
681
+ + " use_this_hostname_instead: \" some-host-name\" " , actual );
682
+ }
683
+
684
+ @ Test
685
+ public void testGetShortTextFormatMutationProto () {
686
+ MutationProto mutationProto =
687
+ ClientProtos .MutationProto .newBuilder ().setRow (ByteString .copyFromUtf8 ("row123" )).build ();
688
+
689
+ String actual = ProtobufUtil .getShortTextFormat (mutationProto );
690
+
691
+ assertNotNull (actual );
692
+ assertEquals ("row=row123, type=APPEND" , actual );
693
+ }
694
+
695
+ @ Test
696
+ public void testGetShortTextFormatGetRequest () throws IOException {
697
+ ClientProtos .GetRequest getRequest = ClientProtos .GetRequest .newBuilder ().setRegion (REGION )
698
+ .setGet (ProtobufUtil .toGet (new Get (Bytes .toBytes ("foo" )))).build ();
699
+
700
+ String actual = ProtobufUtil .getShortTextFormat (getRequest );
701
+
702
+ assertNotNull (actual );
703
+ assertEquals ("region= test, row=foo" , actual );
704
+ }
705
+
706
+ @ Test
707
+ public void testGetShortTextFormatMultiRequest () throws IOException {
708
+ ClientProtos .Action action = ClientProtos .Action .newBuilder ()
709
+ .setGet (ProtobufUtil .toGet (new Get (Bytes .toBytes ("foo" )))).build ();
710
+ ClientProtos .RegionAction regionAction =
711
+ ClientProtos .RegionAction .newBuilder ().addAction (action ).setRegion (REGION ).build ();
712
+
713
+ ClientProtos .MultiRequest multiRequest =
714
+ ClientProtos .MultiRequest .newBuilder ().addRegionAction (regionAction ).build ();
715
+
716
+ String actual = ProtobufUtil .getShortTextFormat (multiRequest );
717
+
718
+ assertNotNull (actual );
719
+ assertEquals ("region= test, for 1 action(s) and 1st row key=foo" , actual );
720
+ }
721
+
722
+ @ Test
723
+ public void testGetShortTextFormatMutateRequest () throws IOException {
724
+ ClientProtos .MutateRequest mutateRequest = ClientProtos .MutateRequest .newBuilder ()
725
+ .setMutation (
726
+ ProtobufUtil .toMutation (MutationType .INCREMENT , new Increment (Bytes .toBytes ("foo" ))))
727
+ .setRegion (REGION ).build ();
728
+
729
+ String actual = ProtobufUtil .getShortTextFormat (mutateRequest );
730
+
731
+ assertNotNull (actual );
732
+ assertEquals ("region= test, row=foo" , actual );
733
+ }
734
+
735
+ @ Test
736
+ public void testGetShortTextFormatCoprocessorServiceRequest () {
737
+ ClientProtos .CoprocessorServiceCall call = ClientProtos .CoprocessorServiceCall .newBuilder ()
738
+ .setRow (ByteString .copyFrom (Bytes .toBytes ("foo" ))).setMethodName ("awesomeMethod" )
739
+ .setServiceName ("awesomeService" )
740
+ .setRequest (ByteString .copyFrom (Bytes .toBytes ("foo-request" ))).build ();
741
+
742
+ ClientProtos .CoprocessorServiceRequest .Builder builder =
743
+ ClientProtos .CoprocessorServiceRequest .newBuilder ();
744
+ builder .setRegion (REGION );
745
+ builder .setCall (call );
746
+ ClientProtos .CoprocessorServiceRequest coprocessorServiceRequest = builder .build ();
747
+
748
+ String actual = ProtobufUtil .getShortTextFormat (coprocessorServiceRequest );
749
+
750
+ assertNotNull (actual );
751
+ assertEquals ("coprocessorService= awesomeService:awesomeMethod" , actual );
752
+ }
753
+
754
+ @ Test
755
+ public void testGetShortTextFormatMoveRegionRequest () {
756
+ MasterProtos .MoveRegionRequest .Builder builder = MasterProtos .MoveRegionRequest .newBuilder ();
757
+ builder .setRegion (REGION );
758
+ builder .setDestServerName (SERVER_NAME );
759
+ MasterProtos .MoveRegionRequest moveRegionRequest = builder .build ();
760
+
761
+ String actual = ProtobufUtil .getShortTextFormat (moveRegionRequest );
762
+
763
+ assertNotNull (actual );
764
+ assertEquals (
765
+ "region { type: REGION_NAME value: \" test\" } dest_server_name { host_name: \" a.b.com\" }" ,
766
+ actual );
767
+ }
626
768
}
0 commit comments