Skip to content

Commit 89e80da

Browse files
authored
HBASE-27823 NPE in ClaimReplicationQueuesProcedure when running TestAssignmentManager.testAssignSocketTimeout (#5216)
Also done some cleanup around the MockMasterServices related classes and tests Signed-off-by: Liangjun He <heliangjun@apache.org>
1 parent b59eb96 commit 89e80da

File tree

6 files changed

+35
-42
lines changed

6 files changed

+35
-42
lines changed

hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoreMasterCoprocessor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ public class TestCoreMasterCoprocessor {
5454
private MasterCoprocessorHost mch;
5555

5656
@Before
57-
public void before() throws IOException {
58-
String methodName = this.name.getMethodName();
59-
this.ms = new MockMasterServices(HTU.getConfiguration(), null);
57+
public void before() throws Exception {
58+
this.ms = new MockMasterServices(HTU.getConfiguration());
6059
this.mch = new MasterCoprocessorHost(this.ms, HTU.getConfiguration());
6160
this.mch.preMasterInitialization();
6261
}

hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/MockMasterServices.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
import static org.apache.hadoop.hbase.HConstants.DEFAULT_HBASE_SPLIT_COORDINATED_BY_ZK;
2121
import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_COORDINATED_BY_ZK;
2222
import static org.mockito.ArgumentMatchers.any;
23+
import static org.mockito.Mockito.mock;
24+
import static org.mockito.Mockito.when;
2325

2426
import java.io.IOException;
27+
import java.util.Collections;
2528
import java.util.List;
2629
import java.util.Map;
27-
import java.util.NavigableMap;
28-
import java.util.SortedSet;
2930
import org.apache.hadoop.conf.Configuration;
3031
import org.apache.hadoop.fs.Path;
3132
import org.apache.hadoop.hbase.CoordinatedStateManager;
@@ -54,17 +55,19 @@
5455
import org.apache.hadoop.hbase.master.procedure.RSProcedureDispatcher;
5556
import org.apache.hadoop.hbase.master.region.MasterRegion;
5657
import org.apache.hadoop.hbase.master.region.MasterRegionFactory;
58+
import org.apache.hadoop.hbase.master.replication.ReplicationPeerManager;
5759
import org.apache.hadoop.hbase.procedure2.ProcedureEvent;
5860
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
5961
import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;
6062
import org.apache.hadoop.hbase.procedure2.store.NoopProcedureStore;
6163
import org.apache.hadoop.hbase.procedure2.store.ProcedureStore;
6264
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;
6367
import org.apache.hadoop.hbase.security.Superusers;
6468
import org.apache.hadoop.hbase.util.CommonFSUtils;
6569
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
6670
import org.apache.zookeeper.KeeperException;
67-
import org.mockito.Mockito;
6871
import org.mockito.invocation.InvocationOnMock;
6972
import 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
}

hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestAssignmentManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void testAssignMetaAndCrashBeforeResponse() throws Exception {
233233
util = new HBaseTestingUtil();
234234
this.executor = Executors.newSingleThreadScheduledExecutor();
235235
setupConfiguration(util.getConfiguration());
236-
master = new MockMasterServices(util.getConfiguration(), this.regionsToRegionServers);
236+
master = new MockMasterServices(util.getConfiguration());
237237
rsDispatcher = new MockRSProcedureDispatcher(master);
238238
master.start(NSERVERS, rsDispatcher);
239239
am = master.getAssignmentManager();

hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestAssignmentManagerBase.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import org.junit.After;
6868
import org.junit.Before;
6969
import org.junit.Rule;
70-
import org.junit.rules.ExpectedException;
7170
import org.junit.rules.TestName;
7271
import org.slf4j.Logger;
7372
import org.slf4j.LoggerFactory;
@@ -96,8 +95,6 @@ public abstract class TestAssignmentManagerBase {
9695

9796
@Rule
9897
public TestName name = new TestName();
99-
@Rule
100-
public final ExpectedException exception = ExpectedException.none();
10198

10299
protected static final int PROC_NTHREADS = 64;
103100
protected static final int NREGIONS = 1 * 1000;
@@ -157,7 +154,7 @@ public void setUp() throws Exception {
157154
this.executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
158155
.setUncaughtExceptionHandler((t, e) -> LOG.warn("Uncaught: ", e)).build());
159156
setupConfiguration(util.getConfiguration());
160-
master = new MockMasterServices(util.getConfiguration(), this.regionsToRegionServers);
157+
master = new MockMasterServices(util.getConfiguration());
161158
rsDispatcher = new MockRSProcedureDispatcher(master);
162159
master.start(NSERVERS, rsDispatcher);
163160
newRsAdded = 0;

hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitor.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.Assert.assertFalse;
2323
import static org.junit.Assert.assertTrue;
24-
import static org.mockito.Mockito.any;
24+
import static org.mockito.ArgumentMatchers.any;
2525
import static org.mockito.Mockito.doAnswer;
2626
import static org.mockito.Mockito.doReturn;
2727
import static org.mockito.Mockito.doThrow;
@@ -32,12 +32,9 @@
3232
import java.util.ArrayList;
3333
import java.util.List;
3434
import java.util.Map;
35-
import java.util.NavigableMap;
3635
import java.util.Objects;
3736
import java.util.SortedMap;
38-
import java.util.SortedSet;
3937
import java.util.TreeMap;
40-
import java.util.concurrent.ConcurrentSkipListMap;
4138
import java.util.concurrent.atomic.AtomicBoolean;
4239
import org.apache.hadoop.fs.FSDataOutputStream;
4340
import org.apache.hadoop.fs.FileStatus;
@@ -47,7 +44,6 @@
4744
import org.apache.hadoop.hbase.HBaseTestingUtil;
4845
import org.apache.hadoop.hbase.HConstants;
4946
import org.apache.hadoop.hbase.MetaMockingUtil;
50-
import org.apache.hadoop.hbase.ServerName;
5147
import org.apache.hadoop.hbase.TableName;
5248
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
5349
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
@@ -71,7 +67,6 @@
7167
import org.apache.hadoop.hbase.util.CommonFSUtils;
7268
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
7369
import org.apache.hadoop.hbase.util.HFileArchiveUtil;
74-
import org.apache.zookeeper.KeeperException;
7570
import org.junit.After;
7671
import org.junit.Before;
7772
import org.junit.BeforeClass;
@@ -107,11 +102,9 @@ public static void beforeClass() throws Exception {
107102
}
108103

109104
@Before
110-
public void setup() throws IOException, KeeperException {
105+
public void setup() throws Exception {
111106
setRootDirAndCleanIt(HTU, this.name.getMethodName());
112-
NavigableMap<ServerName, SortedSet<byte[]>> regionsToRegionServers =
113-
new ConcurrentSkipListMap<ServerName, SortedSet<byte[]>>();
114-
this.masterServices = new MockMasterServices(HTU.getConfiguration(), regionsToRegionServers);
107+
this.masterServices = new MockMasterServices(HTU.getConfiguration());
115108
this.masterServices.start(10, null);
116109
this.janitor = new CatalogJanitor(masterServices);
117110
}

hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestServerRemoteProcedure.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121
import static org.junit.Assert.fail;
2222

2323
import java.io.IOException;
24-
import java.util.NavigableMap;
2524
import java.util.Optional;
2625
import java.util.Set;
27-
import java.util.SortedSet;
28-
import java.util.concurrent.ConcurrentSkipListMap;
2926
import java.util.concurrent.ExecutorService;
3027
import java.util.concurrent.Executors;
3128
import java.util.concurrent.Future;
@@ -57,7 +54,6 @@
5754
import org.junit.Rule;
5855
import org.junit.Test;
5956
import org.junit.experimental.categories.Category;
60-
import org.junit.rules.ExpectedException;
6157
import org.junit.rules.TestName;
6258
import org.slf4j.Logger;
6359
import org.slf4j.LoggerFactory;
@@ -74,23 +70,19 @@ public class TestServerRemoteProcedure {
7470
HBaseClassTestRule.forClass(TestServerRemoteProcedure.class);
7571
@Rule
7672
public TestName name = new TestName();
77-
@Rule
78-
public final ExpectedException exception = ExpectedException.none();
79-
protected HBaseTestingUtil util;
80-
protected MockRSProcedureDispatcher rsDispatcher;
81-
protected MockMasterServices master;
82-
protected AssignmentManager am;
83-
protected NavigableMap<ServerName, SortedSet<byte[]>> regionsToRegionServers =
84-
new ConcurrentSkipListMap<>();
73+
private HBaseTestingUtil util;
74+
private MockRSProcedureDispatcher rsDispatcher;
75+
private MockMasterServices master;
76+
private AssignmentManager am;
8577
// Simple executor to run some simple tasks.
86-
protected ScheduledExecutorService executor;
78+
private ScheduledExecutorService executor;
8779

8880
@Before
8981
public void setUp() throws Exception {
9082
util = new HBaseTestingUtil();
9183
this.executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
9284
.setUncaughtExceptionHandler((t, e) -> LOG.warn("Uncaught: ", e)).build());
93-
master = new MockMasterServices(util.getConfiguration(), this.regionsToRegionServers);
85+
master = new MockMasterServices(util.getConfiguration());
9486
rsDispatcher = new MockRSProcedureDispatcher(master);
9587
rsDispatcher.setMockRsExecutor(new NoopRSExecutor());
9688
master.start(2, rsDispatcher);

0 commit comments

Comments
 (0)