20
20
import static org .apache .hadoop .hbase .HConstants .DEFAULT_HBASE_SPLIT_COORDINATED_BY_ZK ;
21
21
import static org .apache .hadoop .hbase .HConstants .HBASE_SPLIT_WAL_COORDINATED_BY_ZK ;
22
22
import static org .mockito .ArgumentMatchers .any ;
23
+ import static org .mockito .Mockito .mock ;
24
+ import static org .mockito .Mockito .when ;
23
25
24
26
import java .io .IOException ;
27
+ import java .util .Collections ;
25
28
import java .util .List ;
26
29
import java .util .Map ;
27
- import java .util .NavigableMap ;
28
- import java .util .SortedSet ;
29
30
import org .apache .hadoop .conf .Configuration ;
30
31
import org .apache .hadoop .fs .Path ;
31
32
import org .apache .hadoop .hbase .CoordinatedStateManager ;
54
55
import org .apache .hadoop .hbase .master .procedure .RSProcedureDispatcher ;
55
56
import org .apache .hadoop .hbase .master .region .MasterRegion ;
56
57
import org .apache .hadoop .hbase .master .region .MasterRegionFactory ;
58
+ import org .apache .hadoop .hbase .master .replication .ReplicationPeerManager ;
57
59
import org .apache .hadoop .hbase .procedure2 .ProcedureEvent ;
58
60
import org .apache .hadoop .hbase .procedure2 .ProcedureExecutor ;
59
61
import org .apache .hadoop .hbase .procedure2 .ProcedureTestingUtility ;
60
62
import org .apache .hadoop .hbase .procedure2 .store .NoopProcedureStore ;
61
63
import org .apache .hadoop .hbase .procedure2 .store .ProcedureStore ;
62
64
import org .apache .hadoop .hbase .procedure2 .store .ProcedureStore .ProcedureStoreListener ;
65
+ import org .apache .hadoop .hbase .replication .ReplicationException ;
66
+ import org .apache .hadoop .hbase .replication .ReplicationQueueStorage ;
63
67
import org .apache .hadoop .hbase .security .Superusers ;
64
68
import org .apache .hadoop .hbase .util .CommonFSUtils ;
65
69
import org .apache .hadoop .hbase .util .EnvironmentEdgeManager ;
66
70
import org .apache .zookeeper .KeeperException ;
67
- import org .mockito .Mockito ;
68
71
import org .mockito .invocation .InvocationOnMock ;
69
72
import org .mockito .stubbing .Answer ;
70
73
@@ -96,14 +99,14 @@ public class MockMasterServices extends MockNoopMasterServices {
96
99
private final Connection connection ;
97
100
private final LoadBalancer balancer ;
98
101
private final ServerManager serverManager ;
102
+ private final ReplicationPeerManager rpm ;
99
103
100
104
private final ProcedureEvent <?> initialized = new ProcedureEvent <>("master initialized" );
101
105
public static final String DEFAULT_COLUMN_FAMILY_NAME = "cf" ;
102
106
public static final ServerName MOCK_MASTER_SERVERNAME =
103
107
ServerName .valueOf ("mockmaster.example.org" , 1234 , -1L );
104
108
105
- public MockMasterServices (Configuration conf ,
106
- NavigableMap <ServerName , SortedSet <byte []>> regionsToRegionServers ) throws IOException {
109
+ public MockMasterServices (Configuration conf ) throws IOException , ReplicationException {
107
110
super (conf );
108
111
Superusers .initialize (conf );
109
112
this .fileSystemManager = new MasterFileSystem (conf );
@@ -118,22 +121,22 @@ public MockMasterServices(Configuration conf,
118
121
new AssignmentManager (this , masterRegion , new MockRegionStateStore (this , masterRegion ));
119
122
this .balancer = LoadBalancerFactory .getLoadBalancer (conf );
120
123
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 (
123
126
TableName .valueOf ("AnyTableNameSetInMockMasterServcies" ), TableState .State .ENABLED ));
124
127
125
128
// Mock up a Client Interface
126
129
ClientProtos .ClientService .BlockingInterface ri =
127
- Mockito . mock (ClientProtos .ClientService .BlockingInterface .class );
130
+ mock (ClientProtos .ClientService .BlockingInterface .class );
128
131
MutateResponse .Builder builder = MutateResponse .newBuilder ();
129
132
builder .setProcessed (true );
130
133
try {
131
- Mockito . when (ri .mutate (any (), any ())).thenReturn (builder .build ());
134
+ when (ri .mutate (any (), any ())).thenReturn (builder .build ());
132
135
} catch (ServiceException se ) {
133
136
throw ProtobufUtil .handleRemoteException (se );
134
137
}
135
138
try {
136
- Mockito . when (ri .multi (any (), any ())).thenAnswer (new Answer <MultiResponse >() {
139
+ when (ri .multi (any (), any ())).thenAnswer (new Answer <MultiResponse >() {
137
140
@ Override
138
141
public MultiResponse answer (InvocationOnMock invocation ) throws Throwable {
139
142
return buildMultiResponse (invocation .getArgument (1 ));
@@ -146,6 +149,10 @@ public MultiResponse answer(InvocationOnMock invocation) throws Throwable {
146
149
// Set hbase.rootdir into test dir.
147
150
Path rootdir = CommonFSUtils .getRootDir (getConfiguration ());
148
151
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 );
149
156
}
150
157
151
158
public void start (final int numServes , final RSProcedureDispatcher remoteDispatcher )
@@ -357,4 +364,9 @@ private static MultiResponse buildMultiResponse(MultiRequest req) {
357
364
public SplitWALManager getSplitWALManager () {
358
365
return splitWALManager ;
359
366
}
367
+
368
+ @ Override
369
+ public ReplicationPeerManager getReplicationPeerManager () {
370
+ return rpm ;
371
+ }
360
372
}
0 commit comments