Skip to content

Commit da33fb0

Browse files
committed
HBASE-30012 Upgrade hbase-server to use junit5 Part2
1 parent c78724a commit da33fb0

66 files changed

Lines changed: 1149 additions & 1485 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-server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309
</dependency>
310310
<dependency>
311311
<groupId>org.mockito</groupId>
312-
<artifactId>mockito-core</artifactId>
312+
<artifactId>mockito-junit-jupiter</artifactId>
313313
<scope>test</scope>
314314
</dependency>
315315
<dependency>

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
@@ -43,8 +43,8 @@
4343
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
4444
import org.apache.hadoop.hbase.util.CommonFSUtils;
4545
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
46-
import org.junit.AfterClass;
47-
import org.junit.BeforeClass;
46+
import org.junit.jupiter.api.AfterAll;
47+
import org.junit.jupiter.api.BeforeAll;
4848

4949
public abstract class MasterStateStoreTestBase {
5050

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

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

96-
@AfterClass
96+
@AfterAll
9797
public static void tearDownAfterClass() throws IOException {
9898
REGION.close(true);
9999
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

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

Lines changed: 27 additions & 32 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.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;
2324
import static org.mockito.Mockito.mock;
2425
import static org.mockito.Mockito.when;
2526

@@ -56,9 +57,6 @@
5657
import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
5758
import org.apache.hadoop.hbase.rsgroup.RSGroupInfoManager;
5859
import org.apache.hadoop.hbase.util.Bytes;
59-
import org.mockito.Mockito;
60-
import org.mockito.invocation.InvocationOnMock;
61-
import org.mockito.stubbing.Answer;
6260

6361
import org.apache.hbase.thirdparty.com.google.common.collect.ArrayListMultimap;
6462
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
@@ -128,8 +126,8 @@ protected void assertImmediateAssignment(List<RegionInfo> regions, List<ServerNa
128126
tableDescs.get(tableName).getRegionServerGroup().orElse(RSGroupInfo.DEFAULT_GROUP);
129127
assertTrue(StringUtils.isNotEmpty(groupName));
130128
RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName);
131-
assertTrue("Region is not correctly assigned to group servers.",
132-
gInfo.containsServer(server.getAddress()));
129+
assertTrue(gInfo.containsServer(server.getAddress()),
130+
"Region is not correctly assigned to group servers.");
133131
}
134132
}
135133

@@ -150,8 +148,8 @@ protected void assertRetainedAssignment(Map<RegionInfo, ServerName> existing,
150148
Set<ServerName> onlineServerSet = new TreeSet<>(servers);
151149
Set<RegionInfo> assignedRegions = new TreeSet<>(RegionInfo.COMPARATOR);
152150
for (Map.Entry<ServerName, List<RegionInfo>> a : assignment.entrySet()) {
153-
assertTrue("Region assigned to server that was not listed as online",
154-
onlineServerSet.contains(a.getKey()));
151+
assertTrue(onlineServerSet.contains(a.getKey()),
152+
"Region assigned to server that was not listed as online");
155153
for (RegionInfo r : a.getValue()) {
156154
assignedRegions.add(r);
157155
}
@@ -173,8 +171,8 @@ protected void assertRetainedAssignment(Map<RegionInfo, ServerName> existing,
173171
tableDescs.get(tableName).getRegionServerGroup().orElse(RSGroupInfo.DEFAULT_GROUP);
174172
assertTrue(StringUtils.isNotEmpty(groupName));
175173
RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName);
176-
assertTrue("Region is not correctly assigned to group servers.",
177-
gInfo.containsServer(currentServer.getAddress()));
174+
assertTrue(gInfo.containsServer(currentServer.getAddress()),
175+
"Region is not correctly assigned to group servers.");
178176
if (
179177
oldAssignedServer != null && onlineHostNames.contains(oldAssignedServer.getHostname())
180178
) {
@@ -232,7 +230,7 @@ protected String printStats(ArrayListMultimap<String, ServerAndLoad> groupBasedL
232230
}
233231
}
234232
List<RegionInfo> regions = serversMap.get(actual);
235-
assertTrue("No load for " + actual, regions != null);
233+
assertTrue(regions != null, "No load for " + actual);
236234
loadMap.put(gInfo.getName(), new ServerAndLoad(actual, regions.size()));
237235
}
238236
}
@@ -389,31 +387,28 @@ protected static Map<TableName, TableDescriptor> constructTableDesc(boolean hasB
389387
}
390388

