Skip to content

Commit 31e5517

Browse files
authored
HBASE-30057 Upgrade hbase-server to use junit5 Part5 (#8043)
Signed-off-by: Xiao Liu <liuxiaocs@apache.org>
1 parent 03f9f17 commit 31e5517

45 files changed

Lines changed: 747 additions & 950 deletions

Some content is hidden

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

hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtil.java

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

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

2424
import edu.umd.cs.findbugs.annotations.Nullable;
2525
import java.io.Closeable;
@@ -2013,11 +2013,11 @@ public void verifyNumericRows(Table table, final byte[] f, int startRow, int end
20132013
get.setReplicaId(replicaId);
20142014
get.setConsistency(Consistency.TIMELINE);
20152015
Result result = table.get(get);
2016-
assertTrue(failMsg, result.containsColumn(f, null));
2017-
assertEquals(failMsg, 1, result.getColumnCells(f, null).size());
2016+
assertTrue(result.containsColumn(f, null), failMsg);
2017+
assertEquals(1, result.getColumnCells(f, null).size(), failMsg);
20182018
Cell cell = result.getColumnLatestCell(f, null);
2019-
assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(),
2020-
cell.getValueOffset(), cell.getValueLength()));
2019+
assertTrue(Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(),
2020+
cell.getValueLength()), failMsg);
20212021
}
20222022
}
20232023

@@ -2044,14 +2044,14 @@ public void verifyNumericRows(HRegion region, final byte[] f, int startRow, int
20442044
Result result = region.get(new Get(data));
20452045

20462046
boolean hasResult = result != null && !result.isEmpty();
2047-
assertEquals(failMsg + result, present, hasResult);
2047+
assertEquals(present, hasResult, failMsg + result);
20482048
if (!present) continue;
20492049

2050-
assertTrue(failMsg, result.containsColumn(f, null));
2051-
assertEquals(failMsg, 1, result.getColumnCells(f, null).size());
2050+
assertTrue(result.containsColumn(f, null), failMsg);
2051+
assertEquals(1, result.getColumnCells(f, null).size(), failMsg);
20522052
Cell cell = result.getColumnLatestCell(f, null);
2053-
assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(),
2054-
cell.getValueOffset(), cell.getValueLength()));
2053+
assertTrue(Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(),
2054+
cell.getValueLength()), failMsg);
20552055
}
20562056
}
20572057

@@ -3408,8 +3408,8 @@ public void assertRegionOnlyOnServer(final RegionInfo hri, final ServerName serv
34083408
}
34093409
Collection<HRegion> hrs = rs.getOnlineRegionsLocalContext();
34103410
for (HRegion r : hrs) {
3411-
assertTrue("Region should not be double assigned",
3412-
r.getRegionInfo().getRegionId() != hri.getRegionId());
3411+
assertTrue(r.getRegionInfo().getRegionId() != hri.getRegionId(),
3412+
"Region should not be double assigned");
34133413
}
34143414
}
34153415
return; // good, we are happy

hbase-server/src/test/java/org/apache/hadoop/hbase/TestCacheEviction.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import static org.apache.hadoop.hbase.io.hfile.CacheConfig.EVICT_BLOCKS_ON_CLOSE_KEY;
2424
import static org.apache.hadoop.hbase.io.hfile.CacheConfig.EVICT_BLOCKS_ON_SPLIT_KEY;
2525
import static org.apache.hadoop.hbase.io.hfile.CacheConfig.PREFETCH_BLOCKS_ON_OPEN_KEY;
26-
import static org.junit.Assert.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
2727

