Skip to content

Commit 47a9c6f

Browse files
authored
HBASE-30057 Upgrade hbase-server to use junit5 Part5 (#8048) (#8050)
(cherry picked from commit d2a989d) Signed-off-by: Xiao Liu <liuxiaocs@apache.org>
1 parent 4a27d7d commit 47a9c6f

48 files changed

Lines changed: 879 additions & 1092 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/GenericTestUtils.java

Lines changed: 12 additions & 10 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.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.fail;
23+
2024
import java.io.File;
2125
import java.io.IOException;
2226
import java.lang.management.ManagementFactory;
@@ -32,7 +36,6 @@
3236
import java.util.regex.Pattern;
3337
import org.apache.hadoop.fs.FileUtil;
3438
import org.apache.hadoop.util.Time;
35-
import org.junit.Assert;
3639
import org.mockito.invocation.InvocationOnMock;
3740
import org.mockito.stubbing.Answer;
3841
import org.slf4j.Logger;
@@ -68,7 +71,7 @@ public static int uniqueSequenceId() {
6871
* Assert that a given file exists.
6972
*/
7073
public static void assertExists(File f) {
71-
Assert.assertTrue("File " + f + " should exist", f.exists());
74+
assertTrue(f.exists(), "File " + f + " should exist");
7275
}
7376

7477
/**
@@ -86,8 +89,8 @@ public static void assertGlobEquals(File dir, String pattern, String... expected
8689
}
8790
}
8891
Set<String> expectedSet = Sets.newTreeSet(Arrays.asList(expectedMatches));
89-
Assert.assertEquals("Bad files matching " + pattern + " in " + dir,
90-
Joiner.on(",").join(expectedSet), Joiner.on(",").join(found));
92+
assertEquals("Bad files matching " + pattern + " in " + dir, Joiner.on(",").join(expectedSet),
93+
Joiner.on(",").join(found));
9194
}
9295

9396
public static void waitFor(Supplier<Boolean> check, int checkEveryMillis, int waitForMillis)
@@ -273,18 +276,17 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
273276
}
274277

275278
public static void assertMatches(String output, String pattern) {
276-
Assert.assertTrue("Expected output to match /" + pattern + "/" + " but got:\n" + output,
277-
Pattern.compile(pattern).matcher(output).find());
279+
assertTrue(Pattern.compile(pattern).matcher(output).find(),
280+
"Expected output to match /" + pattern + "/" + " but got:\n" + output);
278281
}
279282

280283
public static void assertValueNear(long expected, long actual, long allowedError) {
281284
assertValueWithinRange(expected - allowedError, expected + allowedError, actual);
282285
}
283286

284287
public static void assertValueWithinRange(long expectedMin, long expectedMax, long actual) {
285-
Assert.assertTrue(
286-
"Expected " + actual + " to be in range (" + expectedMin + "," + expectedMax + ")",
287-
expectedMin <= actual && actual <= expectedMax);
288+
assertTrue(expectedMin <= actual && actual <= expectedMax,
289+
"Expected " + actual + " to be in range (" + expectedMin + "," + expectedMax + ")");
288290
}
289291

290292
/**
@@ -299,7 +301,7 @@ public static void assertNoThreadsMatching(String regex) {
299301
for (ThreadInfo info : infos) {
300302
if (info == null) continue;
301303
if (pattern.matcher(info.getThreadName()).matches()) {
302-
Assert.fail("Leaked thread: " + info + "\n" + Joiner.on("\n").join(info.getStackTrace()));
304+
fail("Leaked thread: " + info + "\n" + Joiner.on("\n").join(info.getStackTrace()));
303305
}
304306
}
305307
}

hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.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;
@@ -2422,11 +2422,11 @@ public void verifyNumericRows(Table table, final byte[] f, int startRow, int end
24222422
get.setReplicaId(replicaId);
24232423
get.setConsistency(Consistency.TIMELINE);
24242424
Result result = table.get(get);
2425-
assertTrue(failMsg, result.containsColumn(f, null));
2426-
assertEquals(failMsg, 1, result.getColumnCells(f, null).size());
2425+
assertTrue(result.containsColumn(f, null), failMsg);
2426+
assertEquals(1, result.getColumnCells(f, null).size(), failMsg);
24272427
Cell cell = result.getColumnLatestCell(f, null);
2428-
assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(),
2429-
cell.getValueOffset(), cell.getValueLength()));
2428+
assertTrue(Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(),
2429+
cell.getValueLength()), failMsg);
24302430
}
24312431
}
24322432

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

24552455
boolean hasResult = result != null && !result.isEmpty();
2456-
assertEquals(failMsg + result, present, hasResult);
2456+
assertEquals(present, hasResult);
24572457
if (!present) continue;
24582458

2459-
assertTrue(failMsg, result.containsColumn(f, null));
2460-
assertEquals(failMsg, 1, result.getColumnCells(f, null).size());
2459+
assertTrue(result.containsColumn(f, null), failMsg);
2460+
assertEquals(1, result.getColumnCells(f, null).size(), failMsg);
24612461
Cell cell = result.getColumnLatestCell(f, null);
2462-
assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(),
2463-
cell.getValueOffset(), cell.getValueLength()));
2462+
assertTrue(Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(),
2463+
cell.getValueLength()), failMsg);
24642464
}
24652465
}
24662466

@@ -4007,8 +4007,8 @@ public void assertRegionOnlyOnServer(final RegionInfo hri, final ServerName serv
40074007
}
40084008
Collection<HRegion> hrs = rs.getOnlineRegionsLocalContext();
40094009
for (HRegion r : hrs) {
4010-
assertTrue("Region should not be double assigned",
4011-
r.getRegionInfo().getRegionId() != hri.getRegionId());
4010+
assertTrue(r.getRegionInfo().getRegionId() != hri.getRegionId(),
4011+
"Region should not be double assigned");
40124012
}
40134013
}
40144014
return; // good, we are happy

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
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.regionserver.AnnotationReadingPriorityFunction;
@@ -37,7 +37,7 @@ protected void checkMethod(Configuration conf, final String methodName, final in
3737
final AnnotationReadingPriorityFunction qosf, final Message param) {
3838
RPCProtos.RequestHeader.Builder builder = RPCProtos.RequestHeader.newBuilder();
3939
builder.setMethodName(methodName);
40-
assertEquals(methodName, expected, qosf.getPriority(builder.build(), param,
41-
User.createUserForTesting(conf, "someuser", new String[] { "somegroup" })));
40+
assertEquals(expected, qosf.getPriority(builder.build(), param,
41+
User.createUserForTesting(conf, "someuser", new String[] { "somegroup" })), methodName);
4242
}
4343
}

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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
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

0 commit comments

Comments
 (0)