Skip to content

Commit 01c3b2d

Browse files
liuxiaocs7Apache9
authored andcommitted
HBASE-29879 Upgrade hbase-procedure to use junit5 (#7753)
Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit 01c6451)
1 parent b69e00c commit 01c3b2d

31 files changed

+433
-566
lines changed

hbase-procedure/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@
9191
<artifactId>junit-jupiter-params</artifactId>
9292
<scope>test</scope>
9393
</dependency>
94-
<dependency>
95-
<groupId>org.junit.vintage</groupId>
96-
<artifactId>junit-vintage-engine</artifactId>
97-
<scope>test</scope>
98-
</dependency>
9994
<dependency>
10095
<groupId>org.apache.hbase</groupId>
10196
<artifactId>hbase-metrics-api</artifactId>

hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/ProcedureTestingUtility.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
*/
1818
package org.apache.hadoop.hbase.procedure2;
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.assertInstanceOf;
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
import static org.junit.jupiter.api.Assertions.assertNull;
25+
import static org.junit.jupiter.api.Assertions.assertTrue;
2326

2427
import java.io.IOException;
2528
import java.util.ArrayList;
@@ -264,8 +267,8 @@ public static <TEnv> void setKillAndToggleBeforeStoreUpdateInRollback(
264267
if (
265268
procExecutor.testing.killBeforeStoreUpdate || procExecutor.testing.toggleKillBeforeStoreUpdate
266269
) {
267-
assertEquals("expected only one executor running during test with kill/restart", 1,
268-
procExecutor.getCorePoolSize());
270+
assertEquals(1, procExecutor.getCorePoolSize(),
271+
"expected only one executor running during test with kill/restart");
269272
}
270273
}
271274

@@ -342,48 +345,48 @@ public static <TEnv> void waitNoProcedureRunning(ProcedureExecutor<TEnv> procExe
342345

343346
public static <TEnv> void assertProcNotYetCompleted(ProcedureExecutor<TEnv> procExecutor,
344347
long procId) {
345-
assertFalse("expected a running proc", procExecutor.isFinished(procId));
346-
assertEquals(null, procExecutor.getResult(procId));
348+
assertFalse(procExecutor.isFinished(procId), "expected a running proc");
349+
assertNull(procExecutor.getResult(procId));
347350
}
348351

349352
public static <TEnv> void assertProcNotFailed(ProcedureExecutor<TEnv> procExecutor, long procId) {
350353
Procedure<?> result = procExecutor.getResult(procId);
351-
assertTrue("expected procedure result", result != null);
354+
assertNotNull(result, "expected procedure result");
352355
assertProcNotFailed(result);
353356
}
354357

355358
public static void assertProcNotFailed(final Procedure<?> result) {
356-
assertFalse("found exception: " + result.getException(), result.isFailed());
359+
assertFalse(result.isFailed(), "found exception: " + result.getException());
357360
}
358361

359362
public static <TEnv> Throwable assertProcFailed(final ProcedureExecutor<TEnv> procExecutor,
360363
final long procId) {
361364
Procedure<?> result = procExecutor.getResult(procId);
362-
assertTrue("expected procedure result", result != null);
365+
assertNotNull(result, "expected procedure result");
363366
return assertProcFailed(result);
364367
}
365368

366369
public static Throwable assertProcFailed(final Procedure<?> result) {
367-
assertEquals(true, result.isFailed());
370+
assertTrue(result.isFailed());
368371
LOG.info("procId=" + result.getProcId() + " exception: " + result.getException().getMessage());
369372
return getExceptionCause(result);
370373
}
371374

372375
public static void assertIsAbortException(final Procedure<?> result) {
373376
Throwable cause = assertProcFailed(result);
374-
assertTrue("expected abort exception, got " + cause,
375-
cause instanceof ProcedureAbortedException);
377+
assertInstanceOf(ProcedureAbortedException.class, cause,
378+
"expected abort exception, got " + cause);
376379
}
377380

378381
public static void assertIsTimeoutException(final Procedure<?> result) {
379382
Throwable cause = assertProcFailed(result);
380-
assertTrue("expected TimeoutIOException, got " + cause, cause instanceof TimeoutIOException);
383+
assertInstanceOf(TimeoutIOException.class, cause, "expected TimeoutIOException, got " + cause);
381384
}
382385

383386
public static void assertIsIllegalArgumentException(final Procedure<?> result) {
384387
Throwable cause = assertProcFailed(result);
385-
assertTrue("expected IllegalArgumentIOException, got " + cause,
386-
cause instanceof IllegalArgumentIOException);
388+
assertInstanceOf(IllegalArgumentIOException.class, cause,
389+
"expected IllegalArgumentIOException, got " + cause);
387390
}
388391

389392
public static Throwable getExceptionCause(final Procedure<?> procInfo) {
@@ -669,7 +672,7 @@ public void load(ProcedureIterator procIter) throws IOException {
669672
runnable.add(proc);
670673
}
671674
if (procIds != null) {
672-
assertTrue("procId=" + procId + " unexpected", procIds.contains(procId));
675+
assertTrue(procIds.contains(procId), "procId=" + procId + " unexpected");
673676
}
674677
}
675678
}

hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestChildProcedures.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,27 @@
1717
*/
1818
package org.apache.hadoop.hbase.procedure2;
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

2323
import java.io.IOException;
2424
import org.apache.hadoop.fs.FileSystem;
2525
import org.apache.hadoop.fs.Path;
26-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2726
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
2827
import org.apache.hadoop.hbase.procedure2.store.ProcedureStore;
2928
import org.apache.hadoop.hbase.testclassification.MasterTests;
3029
import org.apache.hadoop.hbase.testclassification.SmallTests;
31-
import org.junit.After;
32-
import org.junit.Before;
33-
import org.junit.ClassRule;
34-
import org.junit.Test;
35-
import org.junit.experimental.categories.Category;
30+
import org.junit.jupiter.api.AfterEach;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Tag;
33+
import org.junit.jupiter.api.Test;
3634
import org.slf4j.Logger;
3735
import org.slf4j.LoggerFactory;
3836

39-
@Category({ MasterTests.class, SmallTests.class })
37+
@Tag(MasterTests.TAG)
38+
@Tag(SmallTests.TAG)
4039
public class TestChildProcedures {
4140

42-
@ClassRule
43-
public static final HBaseClassTestRule CLASS_RULE =
44-
HBaseClassTestRule.forClass(TestChildProcedures.class);
45-
4641
private static final Logger LOG = LoggerFactory.getLogger(TestChildProcedures.class);
4742

4843
private static final int PROCEDURE_EXECUTOR_SLOTS = 1;
@@ -56,7 +51,7 @@ public class TestChildProcedures {
5651
private Path testDir;
5752
private Path logDir;
5853

59-
@Before
54+
@BeforeEach
6055
public void setUp() throws IOException {
6156
htu = new HBaseCommonTestingUtility();
6257
testDir = htu.getDataTestDir();
@@ -72,7 +67,7 @@ public void setUp() throws IOException {
7267
ProcedureTestingUtility.initAndStartWorkers(procExecutor, PROCEDURE_EXECUTOR_SLOTS, true);
7368
}
7469

75-
@After
70+
@AfterEach
7671
public void tearDown() throws IOException {
7772
procExecutor.stop();
7873
procStore.stop(false);
@@ -88,7 +83,7 @@ public void testChildLoad() throws Exception {
8883
ProcedureTestingUtility.restart(procExecutor);
8984
ProcedureTestingUtility.waitProcedure(procExecutor, proc);
9085

91-
assertTrue("expected completed proc", procExecutor.isFinished(procId));
86+
assertTrue(procExecutor.isFinished(procId), "expected completed proc");
9287
ProcedureTestingUtility.assertProcNotFailed(procExecutor, procId);
9388
}
9489

@@ -105,7 +100,7 @@ public void testChildLoadWithSteppedRestart() throws Exception {
105100
restartCount++;
106101
}
107102
assertEquals(3, restartCount);
108-
assertTrue("expected completed proc", procExecutor.isFinished(procId));
103+
assertTrue(procExecutor.isFinished(procId), "expected completed proc");
109104
ProcedureTestingUtility.assertProcNotFailed(procExecutor, procId);
110105
}
111106

@@ -126,7 +121,7 @@ public void testChildLoadWithRestartAfterChildSuccess() throws Exception {
126121
restartCount++;
127122
}
128123
assertEquals(4, restartCount);
129-
assertTrue("expected completed proc", procExecutor.isFinished(procId));
124+
assertTrue(procExecutor.isFinished(procId), "expected completed proc");
130125
ProcedureTestingUtility.assertProcNotFailed(procExecutor, procId);
131126
}
132127

@@ -161,9 +156,9 @@ public void testChildRollbackLoadWithSteppedRestart() throws Exception {
161156
}
162157

163158
private void assertProcFailed(long procId) {
164-
assertTrue("expected completed proc", procExecutor.isFinished(procId));
159+
assertTrue(procExecutor.isFinished(procId), "expected completed proc");
165160
Procedure<?> result = procExecutor.getResult(procId);
166-
assertEquals(true, result.isFailed());
161+
assertTrue(result.isFailed());
167162
LOG.info(result.getException().getMessage());
168163
}
169164

hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestForceUpdateProcedure.java

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,62 +17,55 @@
1717
*/
1818
package org.apache.hadoop.hbase.procedure2;
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

2323
import java.io.IOException;
2424
import java.util.HashMap;
2525
import java.util.Map;
2626
import java.util.concurrent.Exchanger;
2727
import org.apache.hadoop.fs.Path;
28-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2928
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
3029
import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.NoopProcedure;
3130
import org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore;
3231
import org.apache.hadoop.hbase.testclassification.MasterTests;
3332
import org.apache.hadoop.hbase.testclassification.SmallTests;
34-
import org.junit.After;
35-
import org.junit.AfterClass;
36-
import org.junit.Before;
37-
import org.junit.BeforeClass;
38-
import org.junit.ClassRule;
39-
import org.junit.Rule;
40-
import org.junit.Test;
41-
import org.junit.experimental.categories.Category;
42-
import org.junit.rules.TestName;
33+
import org.junit.jupiter.api.AfterAll;
34+
import org.junit.jupiter.api.AfterEach;
35+
import org.junit.jupiter.api.BeforeAll;
36+
import org.junit.jupiter.api.BeforeEach;
37+
import org.junit.jupiter.api.Tag;
38+
import org.junit.jupiter.api.Test;
39+
import org.junit.jupiter.api.TestInfo;
4340

4441
import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState;
4542

46-
@Category({ MasterTests.class, SmallTests.class })
43+
@Tag(MasterTests.TAG)
44+
@Tag(SmallTests.TAG)
4745
public class TestForceUpdateProcedure {
4846

49-
@ClassRule
50-
public static final HBaseClassTestRule CLASS_RULE =
51-
HBaseClassTestRule.forClass(TestForceUpdateProcedure.class);
52-
5347
private static HBaseCommonTestingUtility UTIL = new HBaseCommonTestingUtility();
5448

5549
private static WALProcedureStore STORE;
5650

5751
private static ProcedureExecutor<Void> EXEC;
5852

59-
private static Exchanger<Boolean> EXCHANGER = new Exchanger<>();
53+
private static final Exchanger<Boolean> EXCHANGER = new Exchanger<>();
6054

61-
private static int WAL_COUNT = 5;
55+
private static final int WAL_COUNT = 5;
6256

63-
@Rule
64-
public final TestName name = new TestName();
57+
private String methodName;
6558

6659
private void createStoreAndExecutor() throws IOException {
6760
UTIL.getConfiguration().setInt(CompletedProcedureCleaner.CLEANER_INTERVAL_CONF_KEY, 1000);
68-
Path logDir = UTIL.getDataTestDir(name.getMethodName());
61+
Path logDir = UTIL.getDataTestDir(methodName);
6962
STORE = ProcedureTestingUtility.createWalStore(UTIL.getConfiguration(), logDir);
7063
STORE.start(1);
71-
EXEC = new ProcedureExecutor<Void>(UTIL.getConfiguration(), null, STORE);
64+
EXEC = new ProcedureExecutor<>(UTIL.getConfiguration(), null, STORE);
7265
ProcedureTestingUtility.initAndStartWorkers(EXEC, 1, true);
7366
}
7467

75-
@BeforeClass
68+
@BeforeAll
7669
public static void setUpBeforeClass() throws IOException {
7770
UTIL.getConfiguration().setInt(WALProcedureStore.WAL_COUNT_WARN_THRESHOLD_CONF_KEY, WAL_COUNT);
7871
}
@@ -84,17 +77,18 @@ private void stopStoreAndExecutor() {
8477
STORE = null;
8578
}
8679

87-
@AfterClass
80+
@AfterAll
8881
public static void tearDownAfterClass() throws IOException {
8982
UTIL.cleanupTestDir();
9083
}
9184

92-
@Before
93-
public void setUp() throws IOException {
85+
@BeforeEach
86+
public void setUp(TestInfo testInfo) throws IOException {
87+
methodName = testInfo.getTestMethod().get().getName();
9488
createStoreAndExecutor();
9589
}
9690

97-
@After
91+
@AfterEach
9892
public void tearDown() {
9993
stopStoreAndExecutor();
10094
}

hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestLockAndQueue.java

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

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

2323
import java.util.HashMap;
2424
import java.util.Map;
25-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2625
import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.NoopProcedure;
2726
import org.apache.hadoop.hbase.testclassification.MasterTests;
2827
import org.apache.hadoop.hbase.testclassification.SmallTests;
29-
import org.junit.ClassRule;
30-
import org.junit.Test;
31-
import org.junit.experimental.categories.Category;
28+
import org.junit.jupiter.api.Tag;
29+
import org.junit.jupiter.api.Test;
3230

33-
@Category({ MasterTests.class, SmallTests.class })
31+
@Tag(MasterTests.TAG)
32+
@Tag(SmallTests.TAG)
3433
public class TestLockAndQueue {
3534

36-
@ClassRule
37-
public static final HBaseClassTestRule CLASS_RULE =
38-
HBaseClassTestRule.forClass(TestLockAndQueue.class);
39-
4035
@Test
4136
public void testHasLockAccess() {
4237
Map<Long, NoopProcedure<Void>> procMap = new HashMap<>();

0 commit comments

Comments
 (0)