2828
import java.io.IOException;
2929
import java.util.ArrayList;
@@ -42,26 +42,18 @@
4242
import org.apache.hadoop.hbase.testclassification.MiscTests;
4343
import org.apache.hadoop.hbase.util.Bytes;
4444
import org.apache.hadoop.hbase.util.Pair;
45-
import org.junit.Before;
46-
import org.junit.BeforeClass;
47-
import org.junit.ClassRule;
48-
import org.junit.Test;
49-
import org.junit.experimental.categories.Category;
50-
import org.slf4j.Logger;
51-
import org.slf4j.LoggerFactory;
52-
53-
@Category({ MiscTests.class, LargeTests.class })
54-
public class TestCacheEviction {
55-
56-
@ClassRule
57-
public static final HBaseClassTestRule CLASS_RULE =
58-
HBaseClassTestRule.forClass(TestCacheEviction.class);
45+
import org.junit.jupiter.api.BeforeAll;
46+
import org.junit.jupiter.api.BeforeEach;
47+
import org.junit.jupiter.api.Tag;
48+
import org.junit.jupiter.api.Test;
5949

60-
private static final Logger LOG = LoggerFactory.getLogger(TestCacheEviction.class);
50+
@Tag(MiscTests.TAG)
51+
@Tag(LargeTests.TAG)
52+
public class TestCacheEviction {
6153

6254
private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
6355

64-
@BeforeClass
56+
@BeforeAll
6557
public static void setUp() throws Exception {
6658
UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 1000);
6759
UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
@@ -71,7 +63,7 @@ public static void setUp() throws Exception {
7163
UTIL.getConfiguration().set(StoreFileTrackerFactory.TRACKER_IMPL, "FILE");
7264
}
7365

74-
@Before
66+
@BeforeEach
7567
public void testSetup() {
7668
UTIL.getConfiguration().set(BUCKET_CACHE_IOENGINE_KEY,
7769
"file:" + UTIL.getDataTestDir() + "/bucketcache");

hbase-server/src/test/java/org/apache/hadoop/hbase/TestCachedClusterId.java

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

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

2222
import org.apache.hadoop.conf.Configuration;
2323
import org.apache.hadoop.hbase.MultithreadedTestUtil.TestContext;
2424
import org.apache.hadoop.hbase.MultithreadedTestUtil.TestThread;
2525
import org.apache.hadoop.hbase.master.CachedClusterId;
2626
import org.apache.hadoop.hbase.master.HMaster;
2727
import org.apache.hadoop.hbase.testclassification.MediumTests;
28-
import org.junit.AfterClass;
29-
import org.junit.BeforeClass;
30-
import org.junit.ClassRule;
31-
import org.junit.Test;
32-
import org.junit.experimental.categories.Category;
28+
import org.apache.hadoop.hbase.testclassification.MiscTests;
29+
import org.junit.jupiter.api.AfterAll;
30+
import org.junit.jupiter.api.BeforeAll;
31+
import org.junit.jupiter.api.Tag;
32+
import org.junit.jupiter.api.Test;
3333

34-
@Category(MediumTests.class)
34+
@Tag(MiscTests.TAG)
35+
@Tag(MediumTests.TAG)
3536
public class TestCachedClusterId {
36-
@ClassRule
37-
public static final HBaseClassTestRule CLASS_RULE =
38-
HBaseClassTestRule.forClass(TestCachedClusterId.class);
3937

4038
private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
4139

@@ -57,15 +55,15 @@ public void doWork() throws Exception {
5755
}
5856
}
5957

60-
@BeforeClass
58+
@BeforeAll
6159
public static void setUp() throws Exception {
6260
TEST_UTIL.startMiniCluster(1);
6361
activeMaster = TEST_UTIL.getHBaseCluster().getMaster();
6462
clusterId = activeMaster.getClusterId();
6563
standByMaster = TEST_UTIL.getHBaseCluster().startMaster().getMaster();
6664
}
6765

68-
@AfterClass
66+
@AfterAll
6967
public static void tearDown() throws Exception {
7068
TEST_UTIL.shutdownMiniCluster();
7169
}

hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828

2929
/**
3030
* Checks tests are categorized.
31+
* <p>
32+
* @deprecated Will be removed after we fully upgrade to junit5, so keep it as is.
3133
*/
34+
@Deprecated
3235
@Category({ MiscTests.class, SmallTests.class })
3336
public class TestCheckTestClasses {
3437

hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterStatus.java

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

20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
2024
import java.io.IOException;
2125
import java.util.EnumSet;
2226
import java.util.List;
@@ -34,33 +38,29 @@
3438
import org.apache.hadoop.hbase.master.HMaster;
3539
import org.apache.hadoop.hbase.regionserver.HRegionServer;
3640
import org.apache.hadoop.hbase.testclassification.MediumTests;
41+
import org.apache.hadoop.hbase.testclassification.MiscTests;
3742
import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread;
3843
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
39-
import org.junit.AfterClass;
40-
import org.junit.Assert;
41-
import org.junit.BeforeClass;
42-
import org.junit.ClassRule;
43-
import org.junit.Test;
44-
import org.junit.experimental.categories.Category;
44+
import org.junit.jupiter.api.AfterAll;
45+
import org.junit.jupiter.api.BeforeAll;
46+
import org.junit.jupiter.api.Tag;
47+
import org.junit.jupiter.api.Test;
4548

4649
/**
4750
* Test the ClusterStatus.
4851
*/
49-
@Category(MediumTests.class)
52+
@Tag(MiscTests.TAG)
53+
@Tag(MediumTests.TAG)
5054
public class TestClientClusterStatus {
5155

52-
@ClassRule
53-
public static final HBaseClassTestRule CLASS_RULE =
54-
HBaseClassTestRule.forClass(TestClientClusterStatus.class);
55-
5656
private static HBaseTestingUtil UTIL;
5757
private static Admin ADMIN;
5858
private final static int SLAVES = 5;
5959
private final static int MASTERS = 3;
6060
private static SingleProcessHBaseCluster CLUSTER;
6161
private static HRegionServer DEAD;
6262

63-
@BeforeClass
63+
@BeforeAll
6464
public static void setUpBeforeClass() throws Exception {
6565
Configuration conf = HBaseConfiguration.create();
6666
conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MyObserver.class.getName());
@@ -87,8 +87,7 @@ public void testNone() throws Exception {
8787
ClusterMetrics status1 = ADMIN.getClusterMetrics(EnumSet.noneOf(Option.class));
8888
// Do a rough compare. More specific compares can fail because all regions not deployed yet
8989
// or more requests than expected.
90-
Assert.assertEquals(status0.getLiveServerMetrics().size(),
91-
status1.getLiveServerMetrics().size());
90+
assertEquals(status0.getLiveServerMetrics().size(), status1.getLiveServerMetrics().size());
9291
}
9392

9493
@Test
@@ -108,29 +107,29 @@ public void testLiveAndDeadServersStatus() throws Exception {
108107
@Override
109108
public boolean evaluate() throws Exception {
110109
ClusterMetrics status = ADMIN.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
111-
Assert.assertNotNull(status);
110+
assertNotNull(status);
112111
return status.getRegionCount() > 0;
113112
}
114113
});
115114
// Retrieve live servers and dead servers info.
116115
EnumSet<Option> options =
117116
EnumSet.of(Option.LIVE_SERVERS, Option.DEAD_SERVERS, Option.SERVERS_NAME);
118117
ClusterMetrics status = ADMIN.getClusterMetrics(options);
119-
Assert.assertNotNull(status);
120-
Assert.assertNotNull(status.getLiveServerMetrics().keySet());
118+
assertNotNull(status);
119+
assertNotNull(status.getLiveServerMetrics().keySet());
121120
// exclude a dead region server
122-
Assert.assertEquals(SLAVES - 1, numRs);
121+
assertEquals(SLAVES - 1, numRs);
123122
// live servers = nums of regionservers
124123
// By default, HMaster don't carry any regions so it won't report its load.
125124
// Hence, it won't be in the server list.
126-
Assert.assertEquals(status.getLiveServerMetrics().keySet().size(), numRs);
127-
Assert.assertTrue(status.getRegionCount() > 0);
128-
Assert.assertNotNull(status.getDeadServerNames());
129-
Assert.assertEquals(1, status.getDeadServerNames().size());
125+
assertEquals(status.getLiveServerMetrics().keySet().size(), numRs);
126+
assertTrue(status.getRegionCount() > 0);
127+
assertNotNull(status.getDeadServerNames());
128+
assertEquals(1, status.getDeadServerNames().size());
130129
ServerName deadServerName = status.getDeadServerNames().iterator().next();
131-
Assert.assertEquals(DEAD.getServerName(), deadServerName);
132-
Assert.assertNotNull(status.getServersName());
133-
Assert.assertEquals(numRs, status.getServersName().size());
130+
assertEquals(DEAD.getServerName(), deadServerName);
131+
assertNotNull(status.getServersName());
132+
assertEquals(numRs, status.getServersName().size());
134133
}
135134

136135
@Test
@@ -149,29 +148,29 @@ public void testMasterAndBackupMastersStatus() throws Exception {
149148
activeName = active.getServerName();
150149
}
151150
}
152-
Assert.assertNotNull(active);
153-
Assert.assertEquals(1, numActive);
154-
Assert.assertEquals(MASTERS, masterThreads.size());
151+
assertNotNull(active);
152+
assertEquals(1, numActive);
153+
assertEquals(MASTERS, masterThreads.size());
155154
// Retrieve master and backup masters infos only.
156155
EnumSet<Option> options = EnumSet.of(Option.MASTER, Option.BACKUP_MASTERS);
157156
ClusterMetrics status = ADMIN.getClusterMetrics(options);
158-
Assert.assertTrue(status.getMasterName().equals(activeName));
159-
Assert.assertEquals(MASTERS - 1, status.getBackupMasterNames().size());
157+
assertTrue(status.getMasterName().equals(activeName));
158+
assertEquals(MASTERS - 1, status.getBackupMasterNames().size());
160159
}
161160

162161
@Test
163162
public void testOtherStatusInfos() throws Exception {
164163
EnumSet<Option> options = EnumSet.of(Option.MASTER_COPROCESSORS, Option.HBASE_VERSION,
165164
Option.CLUSTER_ID, Option.BALANCER_ON);
166165
ClusterMetrics status = ADMIN.getClusterMetrics(options);
167-
Assert.assertTrue(status.getMasterCoprocessorNames().size() == 1);
168-
Assert.assertNotNull(status.getHBaseVersion());
169-
Assert.assertNotNull(status.getClusterId());
170-
Assert.assertTrue(status.getAverageLoad() == 0.0);
171-
Assert.assertNotNull(status.getBalancerOn());
166+
assertTrue(status.getMasterCoprocessorNames().size() == 1);
167+
assertNotNull(status.getHBaseVersion());
168+
assertNotNull(status.getClusterId());
169+
assertTrue(status.getAverageLoad() == 0.0);
170+
assertNotNull(status.getBalancerOn());
172171
}
173172

174-
@AfterClass
173+
@AfterAll
175174
public static void tearDownAfterClass() throws Exception {
176175
if (ADMIN != null) ADMIN.close();
177176
UTIL.shutdownMiniCluster();
@@ -181,10 +180,10 @@ public static void tearDownAfterClass() throws Exception {
181180
public void testObserver() throws IOException {
182181
int preCount = MyObserver.PRE_COUNT.get();
183182
int postCount = MyObserver.POST_COUNT.get();
184-
Assert.assertTrue(ADMIN.getClusterMetrics().getMasterCoprocessorNames().stream()
183+
assertTrue(ADMIN.getClusterMetrics().getMasterCoprocessorNames().stream()
185184
.anyMatch(s -> s.equals(MyObserver.class.getSimpleName())));
186-
Assert.assertEquals(preCount + 1, MyObserver.PRE_COUNT.get());
187-
Assert.assertEquals(postCount + 1, MyObserver.POST_COUNT.get());
185+
assertEquals(preCount + 1, MyObserver.PRE_COUNT.get());
186+
assertEquals(postCount + 1, MyObserver.POST_COUNT.get());
188187
}
189188

190189
public static class MyObserver implements MasterCoprocessor, MasterObserver {

0 commit comments

Comments
 (0)