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 .mock ;
24+ import static org .mockito .Mockito .when ;
2325
2426import java .io .IOException ;
27+ import java .util .Collections ;
2528import java .util .List ;
2629import java .util .Map ;
27- import java .util .NavigableMap ;
28- import java .util .SortedSet ;
2930import org .apache .hadoop .conf .Configuration ;
3031import org .apache .hadoop .fs .Path ;
3132import org .apache .hadoop .hbase .CoordinatedStateManager ;
5455import org .apache .hadoop .hbase .master .procedure .RSProcedureDispatcher ;
5556import org .apache .hadoop .hbase .master .region .MasterRegion ;
5657import org .apache .hadoop .hbase .master .region .MasterRegionFactory ;
58+ import org .apache .hadoop .hbase .master .replication .ReplicationPeerManager ;
5759import org .apache .hadoop .hbase .procedure2 .ProcedureEvent ;
5860import org .apache .hadoop .hbase .procedure2 .ProcedureExecutor ;
5961import org .apache .hadoop .hbase .procedure2 .ProcedureTestingUtility ;
6062import org .apache .hadoop .hbase .procedure2 .store .NoopProcedureStore ;
6163import org .apache .hadoop .hbase .procedure2 .store .ProcedureStore ;
6264import org .apache .hadoop .hbase .procedure2 .store .ProcedureStore .ProcedureStoreListener ;
65+ import org .apache .hadoop .hbase .replication .ReplicationException ;
66+ import org .apache .hadoop .hbase .replication .ReplicationQueueStorage ;
6367import org .apache .hadoop .hbase .security .Superusers ;
6468import org .apache .hadoop .hbase .util .CommonFSUtils ;
6569import org .apache .hadoop .hbase .util .EnvironmentEdgeManager ;
6670import org .apache .zookeeper .KeeperException ;
67- import org .mockito .Mockito ;
6871import org .mockito .invocation .InvocationOnMock ;
6972import org .mockito .stubbing .Answer ;
7073
@@ -96,14 +99,14 @@ public class MockMasterServices extends MockNoopMasterServices {
9699 private final Connection connection ;
97100 private final LoadBalancer balancer ;
98101 private final ServerManager serverManager ;
102+ private final ReplicationPeerManager rpm ;
99103
100104 private final ProcedureEvent <?> initialized = new ProcedureEvent <>("master initialized" );
101105 public static final String DEFAULT_COLUMN_FAMILY_NAME = "cf" ;
102106 public static final ServerName MOCK_MASTER_SERVERNAME =
103107 ServerName .valueOf ("mockmaster.example.org" , 1234 , -1L );
104108
105- public MockMasterServices (Configuration conf ,
106- NavigableMap <ServerName , SortedSet <byte []>> regionsToRegionServers ) throws IOException {
109+ public MockMasterServices (Configuration conf ) throws IOException , ReplicationException {
107110 super (conf );
108111 Superusers .initialize (conf );
109112 this .fileSystemManager = new MasterFileSystem (conf );
@@ -118,22 +121,22 @@ public MockMasterServices(Configuration conf,
118121 new AssignmentManager (this , masterRegion , new MockRegionStateStore (this , masterRegion ));
119122 this .balancer = LoadBalancerFactory .getLoadBalancer (conf );
120123 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 (
124+ this .tableStateManager = mock (TableStateManager .class );
125+ when (this .tableStateManager .getTableState (any ())).thenReturn (new TableState (
123126 TableName .valueOf ("AnyTableNameSetInMockMasterServcies" ), TableState .State .ENABLED ));
124127
125128 // Mock up a Client Interface
126129 ClientProtos .ClientService .BlockingInterface ri =
127- Mockito . mock (ClientProtos .ClientService .BlockingInterface .class );
130+ mock (ClientProtos .ClientService .BlockingInterface .class );
128131 MutateResponse .Builder builder = MutateResponse .newBuilder ();
129132 builder .setProcessed (true );
130133 try {
131- Mockito . when (ri .mutate (any (), any ())).thenReturn (builder .build ());
134+ when (ri .mutate (any (), any ())).thenReturn (builder .build ());
132135 } catch (ServiceException se ) {
133136 throw ProtobufUtil .handleRemoteException (se );
134137 }
135138 try {
136- Mockito . when (ri .multi (any (), any ())).thenAnswer (new Answer <MultiResponse >() {
139+ when (ri .multi (any (), any ())).thenAnswer (new Answer <MultiResponse >() {
137140 @ Override
138141 public MultiResponse answer (InvocationOnMock invocation ) throws Throwable {
139142 return buildMultiResponse (invocation .getArgument (1 ));
@@ -146,6 +149,10 @@ public MultiResponse answer(InvocationOnMock invocation) throws Throwable {
146149 // Set hbase.rootdir into test dir.
147150 Path rootdir = CommonFSUtils .getRootDir (getConfiguration ());
148151 CommonFSUtils .setRootDir (getConfiguration (), rootdir );
152+ this .rpm = mock (ReplicationPeerManager .class );
153+ ReplicationQueueStorage rqs = mock (ReplicationQueueStorage .class );
154+ when (rqs .getAllQueues (any ())).thenReturn (Collections .emptyList ());
155+ when (rpm .getQueueStorage ()).thenReturn (rqs );
149156 }
150157
151158 public void start (final int numServes , final RSProcedureDispatcher remoteDispatcher )
@@ -357,4 +364,9 @@ private static MultiResponse buildMultiResponse(MultiRequest req) {
357364 public SplitWALManager getSplitWALManager () {
358365 return splitWALManager ;
359366 }
367+
368+ @ Override
369+ public ReplicationPeerManager getReplicationPeerManager () {
370+ return rpm ;
371+ }
360372}
0 commit comments