391389
protected static MasterServices getMockedMaster() throws IOException {
392-
TableDescriptors tds = Mockito.mock(TableDescriptors.class);
393-
Mockito.when(tds.get(tables[0])).thenReturn(tableDescs.get(tables[0]));
394-
Mockito.when(tds.get(tables[1])).thenReturn(tableDescs.get(tables[1]));
395-
Mockito.when(tds.get(tables[2])).thenReturn(tableDescs.get(tables[2]));
396-
Mockito.when(tds.get(tables[3])).thenReturn(tableDescs.get(tables[3]));
397-
MasterServices services = Mockito.mock(HMaster.class);
398-
Mockito.when(services.getTableDescriptors()).thenReturn(tds);
399-
AssignmentManager am = Mockito.mock(AssignmentManager.class);
400-
Mockito.when(services.getAssignmentManager()).thenReturn(am);
401-
Mockito.when(services.getConfiguration()).thenReturn(conf);
390+
TableDescriptors tds = mock(TableDescriptors.class);
391+
when(tds.get(tables[0])).thenReturn(tableDescs.get(tables[0]));
392+
when(tds.get(tables[1])).thenReturn(tableDescs.get(tables[1]));
393+
when(tds.get(tables[2])).thenReturn(tableDescs.get(tables[2]));
394+
when(tds.get(tables[3])).thenReturn(tableDescs.get(tables[3]));
395+
MasterServices services = mock(HMaster.class);
396+
when(services.getTableDescriptors()).thenReturn(tds);
397+
AssignmentManager am = mock(AssignmentManager.class);
398+
when(services.getAssignmentManager()).thenReturn(am);
399+
when(services.getConfiguration()).thenReturn(conf);
402400
RSGroupInfoManager manager = getMockedGroupInfoManager();
403-
Mockito.when(services.getRSGroupInfoManager()).thenReturn(manager);
401+
when(services.getRSGroupInfoManager()).thenReturn(manager);
404402
return services;
405403
}
406404

