Skip to content

Commit 7908591

Browse files
authored
HBASE-30012 Upgrade hbase-server to use junit5 Part2 (#8088)
Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit 3c99c06) (cherry picked from commit 8c720ae)
1 parent 65f5c3c commit 7908591

82 files changed

Lines changed: 1319 additions & 1733 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/master/balancer/RSGroupableBalancerTestBase.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
*/
1818
package org.apache.hadoop.hbase.master.balancer;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
import static org.mockito.Mockito.any;
24+
import static org.mockito.Mockito.mock;
25+
import static org.mockito.Mockito.when;
2326

2427
import java.io.FileNotFoundException;
2528
import java.io.IOException;
@@ -122,8 +125,8 @@ protected void assertImmediateAssignment(List<RegionInfo> regions, List<ServerNa
122125
String groupName = getMockedGroupInfoManager().getRSGroupOfTable(tableName);
123126
assertTrue(StringUtils.isNotEmpty(groupName));
124127
RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName);
125-
assertTrue("Region is not correctly assigned to group servers.",
126-
gInfo.containsServer(server.getAddress()));
128+
assertTrue(gInfo.containsServer(server.getAddress()),
129+
"Region is not correctly assigned to group servers.");
127130
}
128131
}
129132

@@ -144,8 +147,8 @@ protected void assertRetainedAssignment(Map<RegionInfo, ServerName> existing,
144147
Set<ServerName> onlineServerSet = new TreeSet<>(servers);
145148
Set<RegionInfo> assignedRegions = new TreeSet<>(RegionInfo.COMPARATOR);
146149
for (Map.Entry<ServerName, List<RegionInfo>> a : assignment.entrySet()) {
147-
assertTrue("Region assigned to server that was not listed as online",
148-
onlineServerSet.contains(a.getKey()));
150+
assertTrue(onlineServerSet.contains(a.getKey()),
151+
"Region assigned to server that was not listed as online");
149152
for (RegionInfo r : a.getValue()) {
150153
assignedRegions.add(r);
151154
}
@@ -166,8 +169,8 @@ protected void assertRetainedAssignment(Map<RegionInfo, ServerName> existing,
166169
String groupName = getMockedGroupInfoManager().getRSGroupOfTable(tableName);
167170
assertTrue(StringUtils.isNotEmpty(groupName));
168171
RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName);
169-
assertTrue("Region is not correctly assigned to group servers.",
170-
gInfo.containsServer(currentServer.getAddress()));
172+
assertTrue(gInfo.containsServer(currentServer.getAddress()),
173+
"Region is not correctly assigned to group servers.");
171174
if (
172175
oldAssignedServer != null && onlineHostNames.contains(oldAssignedServer.getHostname())
173176
) {
@@ -225,7 +228,7 @@ protected String printStats(ArrayListMultimap<String, ServerAndLoad> groupBasedL
225228
}
226229
}
227230
List<RegionInfo> regions = serversMap.get(actual);
228-
assertTrue("No load for " + actual, regions != null);
231+
assertTrue(regions != null, "No load for " + actual);
229232
loadMap.put(gInfo.getName(), new ServerAndLoad(actual, regions.size()));
230233
}
231234
}
@@ -397,12 +400,9 @@ protected static MasterServices getMockedMaster() throws IOException {
397400
}
398401

