Skip to content

Commit b09280e

Browse files
committed
HBASE-30191 Upgrade hbase-testing-util to use junit5
1 parent 5d5c0f1 commit b09280e

9 files changed

Lines changed: 73 additions & 96 deletions

hbase-testing-util/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@
133133
<artifactId>mockito-core</artifactId>
134134
<scope>compile</scope>
135135
</dependency>
136+
<dependency>
137+
<groupId>org.junit.jupiter</groupId>
138+
<artifactId>junit-jupiter-api</artifactId>
139+
<scope>test</scope>
140+
</dependency>
141+
<dependency>
142+
<groupId>org.junit.jupiter</groupId>
143+
<artifactId>junit-jupiter-engine</artifactId>
144+
<scope>test</scope>
145+
</dependency>
146+
<dependency>
147+
<groupId>org.junit.jupiter</groupId>
148+
<artifactId>junit-jupiter-params</artifactId>
149+
<scope>test</scope>
150+
</dependency>
136151
<dependency>
137152
<groupId>com.github.stephenc.findbugs</groupId>
138153
<artifactId>findbugs-annotations</artifactId>

hbase-testing-util/src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtilSpinup.java

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

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

2222
import java.util.List;
2323
import org.apache.hadoop.hbase.testclassification.MediumTests;
2424
import org.apache.hadoop.hbase.testclassification.MiscTests;
25-
import org.junit.AfterClass;
26-
import org.junit.BeforeClass;
27-
import org.junit.ClassRule;
28-
import org.junit.Test;
29-
import org.junit.experimental.categories.Category;
30-
import org.slf4j.Logger;
31-
import org.slf4j.LoggerFactory;
25+
import org.junit.jupiter.api.AfterAll;
26+
import org.junit.jupiter.api.BeforeAll;
27+
import org.junit.jupiter.api.Tag;
28+
import org.junit.jupiter.api.Test;
3229

3330
/**
3431
* Make sure we can spin up a HBTU without a hbase-site.xml
3532
*/
36-
@Category({ MiscTests.class, MediumTests.class })
33+
@Tag(MiscTests.TAG)
34+
@Tag(MediumTests.TAG)
3735
public class TestHBaseTestingUtilSpinup {
3836

39-
@ClassRule
40-
public static final HBaseClassTestRule CLASS_RULE =
41-
HBaseClassTestRule.forClass(TestHBaseTestingUtilSpinup.class);
42-
43-
private static final Logger LOG = LoggerFactory.getLogger(TestHBaseTestingUtilSpinup.class);
4437
private final static HBaseTestingUtility UTIL = new HBaseTestingUtility();
4538

46-
@BeforeClass
39+
@BeforeAll
4740
public static void beforeClass() throws Exception {
4841
UTIL.startMiniCluster();
4942
if (!UTIL.getHBaseCluster().waitForActiveAndReadyMaster(30000)) {
5043
throw new RuntimeException("Active master not ready");
5144
}
5245
}
5346

54-
@AfterClass
47+
@AfterAll
5548
public static void afterClass() throws Exception {
5649
UTIL.shutdownMiniCluster();
5750
}
5851

5952
@Test
6053
public void testGetMetaTableRows() throws Exception {
6154
List<byte[]> results = UTIL.getMetaTableRows();
62-
assertFalse("results should have some entries and is empty.", results.isEmpty());
55+
assertFalse(results.isEmpty(), "results should have some entries and is empty.");
6356
}
64-
6557
}

hbase-testing-util/src/test/java/org/apache/hadoop/hbase/testing/TestTestingHBaseCluster.java

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

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertThrows;
23-
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.assertThrows;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

2525
import java.util.Collection;
26-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2726
import org.apache.hadoop.hbase.ServerName;
2827
import org.apache.hadoop.hbase.Waiter;
2928
import org.apache.hadoop.hbase.client.Admin;
@@ -33,44 +32,40 @@
3332
import org.apache.hadoop.hbase.testclassification.MiscTests;
3433
import org.apache.hadoop.hbase.util.DNS;
3534
import org.apache.hadoop.hbase.util.DNS.ServerType;
36-
import org.junit.After;
37-
import org.junit.AfterClass;
38-
import org.junit.Before;
39-
import org.junit.BeforeClass;
40-
import org.junit.ClassRule;
41-
import org.junit.Test;
42-
import org.junit.experimental.categories.Category;
35+
import org.junit.jupiter.api.AfterAll;
36+
import org.junit.jupiter.api.AfterEach;
37+
import org.junit.jupiter.api.BeforeAll;
38+
import org.junit.jupiter.api.BeforeEach;
39+
import org.junit.jupiter.api.Tag;
40+
import org.junit.jupiter.api.Test;
4341

4442
import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
4543
import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
4644