407405
protected static RSGroupInfoManager getMockedGroupInfoManager() throws IOException {
408-
RSGroupInfoManager gm = Mockito.mock(RSGroupInfoManager.class);
409-
Mockito.when(gm.getRSGroup(Mockito.any())).thenAnswer(new Answer<RSGroupInfo>() {
410-
@Override
411-
public RSGroupInfo answer(InvocationOnMock invocation) throws Throwable {
412-
return groupMap.get(invocation.getArgument(0));
413-
}
406+
RSGroupInfoManager gm = mock(RSGroupInfoManager.class);
407+
when(gm.getRSGroup(any())).thenAnswer(invocation -> {
408+
return groupMap.get(invocation.getArgument(0));
414409
});
415-
Mockito.when(gm.listRSGroups()).thenReturn(Lists.newLinkedList(groupMap.values()));
416-
Mockito.when(gm.isOnline()).thenReturn(true);
410+
when(gm.listRSGroups()).thenReturn(Lists.newLinkedList(groupMap.values()));
411+
when(gm.isOnline()).thenReturn(true);
417412
return gm;
418413
}
419414

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

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

20-
import static org.junit.Assert.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
2121

2222
import java.util.Random;
2323
import java.util.concurrent.ThreadLocalRandom;
2424
import org.apache.hadoop.conf.Configuration;
25-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2625
import org.apache.hadoop.hbase.HBaseTestingUtil;
2726
import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
2827
import org.apache.hadoop.hbase.master.HMaster;
2928
import org.apache.hadoop.hbase.testclassification.MediumTests;
29+
import org.apache.hadoop.hbase.testclassification.MiscTests;
3030
import org.apache.hadoop.metrics2.MetricsSource;
3131
import org.apache.hadoop.metrics2.MetricsTag;
3232
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
33-
import org.junit.AfterClass;
34-
import org.junit.BeforeClass;
35-
import org.junit.ClassRule;
36-
import org.junit.Test;
37-
import org.junit.experimental.categories.Category;
33+
import org.junit.jupiter.api.AfterAll;
34+
import org.junit.jupiter.api.BeforeAll;
35+
import org.junit.jupiter.api.Tag;
36+
import org.junit.jupiter.api.Test;
3837
import org.slf4j.Logger;
3938
import org.slf4j.LoggerFactory;
4039

41-
@Category({ MediumTests.class })
40+
@Tag(MiscTests.TAG)
41+
@Tag(MediumTests.TAG)
4242
public class TestBalancerStatusTagInJMXMetrics extends BalancerTestBase {
4343

44-
@ClassRule
45-
public static final HBaseClassTestRule CLASS_RULE =
46-
HBaseClassTestRule.forClass(TestBalancerStatusTagInJMXMetrics.class);
47-
4844
private static final Logger LOG =
4945
LoggerFactory.getLogger(TestBalancerStatusTagInJMXMetrics.class);
5046
private static HBaseTestingUtil UTIL = new HBaseTestingUtil();
@@ -56,7 +52,7 @@ public class TestBalancerStatusTagInJMXMetrics extends BalancerTestBase {
5652
/**
5753
* Setup the environment for the test.
5854
*/
59-
@BeforeClass
55+
@BeforeAll
6056
public static void setupBeforeClass() throws Exception {
6157
conf = UTIL.getConfiguration();
6258
Random rand = ThreadLocalRandom.current();
@@ -85,7 +81,7 @@ public static void setupBeforeClass() throws Exception {
8581
}
8682
}
8783

88-
@AfterClass
84+
@AfterAll
8985
public static void tearDownAfterClass() throws Exception {
9086
UTIL.shutdownMiniCluster();
9187
}
@@ -96,9 +92,9 @@ public static void tearDownAfterClass() throws Exception {
9692
@Test
9793
public void testJmxMetrics() throws Exception {
9894

99-
assertEquals(getStatus(), "true");
95+
assertEquals("true", getStatus());
10096
master.getLoadBalancer().updateBalancerStatus(false);
101-
assertEquals(getStatus(), "false");
97+
assertEquals("false", getStatus());
10298

10399
}
104100

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

Lines changed: 7 additions & 12 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.assertNull;
21-
import static org.junit.Assert.fail;
20+
import static org.junit.jupiter.api.Assertions.assertNull;
21+
import static org.junit.jupiter.api.Assertions.fail;
2222
import static org.mockito.Mockito.mock;
2323
import static org.mockito.Mockito.when;
2424

@@ -31,7 +31,6 @@
3131
import java.util.concurrent.ThreadLocalRandom;
3232
import org.apache.hadoop.conf.Configuration;
3333
import org.apache.hadoop.hbase.ClusterMetrics;
34-
import org.apache.hadoop.hbase.HBaseClassTestRule;
3534
import org.apache.hadoop.hbase.HBaseConfiguration;
3635
import org.apache.hadoop.hbase.HConstants;
3736
import org.apache.hadoop.hbase.RegionMetrics;
@@ -45,20 +44,16 @@
4544
import org.apache.hadoop.hbase.master.RegionPlan;
4645
import org.apache.hadoop.hbase.testclassification.LargeTests;
4746
import org.apache.hadoop.hbase.util.Bytes;
48-
import org.junit.BeforeClass;
49-
import org.junit.ClassRule;
50-
import org.junit.Test;
51-
import org.junit.experimental.categories.Category;
47+
import org.junit.jupiter.api.BeforeAll;
48+
import org.junit.jupiter.api.Tag;
49+
import org.junit.jupiter.api.Test;
5250
import org.slf4j.Logger;
5351
import org.slf4j.LoggerFactory;
5452

5553
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
5654

57-
@Category({ LargeTests.class })
55+
@Tag(LargeTests.TAG)
5856
public class TestCacheAwareLoadBalancer extends BalancerTestBase {
59-
@ClassRule
60-
public static final HBaseClassTestRule CLASS_RULE =
61-
HBaseClassTestRule.forClass(TestCacheAwareLoadBalancer.class);
6257

6358
private static final Logger LOG = LoggerFactory.getLogger(TestCacheAwareLoadBalancer.class);
6459

@@ -115,7 +110,7 @@ private ServerMetrics mockServerMetricsWithRegionCacheInfo(ServerName server,
115110
return serverMetrics;
116111
}
117112

118-
@BeforeClass
113+
@BeforeAll
119114
public static void beforeAllTests() throws Exception {
120115
servers = generateServers(3);
121116
tableDescs = constructTableDesc(false);

0 commit comments

Comments
 (0)