Skip to content

Commit 8c720ae

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

86 files changed

Lines changed: 1373 additions & 1804 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/BalancerConditionalsTestUtil.java

Lines changed: 15 additions & 16 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.assertNotEquals;
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.assertNotEquals;
2323

2424
import java.io.IOException;
2525
import java.util.HashSet;
@@ -130,16 +130,15 @@ static void validateReplicaDistribution(Connection connection, TableName tableNa
130130
Set<byte[]> startKeys = new HashSet<>();
131131
for (RegionInfo regionInfo : regionInfos) {
132132
// each region should have a distinct start key
133-
assertFalse(
133+
assertFalse(startKeys.contains(regionInfo.getStartKey()),
134134
"Each region should have its own start key, "
135-
+ "demonstrating it is not a replica of any others on this host",
136-
startKeys.contains(regionInfo.getStartKey()));
135+
+ "demonstrating it is not a replica of any others on this host");
137136
startKeys.add(regionInfo.getStartKey());
138137
}
139138
}
140139
} else {
141140
// Ensure all replicas are on the same server
142-
assertEquals("All regions should share one server", 1, serverToRegions.size());
141+
assertEquals(1, serverToRegions.size(), "All regions should share one server");
143142
}
144143
}
145144

@@ -153,19 +152,19 @@ static void validateRegionLocations(Map<TableName, Set<ServerName>> tableToServe
153152

154153
if (shouldBeBalanced) {
155154
for (ServerName server : productServers) {
156-
assertNotEquals("Meta table and product table should not share servers", server,
157-
metaServer);
158-
assertNotEquals("Quota table and product table should not share servers", server,
159-
quotaServer);
155+
assertNotEquals(server, metaServer,
156+
"Meta table and product table should not share servers");
157+
assertNotEquals(server, quotaServer,
158+
"Quota table and product table should not share servers");
160159
}
161-
assertNotEquals("The meta server and quotas server should be different", metaServer,
162-
quotaServer);
160+
assertNotEquals(metaServer, quotaServer,
161+
"The meta server and quotas server should be different");
163162
} else {
164163
for (ServerName server : productServers) {
165-
assertEquals("Meta table and product table must share servers", server, metaServer);
166-
assertEquals("Quota table and product table must share servers", server, quotaServer);
164+
assertEquals(server, metaServer, "Meta table and product table must share servers");
165+
assertEquals(server, quotaServer, "Quota table and product table must share servers");
167166
}
168-
assertEquals("The meta server and quotas server must be the same", metaServer, quotaServer);
167+
assertEquals(metaServer, quotaServer, "The meta server and quotas server must be the same");
169168
}
170169
}
171170

0 commit comments

Comments
 (0)