47-
@Category({ MiscTests.class, LargeTests.class })
45+
@Tag(MiscTests.TAG)
46+
@Tag(LargeTests.TAG)
4847
public class TestTestingHBaseCluster {
4948

50-
@ClassRule
51-
public static final HBaseClassTestRule CLASS_RULE =
52-
HBaseClassTestRule.forClass(TestTestingHBaseCluster.class);
53-
5449
private static TestingHBaseCluster CLUSTER;
5550

5651
private Connection conn;
5752

5853
private Admin admin;
5954

60-
@BeforeClass
55+
@BeforeAll
6156
public static void setUpBeforeClass() throws Exception {
6257
CLUSTER = TestingHBaseCluster.create(TestingHBaseClusterOption.builder().numMasters(2)
6358
.numRegionServers(3).numDataNodes(3).build());
6459
}
6560

66-
@AfterClass
61+
@AfterAll
6762
public static void tearDownAfterClass() throws Exception {
6863
if (CLUSTER.isClusterRunning()) {
6964
CLUSTER.stop();
7065
}
7166
}
7267

73-
@Before
68+
@BeforeEach
7469
public void setUp() throws Exception {
7570
if (!CLUSTER.isClusterRunning()) {
7671
CLUSTER.start();
@@ -82,7 +77,7 @@ public void setUp() throws Exception {
8277
admin = conn.getAdmin();
8378
}
8479

85-
@After
80+
@AfterEach
8681
public void tearDown() throws Exception {
8782
Closeables.close(admin, true);
8883
Closeables.close(conn, true);

hbase-testing-util/src/test/java/org/apache/hadoop/hbase/testing/TestTestingHBaseClusterImplForCPs.java

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

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertSame;
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.assertSame;
2323

2424
import java.io.IOException;
2525
import java.util.List;
26-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2726
import org.apache.hadoop.hbase.ServerName;
2827
import org.apache.hadoop.hbase.TableName;
2928
import org.apache.hadoop.hbase.client.Admin;
@@ -39,21 +38,17 @@
3938
import org.apache.hadoop.hbase.testclassification.LargeTests;
4039
import org.apache.hadoop.hbase.testclassification.MiscTests;
4140
import org.apache.hadoop.hbase.util.Bytes;
42-
import org.junit.AfterClass;
43-
import org.junit.BeforeClass;
44-
import org.junit.ClassRule;
45-
import org.junit.Test;
46-
import org.junit.experimental.categories.Category;
41+
import org.junit.jupiter.api.AfterAll;
42+
import org.junit.jupiter.api.BeforeAll;
43+
import org.junit.jupiter.api.Tag;
44+
import org.junit.jupiter.api.Test;
4745

4846
import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
4947

50-
@Category({ MiscTests.class, LargeTests.class })
48+
@Tag(MiscTests.TAG)
49+
@Tag(LargeTests.TAG)
5150
public class TestTestingHBaseClusterImplForCPs {
5251

53-
@ClassRule
54-
public static final HBaseClassTestRule CLASS_RULE =
55-
HBaseClassTestRule.forClass(TestTestingHBaseClusterImplForCPs.class);
56-
5752
private static TestingHBaseCluster CLUSTER;
5853

5954
private static TableName NAME = TableName.valueOf("test");
@@ -64,7 +59,7 @@ public class TestTestingHBaseClusterImplForCPs {
6459

6560
private static Admin ADMIN;
6661

67-
@BeforeClass
62+
@BeforeAll
6863
public static void setUpBeforeClass() throws Exception {
6964
CLUSTER = TestingHBaseCluster.create(TestingHBaseClusterOption.builder().numMasters(2)
7065
.numRegionServers(3).numDataNodes(3).build());
@@ -76,7 +71,7 @@ public static void setUpBeforeClass() throws Exception {
7671
ADMIN.balancerSwitch(false, true);
7772
}
7873

79-
@AfterClass
74+
@AfterAll
8075
public static void tearDownAfterClass() throws Exception {
8176
Closeables.close(ADMIN, true);
8277
Closeables.close(CONN, true);

hbase-testing-util/src/test/java/org/apache/hadoop/hbase/testing/TestTestingHBaseClusterReplicationShareDfs.java

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

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

22-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2322
import org.apache.hadoop.hbase.HBaseTestingUtility;
2423
import org.apache.hadoop.hbase.HConstants;
2524
import org.apache.hadoop.hbase.testclassification.LargeTests;
2625
import org.apache.hadoop.hbase.testclassification.MiscTests;
27-
import org.junit.ClassRule;
28-
import org.junit.experimental.categories.Category;
26+
import org.junit.jupiter.api.Tag;
2927

30-
@Category({ MiscTests.class, LargeTests.class })
28+
@Tag(MiscTests.TAG)
29+
@Tag(LargeTests.TAG)
3130
public class TestTestingHBaseClusterReplicationShareDfs
3231
extends TestingHBaseClusterReplicationTestBase {
3332

34-
@ClassRule
35-
public static final HBaseClassTestRule CLASS_RULE =
36-
HBaseClassTestRule.forClass(TestTestingHBaseClusterReplicationShareDfs.class);
37-
3833
private HBaseTestingUtility util = new HBaseTestingUtility();
3934

4035
@Override

hbase-testing-util/src/test/java/org/apache/hadoop/hbase/testing/TestTestingHBaseClusterReplicationShareZk.java

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

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

22-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2322
import org.apache.hadoop.hbase.HBaseTestingUtility;
2423
import org.apache.hadoop.hbase.HConstants;
2524
import org.apache.hadoop.hbase.testclassification.LargeTests;
2625
import org.apache.hadoop.hbase.testclassification.MiscTests;
27-
import org.junit.ClassRule;
28-
import org.junit.experimental.categories.Category;
26+
import org.junit.jupiter.api.Tag;
2927

30-
@Category({ MiscTests.class, LargeTests.class })
28+
@Tag(MiscTests.TAG)
29+
@Tag(LargeTests.TAG)
3130
public class TestTestingHBaseClusterReplicationShareZk
3231
extends TestingHBaseClusterReplicationTestBase {
3332

34-
@ClassRule
35-
public static final HBaseClassTestRule CLASS_RULE =
36-
HBaseClassTestRule.forClass(TestTestingHBaseClusterReplicationShareZk.class);
37-
3833
private HBaseTestingUtility util = new HBaseTestingUtility();
3934

4035
@Override

hbase-testing-util/src/test/java/org/apache/hadoop/hbase/testing/TestTestingHBaseClusterReplicationShareZkDfs.java

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

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

22-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2322
import org.apache.hadoop.hbase.HBaseTestingUtility;
2423
import org.apache.hadoop.hbase.HConstants;
2524
import org.apache.hadoop.hbase.testclassification.LargeTests;
2625
import org.apache.hadoop.hbase.testclassification.MiscTests;
27-
import org.junit.ClassRule;
28-
import org.junit.experimental.categories.Category;
26+
import org.junit.jupiter.api.Tag;
2927

30-
@Category({ MiscTests.class, LargeTests.class })
28+
@Tag(MiscTests.TAG)
29+
@Tag(LargeTests.TAG)
3130
public class TestTestingHBaseClusterReplicationShareZkDfs
3231
extends TestingHBaseClusterReplicationTestBase {
3332

34-
@ClassRule
35-
public static final HBaseClassTestRule CLASS_RULE =
36-
HBaseClassTestRule.forClass(TestTestingHBaseClusterReplicationShareZkDfs.class);
37-
3833
private HBaseTestingUtility util = new HBaseTestingUtility();
3934

4035
@Override

hbase-testing-util/src/test/java/org/apache/hadoop/hbase/testing/TestTestingHBaseClusterReplicationTwoClusters.java

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

20-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2120
import org.apache.hadoop.hbase.testclassification.LargeTests;
2221
import org.apache.hadoop.hbase.testclassification.MiscTests;
23-
import org.junit.ClassRule;
24-
import org.junit.experimental.categories.Category;
22+
import org.junit.jupiter.api.Tag;
2523

26-
@Category({ MiscTests.class, LargeTests.class })
24+
@Tag(MiscTests.TAG)
25+
@Tag(LargeTests.TAG)
2726
public class TestTestingHBaseClusterReplicationTwoClusters
2827
extends TestingHBaseClusterReplicationTestBase {
2928

30-
@ClassRule
31-
public static final HBaseClassTestRule CLASS_RULE =
32-
HBaseClassTestRule.forClass(TestTestingHBaseClusterReplicationTwoClusters.class);
33-
3429
@Override
3530
protected void startClusters() throws Exception {
3631
sourceCluster = TestingHBaseCluster.create(TestingHBaseClusterOption.builder().build());

hbase-testing-util/src/test/java/org/apache/hadoop/hbase/testing/TestingHBaseClusterReplicationTestBase.java

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

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

2222
import java.io.IOException;
2323
import org.apache.hadoop.hbase.HConstants;
@@ -35,9 +35,9 @@
3535
import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
3636
import org.apache.hadoop.hbase.util.Bytes;
3737
import org.apache.hadoop.hbase.zookeeper.ZKConfig;
38-
import org.junit.After;
39-
import org.junit.Before;
40-
import org.junit.Test;
38+
import org.junit.jupiter.api.AfterEach;
39+
import org.junit.jupiter.api.BeforeEach;
40+
import org.junit.jupiter.api.Test;
4141

4242
import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
4343

@@ -64,7 +64,7 @@ private String getPeerClusterKey() {
6464
return ZKConfig.getZooKeeperClusterKey(peerCluster.getConf());
6565
}
6666

67-
@Before
67+
@BeforeEach
6868
public void setUp() throws Exception {
6969
startClusters();
7070
sourceConn = ConnectionFactory.createConnection(sourceCluster.getConf());
@@ -82,7 +82,7 @@ public void setUp() throws Exception {
8282
}
8383
}
8484

85-
@After
85+
@AfterEach
8686
public void tearDown() throws Exception {
8787
Closeables.close(sourceConn, true);
8888
Closeables.close(peerConn, true);

0 commit comments

Comments
 (0)