2020import static org .apache .hadoop .hbase .HConstants .DEFAULT_HBASE_SPLIT_COORDINATED_BY_ZK ;
2121import static org .apache .hadoop .hbase .HConstants .HBASE_SPLIT_WAL_COORDINATED_BY_ZK ;
2222import static org .mockito .ArgumentMatchers .any ;
23+ import static org .mockito .Mockito .*;
2324
2425import java .io .IOException ;
26+ import java .util .Collections ;
2527import java .util .List ;
2628import java .util .Map ;
2729import java .util .NavigableMap ;
5456import org .apache .hadoop .hbase .master .procedure .RSProcedureDispatcher ;
5557import org .apache .hadoop .hbase .master .region .MasterRegion ;
5658import org .apache .hadoop .hbase .master .region .MasterRegionFactory ;
59+ import org .apache .hadoop .hbase .master .replication .ReplicationPeerManager ;
5760import org .apache .hadoop .hbase .procedure2 .ProcedureEvent ;
5861import org .apache .hadoop .hbase .procedure2 .ProcedureExecutor ;
5962import org .apache .hadoop .hbase .procedure2 .ProcedureTestingUtility ;
6063import org .apache .hadoop .hbase .procedure2 .store .NoopProcedureStore ;
6164import org .apache .hadoop .hbase .procedure2 .store .ProcedureStore ;
6265import org .apache .hadoop .hbase .procedure2 .store .ProcedureStore .ProcedureStoreListener ;
66+ import org .apache .hadoop .hbase .replication .ReplicationException ;
67+ import org .apache .hadoop .hbase .replication .ReplicationQueueStorage ;
6368import org .apache .hadoop .hbase .security .Superusers ;
6469import org .apache .hadoop .hbase .util .CommonFSUtils ;
6570import org .apache .hadoop .hbase .util .EnvironmentEdgeManager ;
6671import org .apache .zookeeper .KeeperException ;
67- import org .mockito .Mockito ;
6872import org .mockito .invocation .InvocationOnMock ;
6973import org .mockito .stubbing .Answer ;
7074
@@ -96,14 +100,16 @@ public class MockMasterServices extends MockNoopMasterServices {
96100 private final Connection connection ;
97101 private final LoadBalancer balancer ;
98102 private final ServerManager serverManager ;
103+ private final ReplicationPeerManager rpm ;
99104
100105 private final ProcedureEvent <?> initialized = new ProcedureEvent <>("master initialized" );
101106 public static final String DEFAULT_COLUMN_FAMILY_NAME = "cf" ;
102107 public static final ServerName MOCK_MASTER_SERVERNAME =
103108 ServerName .valueOf ("mockmaster.example.org" , 1234 , -1L );
104109
105110 public MockMasterServices (Configuration conf ,
106- NavigableMap <ServerName , SortedSet <byte []>> regionsToRegionServers ) throws IOException {
111+ NavigableMap <ServerName , SortedSet <byte []>> regionsToRegionServers )
112+ throws IOException , ReplicationException {
107113 super (conf );
108114 Superusers .initialize (conf );
109115 this .fileSystemManager = new MasterFileSystem (conf );
@@ -118,22 +124,22 @@ public MockMasterServices(Configuration conf,
118124 new AssignmentManager (this , masterRegion , new MockRegionStateStore (this , masterRegion ));
119125 this .balancer = LoadBalancerFactory .getLoadBalancer (conf );
120126 this .serverManager = new ServerManager (this , new DummyRegionServerList ());
121- this .tableStateManager = Mockito . mock (TableStateManager .class );
122- Mockito . when (this .tableStateManager .getTableState (Mockito . any ())).thenReturn (new TableState (
127+ this .tableStateManager = mock (TableStateManager .class );
128+ when (this .tableStateManager .getTableState (any ())).thenReturn (new TableState (
123129 TableName .valueOf ("AnyTableNameSetInMockMasterServcies" ), TableState .State .ENABLED ));
124130
125131 // Mock up a Client Interface
126132 ClientProtos .ClientService .BlockingInterface ri =
127- Mockito . mock (ClientProtos .ClientService .BlockingInterface .class );
133+ mock (ClientProtos .ClientService .BlockingInterface .class );
128134 MutateResponse .Builder builder = MutateResponse .newBuilder ();
129135 builder .setProcessed (true );
130136 try {
131- Mockito . when (ri .mutate (any (), any ())).thenReturn (builder .build ());
137+ when (ri .mutate (any (), any ())).thenReturn (builder .build ());
132138 } catch (ServiceException se ) {
133139 throw ProtobufUtil .handleRemoteException (se );
134140 }
135141 try {
136- Mockito . when (ri .multi (any (), any ())).thenAnswer (new Answer <MultiResponse >() {
142+ when (ri .multi (any (), any ())).thenAnswer (new Answer <MultiResponse >() {
137143 @ Override
138144 public MultiResponse answer (InvocationOnMock invocation ) throws Throwable {
139145 return buildMultiResponse (invocation .getArgument (1 ));
@@ -146,6 +152,10 @@ public MultiResponse answer(InvocationOnMock invocation) throws Throwable {
146152 // Set hbase.rootdir into test dir.
147153 Path rootdir = CommonFSUtils .getRootDir (getConfiguration ());
148154 CommonFSUtils .setRootDir (getConfiguration (), rootdir );
155+ this .rpm = mock (ReplicationPeerManager .class );
156+ ReplicationQueueStorage rqs = mock (ReplicationQueueStorage .class );
157+ when (rqs .getAllQueues (any ())).thenReturn (Collections .emptyList ());
158+ when (rpm .getQueueStorage ()).thenReturn (rqs );
149159 }
150160
151161 public void start (final int numServes , final RSProcedureDispatcher remoteDispatcher )
@@ -357,4 +367,9 @@ private static MultiResponse buildMultiResponse(MultiRequest req) {
357367 public SplitWALManager getSplitWALManager () {
358368 return splitWALManager ;
359369 }
370+
371+ @ Override
372+ public ReplicationPeerManager getReplicationPeerManager () {
373+ return rpm ;
374+ }
360375}
0 commit comments