399402
protected static RSGroupInfoManager getMockedGroupInfoManager() throws IOException {
400-
RSGroupInfoManager gm = Mockito.mock(RSGroupInfoManager.class);
401-
Mockito.when(gm.getRSGroup(Mockito.any())).thenAnswer(new Answer<RSGroupInfo>() {
402-
@Override
403-
public RSGroupInfo answer(InvocationOnMock invocation) throws Throwable {
404-
return groupMap.get(invocation.getArgument(0));
405-
}
403+
RSGroupInfoManager gm = mock(RSGroupInfoManager.class);
404+
when(gm.getRSGroup(any())).thenAnswer(invocation -> {
405+
return groupMap.get(invocation.getArgument(0));
406406
});
407407
Mockito.when(gm.listRSGroups()).thenReturn(Lists.newLinkedList(groupMap.values()));
408408
Mockito.when(gm.isOnline()).thenReturn(true);

hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
*/
1818
package org.apache.hadoop.hbase.master.balancer;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
2323

2424
import java.util.ArrayList;
2525
import java.util.Collections;
@@ -30,7 +30,6 @@
3030
import java.util.Map;
3131
import java.util.Set;
3232
import org.apache.commons.lang3.StringUtils;
33-
import org.apache.hadoop.hbase.HBaseClassTestRule;
3433
import org.apache.hadoop.hbase.HConstants;
3534
import org.apache.hadoop.hbase.ServerName;
3635
import org.apache.hadoop.hbase.TableName;
@@ -42,10 +41,9 @@
4241
import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
4342
import org.apache.hadoop.hbase.testclassification.LargeTests;
4443
import org.apache.hadoop.net.DNSToSwitchMapping;
45-
import org.junit.BeforeClass;
46-
import org.junit.ClassRule;
47-
import org.junit.Test;
48-
import org.junit.experimental.categories.Category;
44+
import org.junit.jupiter.api.BeforeAll;
45+
import org.junit.jupiter.api.Tag;
46+
import org.junit.jupiter.api.Test;
4947
import org.slf4j.Logger;
5048
import org.slf4j.LoggerFactory;
5149

@@ -54,15 +52,12 @@
5452
/**
5553
* Test RSGroupBasedLoadBalancer with SimpleLoadBalancer as internal balancer
5654
*/
57-
@Category(LargeTests.class)
55+
@Tag(LargeTests.TAG)
5856
public class TestRSGroupBasedLoadBalancer extends RSGroupableBalancerTestBase {
59-
@ClassRule
60-
public static final HBaseClassTestRule CLASS_RULE =
61-
HBaseClassTestRule.forClass(TestRSGroupBasedLoadBalancer.class);
6257
private static final Logger LOG = LoggerFactory.getLogger(TestRSGroupBasedLoadBalancer.class);
6358
private static RSGroupBasedLoadBalancer loadBalancer;
6459

65-
@BeforeClass
60+
@BeforeAll
6661
public static void beforeAllTests() throws Exception {
6762
servers = generateServers(7);
6863
groupMap = constructGroupInfo(servers, groups);
@@ -121,8 +116,8 @@ public void testBulkAssignment() throws Exception {
121116
String groupName = getMockedGroupInfoManager().getRSGroupOfTable(tableName);
122117
assertTrue(StringUtils.isNotEmpty(groupName));
123118
RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName);
124-
assertTrue("Region is not correctly assigned to group servers.",
125-
gInfo.containsServer(sn.getAddress()));
119+
assertTrue(gInfo.containsServer(sn.getAddress()),
120+
"Region is not correctly assigned to group servers.");
126121
}
127122
}
128123
ArrayListMultimap<String, ServerAndLoad> loadMap = convertToGroupBasedMap(assignments);

hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hbase.master.balancer;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222
import static org.mockito.Mockito.mock;
2323
import static org.mockito.Mockito.when;
2424

@@ -30,7 +30,6 @@
3030
import java.util.Set;
3131
import java.util.TreeMap;
3232
import org.apache.hadoop.hbase.ClusterMetrics;
33-
import org.apache.hadoop.hbase.HBaseClassTestRule;
3433
import org.apache.hadoop.hbase.RegionMetrics;
3534
import org.apache.hadoop.hbase.ServerMetrics;
3635
import org.apache.hadoop.hbase.ServerName;
@@ -43,23 +42,16 @@
4342
import org.apache.hadoop.hbase.testclassification.LargeTests;
4443
import org.apache.hadoop.hbase.util.Bytes;
4544
import org.apache.hadoop.net.DNSToSwitchMapping;
46-
import org.junit.BeforeClass;
47-
import org.junit.ClassRule;
48-
import org.junit.Test;
49-
import org.junit.experimental.categories.Category;
45+
import org.junit.jupiter.api.BeforeAll;
46+
import org.junit.jupiter.api.Tag;
47+
import org.junit.jupiter.api.Test;
5048

51-
/**
52-
* Test RSGroupBasedLoadBalancer with StochasticLoadBalancer as internal balancer
53-
*/
54-
@Category(LargeTests.class)
49+
@Tag(LargeTests.TAG)
5550
public class TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal
5651
extends RSGroupableBalancerTestBase {
57-
@ClassRule
58-
public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule
59-
.forClass(TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal.class);
6052
private static RSGroupBasedLoadBalancer loadBalancer;
6153

62-
@BeforeClass
54+
@BeforeAll
6355
public static void beforeAllTests() throws Exception {
6456
groups = new String[] { RSGroupInfo.DEFAULT_GROUP };
6557
servers = generateServers(3);

hbase-server/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,6 @@
319319
<artifactId>awaitility</artifactId>
320320
<scope>test</scope>
321321
</dependency>
322-
<dependency>
323-
<groupId>org.mockito</groupId>
324-
<artifactId>mockito-core</artifactId>
325-
<scope>test</scope>
326-
</dependency>
327322
<dependency>
328323
<groupId>org.mockito</groupId>
329324
<artifactId>mockito-inline</artifactId>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
4545
import org.apache.hadoop.hbase.util.CommonFSUtils;
4646
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
47-
import org.junit.AfterClass;
48-
import org.junit.BeforeClass;
47+
import org.junit.jupiter.api.AfterAll;
48+
import org.junit.jupiter.api.BeforeAll;
4949

5050
public abstract class MasterStateStoreTestBase {
5151

@@ -63,7 +63,7 @@ public abstract class MasterStateStoreTestBase {
6363
TableDescriptorBuilder.newBuilder(TableName.valueOf("test:local"))
6464
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(MasterRegionFactory.STATE_FAMILY)).build();
6565

66-
@BeforeClass
66+
@BeforeAll
6767
public static void setUpBeforeClass() throws Exception {
6868
Configuration conf = UTIL.getConfiguration();
6969
conf.setBoolean(MemStoreLAB.USEMSLAB_KEY, false);
@@ -94,7 +94,7 @@ public static void setUpBeforeClass() throws Exception {
9494
UTIL.startMiniZKCluster();
9595
}
9696

97-
@AfterClass
97+
@AfterAll
9898
public static void tearDownAfterClass() throws IOException {
9999
REGION.close(true);
100100
HFILE_CLEANER_POOL.shutdownNow();

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,27 @@
1717
*/
1818
package org.apache.hadoop.hbase.master;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
2323

24-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2524
import org.apache.hadoop.hbase.client.MasterSwitchType;
2625
import org.apache.hadoop.hbase.testclassification.MasterTests;
2726
import org.apache.hadoop.hbase.testclassification.MediumTests;
2827
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
2928
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
30-
import org.junit.After;
31-
import org.junit.ClassRule;
32-
import org.junit.Test;
33-
import org.junit.experimental.categories.Category;
29+
import org.junit.jupiter.api.AfterEach;
30+
import org.junit.jupiter.api.Tag;
31+
import org.junit.jupiter.api.Test;
3432

3533
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
3634
import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos;
3735

38-
@Category({ MasterTests.class, MediumTests.class })
36+
@Tag(MasterTests.TAG)
37+
@Tag(MediumTests.TAG)
3938
public class TestSplitOrMergeStateStore extends MasterStateStoreTestBase {
4039

41-
@ClassRule
42-
public static final HBaseClassTestRule CLASS_RULE =
43-
HBaseClassTestRule.forClass(TestSplitOrMergeStateStore.class);
44-
45-
@After
40+
@AfterEach
4641
public void tearDown() throws Exception {
4742
cleanup();
4843
ZKUtil.deleteNodeRecursively(UTIL.getZooKeeperWatcher(),

hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
*/
1818
package org.apache.hadoop.hbase.master.balancer;
1919

20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertNull;
22-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertNull;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
import static org.junit.jupiter.api.Assertions.fail;
2324
import static org.mockito.Mockito.mock;
2425
import static org.mockito.Mockito.when;
2526

@@ -53,8 +54,7 @@
5354
import org.apache.hadoop.hbase.master.RegionPlan;
5455
import org.apache.hadoop.hbase.util.Bytes;
5556
import org.apache.hadoop.net.DNSToSwitchMapping;
56-
import org.junit.Assert;
57-
import org.junit.BeforeClass;
57+
import org.junit.jupiter.api.BeforeAll;
5858
import org.slf4j.Logger;
5959
import org.slf4j.LoggerFactory;
6060

@@ -71,7 +71,7 @@ public class BalancerTestBase {
7171
protected static DummyMetricsStochasticBalancer dummyMetricsStochasticBalancer =
7272
new DummyMetricsStochasticBalancer();
7373

74-
@BeforeClass
74+
@BeforeAll
7575
public static void beforeAllTests() throws Exception {
7676
conf = HBaseConfiguration.create();
7777
conf.setClass("hbase.util.ip.to.rack.determiner", MockMapping.class, DNSToSwitchMapping.class);
@@ -196,11 +196,11 @@ public void assertClusterAsBalanced(List<ServerAndLoad> servers) {
196196
int max = numRegions % numServers == 0 ? min : min + 1;
197197

198198
for (ServerAndLoad server : servers) {
199-
assertTrue("All servers should have a positive load. " + server, server.getLoad() >= 0);
200-
assertTrue("All servers should have load no more than " + max + ". " + server,
201-
server.getLoad() <= max);
202-
assertTrue("All servers should have load no less than " + min + ". " + server,
203-
server.getLoad() >= min);
199+
assertTrue(server.getLoad() >= 0, "All servers should have a positive load. " + server);
200+
assertTrue(server.getLoad() <= max,
201+
"All servers should have load no more than " + max + ". " + server);
202+
assertTrue(server.getLoad() >= min,
203+
"All servers should have load no less than " + min + ". " + server);
204204
}
205205
}
206206

@@ -262,7 +262,7 @@ public void assertRegionReplicaPlacement(Map<ServerName, List<RegionInfo>> serve
262262
for (RegionInfo info : entry.getValue()) {
263263
RegionInfo primaryInfo = RegionReplicaUtil.getRegionInfoForDefaultReplica(info);
264264
if (!infos.add(primaryInfo)) {
265-
Assert.fail("Two or more region replicas are hosted on the same host after balance");
265+
fail("Two or more region replicas are hosted on the same host after balance");
266266
}
267267
}
268268
}
@@ -282,7 +282,7 @@ public void assertRegionReplicaPlacement(Map<ServerName, List<RegionInfo>> serve
282282
for (RegionInfo info : entry.getValue()) {
283283
RegionInfo primaryInfo = RegionReplicaUtil.getRegionInfoForDefaultReplica(info);
284284
if (!infos.add(primaryInfo)) {
285-
Assert.fail("Two or more region replicas are hosted on the same rack after balance");
285+
fail("Two or more region replicas are hosted on the same rack after balance");
286286
}
287287
}
288288
}
@@ -586,7 +586,7 @@ protected void testWithCluster(Map<ServerName, List<RegionInfo>> serverMap,
586586
Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable =
587587
(Map) mockClusterServersWithTables(serverMap);
588588
List<RegionPlan> plans = loadBalancer.balanceCluster(LoadOfAllTable);
589-
assertNotNull("Initial cluster balance should produce plans.", plans);
589+
assertNotNull(plans, "Initial cluster balance should produce plans.");
590590

591591
// Check to see that this actually got to a stable place.
592592
if (assertFullyBalanced || assertFullyBalancedForReplicas) {
@@ -600,8 +600,8 @@ protected void testWithCluster(Map<ServerName, List<RegionInfo>> serverMap,
600600
assertClusterAsBalanced(balancedCluster);
601601
LoadOfAllTable = (Map) mockClusterServersWithTables(serverMap);
602602
List<RegionPlan> secondPlans = loadBalancer.balanceCluster(LoadOfAllTable);
603-
assertNull("Given a requirement to be fully balanced, second attempt at plans should "
604-
+ "produce none.", secondPlans);
603+
assertNull(secondPlans, "Given a requirement to be fully balanced, second attempt at plans "
604+
+ "should produce none.");
605605
}
606606

607607
if (assertFullyBalancedForReplicas) {
@@ -620,7 +620,7 @@ protected void testWithClusterWithIteration(Map<ServerName, List<RegionInfo>> se
620620
Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable =
621621
(Map) mockClusterServersWithTables(serverMap);
622622
List<RegionPlan> plans = loadBalancer.balanceCluster(LoadOfAllTable);
623-
assertNotNull("Initial cluster balance should produce plans.", plans);
623+
assertNotNull(plans, "Initial cluster balance should produce plans.");
624624

625625
List<ServerAndLoad> balancedCluster = null;
626626
// Run through iteration until done. Otherwise will be killed as test time out
@@ -639,8 +639,8 @@ protected void testWithClusterWithIteration(Map<ServerName, List<RegionInfo>> se
639639
LOG.info("Mock Final balance: " + printMock(balancedCluster));
640640

641641
if (assertFullyBalanced) {
642-
assertNull("Given a requirement to be fully balanced, second attempt at plans should "
643-
+ "produce none.", plans);
642+
assertNull(plans, "Given a requirement to be fully balanced, second attempt at plans should "
643+
+ "produce none.");
644644
}
645645
if (assertFullyBalancedForReplicas) {
646646
assertRegionReplicaPlacement(serverMap, rackManager);

0 commit comments

Comments
 (0)