Skip to content

Commit 70a10f2

Browse files
authored
HBASE-30041 Upgrade hbase-server to use junit5 Part4 (#8089)
Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit 04e2194) (cherry picked from commit 781c77c)
1 parent aae26c8 commit 70a10f2

69 files changed

Lines changed: 1011 additions & 1352 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-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupMajorCompactionTTL.java

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

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

2222
import java.util.List;
2323
import org.apache.hadoop.conf.Configuration;
24-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2524
import org.apache.hadoop.hbase.HBaseTestingUtility;
2625
import org.apache.hadoop.hbase.HConstants;
2726
import org.apache.hadoop.hbase.MiniHBaseCluster;
@@ -30,25 +29,24 @@
3029
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
3130
import org.apache.hadoop.hbase.master.HMaster;
3231
import org.apache.hadoop.hbase.master.ServerManager;
33-
import org.apache.hadoop.hbase.testclassification.LargeTests;
32+
import org.apache.hadoop.hbase.testclassification.MediumTests;
33+
import org.apache.hadoop.hbase.testclassification.MiscTests;
3434
import org.apache.hadoop.hbase.util.compaction.TestMajorCompactorTTL;
35-
import org.junit.After;
36-
import org.junit.Before;
37-
import org.junit.ClassRule;
38-
import org.junit.Test;
39-
import org.junit.experimental.categories.Category;
35+
import org.junit.jupiter.api.AfterEach;
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;
4040

4141
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
4242

43-
@Category(LargeTests.class)
43+
@Tag(MiscTests.TAG)
44+
@Tag(MediumTests.TAG)
4445
public class TestRSGroupMajorCompactionTTL extends TestMajorCompactorTTL {
45-
@ClassRule
46-
public static final HBaseClassTestRule CLASS_RULE =
47-
HBaseClassTestRule.forClass(TestRSGroupMajorCompactionTTL.class);
4846

4947
private final static int NUM_SLAVES_BASE = 6;
5048

51-
@Before
49+
@BeforeEach
5250
@Override
5351
public void setUp() throws Exception {
5452
utility = new HBaseTestingUtility();
@@ -72,17 +70,17 @@ public boolean evaluate() {
7270
admin = utility.getAdmin();
7371
}
7472

75-
@After
73+
@AfterEach
7674
@Override
7775
public void tearDown() throws Exception {
7876
utility.shutdownMiniCluster();
7977
}
8078

8179
@Test
82-
public void testCompactingTables() throws Exception {
80+
public void testCompactingTables(TestInfo testInfo) throws Exception {
8381
List<TableName> tableNames = Lists.newArrayList();
8482
for (int i = 0; i < 10; i++) {
85-
tableNames.add(createTable(name.getMethodName() + "___" + i));
83+
tableNames.add(createTable(testInfo.getTestMethod().get().getName() + "___" + i));
8684
}
8785

8886
// Delay a bit, so we can set the table TTL to 5 seconds

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,17 @@
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

22-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2322
import org.apache.hadoop.hbase.testclassification.MasterTests;
2423
import org.apache.hadoop.hbase.testclassification.SmallTests;
25-
import org.junit.ClassRule;
26-
import org.junit.Test;
27-
import org.junit.experimental.categories.Category;
24+
import org.junit.jupiter.api.Tag;
25+
import org.junit.jupiter.api.Test;
2826

29-
@Category({ MasterTests.class, SmallTests.class })
27+
@Tag(MasterTests.TAG)
28+
@Tag(SmallTests.TAG)
3029
public class TestDoubleArrayCost {
3130

32-
@ClassRule
33-
public static final HBaseClassTestRule CLASS_RULE =
34-
HBaseClassTestRule.forClass(TestDoubleArrayCost.class);
35-
3631
@Test
3732
public void testComputeCost() {
3833
DoubleArrayCost cost = new DoubleArrayCost();

hbase-server/src/test/java/org/apache/hadoop/hbase/util/BaseTestHBaseFsck.java

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

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

2323
import java.io.IOException;
2424
import java.util.ArrayList;
@@ -65,7 +65,6 @@
6565
import org.apache.hadoop.hbase.mob.MobUtils;
6666
import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;
6767
import org.apache.hadoop.hbase.util.hbck.HFileCorruptionChecker;
68-
import org.junit.rules.TestName;
6968
import org.slf4j.Logger;
7069
import org.slf4j.LoggerFactory;
7170

@@ -547,9 +546,6 @@ protected void deleteMetaRegion(Configuration conf, boolean unassign, boolean hd
547546
}
548547
}
549548

550-
@org.junit.Rule
551-
public TestName name = new TestName();
552-
553549
public static class MasterSyncCoprocessor implements MasterCoprocessor, MasterObserver {
554550
volatile CountDownLatch tableCreationLatch = null;
555551
volatile CountDownLatch tableDeletionLatch = null;

hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestBloomFilterChunk.java

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

2424
import java.io.ByteArrayOutputStream;
2525
import java.io.DataOutputStream;
2626
import java.nio.ByteBuffer;
27-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2827
import org.apache.hadoop.hbase.nio.MultiByteBuff;
2928
import org.apache.hadoop.hbase.testclassification.MiscTests;
3029
import org.apache.hadoop.hbase.testclassification.SmallTests;
31-
import org.junit.ClassRule;
32-
import org.junit.Test;
33-
import org.junit.experimental.categories.Category;
30+
import org.junit.jupiter.api.Tag;
31+
import org.junit.jupiter.api.Test;
3432

35-
@Category({ MiscTests.class, SmallTests.class })
33+
@Tag(MiscTests.TAG)
34+
@Tag(SmallTests.TAG)
3635
public class TestBloomFilterChunk {
3736

38-
@ClassRule
39-
public static final HBaseClassTestRule CLASS_RULE =
40-
HBaseClassTestRule.forClass(TestBloomFilterChunk.class);
41-
4237
@Test
4338
public void testBasicBloom() throws Exception {
4439
BloomFilterChunk bf1 = new BloomFilterChunk(1000, (float) 0.01, Hash.MURMUR_HASH, 0);

hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestBoundedPriorityBlockingQueue.java

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

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

2626
import java.util.Comparator;
2727
import java.util.PriorityQueue;
2828
import java.util.concurrent.CyclicBarrier;
2929
import java.util.concurrent.ExecutorService;
3030
import java.util.concurrent.Executors;
3131
import java.util.concurrent.TimeUnit;
32-
import org.apache.hadoop.hbase.HBaseClassTestRule;
3332
import org.apache.hadoop.hbase.testclassification.MiscTests;
3433
import org.apache.hadoop.hbase.testclassification.SmallTests;
35-
import org.junit.After;
36-
import org.junit.Before;
37-
import org.junit.ClassRule;
38-
import org.junit.Test;
39-
import org.junit.experimental.categories.Category;
34+
import org.junit.jupiter.api.AfterEach;
35+
import org.junit.jupiter.api.BeforeEach;
36+
import org.junit.jupiter.api.Tag;
37+
import org.junit.jupiter.api.Test;
4038

41-
@Category({ MiscTests.class, SmallTests.class })
39+
@Tag(MiscTests.TAG)
40+
@Tag(SmallTests.TAG)
4241
public class TestBoundedPriorityBlockingQueue {
4342

44-
@ClassRule
45-
public static final HBaseClassTestRule CLASS_RULE =
46-
HBaseClassTestRule.forClass(TestBoundedPriorityBlockingQueue.class);
47-
4843
private final static int CAPACITY = 16;
4944

5045
static class TestObject {
@@ -77,12 +72,12 @@ public int compare(TestObject a, TestObject b) {
7772

7873
private BoundedPriorityBlockingQueue<TestObject> queue;
7974

80-
@Before
75+
@BeforeEach
8176
public void setUp() throws Exception {
8277
this.queue = new BoundedPriorityBlockingQueue<>(CAPACITY, new TestObjectComparator());
8378
}
8479

85-
@After
80+
@AfterEach
8681
public void tearDown() throws Exception {
8782
}
8883

@@ -204,7 +199,7 @@ public void testPoll() {
204199
assertEquals(testList.poll(), queue.poll());
205200
}
206201

207-
assertNull(null, queue.poll());
202+
assertNull(queue.poll());
208203
}
209204

210205
@Test

hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestByteBuffUtils.java

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

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

2222
import java.nio.ByteBuffer;
23-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2423
import org.apache.hadoop.hbase.nio.ByteBuff;
2524
import org.apache.hadoop.hbase.nio.MultiByteBuff;
2625
import org.apache.hadoop.hbase.nio.SingleByteBuff;
2726
import org.apache.hadoop.hbase.testclassification.MiscTests;
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({ MiscTests.class, SmallTests.class })
31+
@Tag(MiscTests.TAG)
32+
@Tag(SmallTests.TAG)
3433
public class TestByteBuffUtils {
3534

36-
@ClassRule
37-
public static final HBaseClassTestRule CLASS_RULE =
38-
HBaseClassTestRule.forClass(TestByteBuffUtils.class);
39-
4035
@Test
4136
public void testCopyAndCompare() throws Exception {
4237
ByteBuffer bb1 = ByteBuffer.allocate(50);

hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCompressionTest.java

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

20-
import static org.junit.Assert.*;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.fail;
2125

2226
import java.io.BufferedOutputStream;
2327
import java.io.DataOutputStream;
2428
import java.io.IOException;
2529
import org.apache.hadoop.conf.Configuration;
26-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2730
import org.apache.hadoop.hbase.io.compress.Compression;
2831
import org.apache.hadoop.hbase.testclassification.MiscTests;
2932
import org.apache.hadoop.hbase.testclassification.SmallTests;
@@ -32,19 +35,15 @@
3235
import org.apache.hadoop.io.compress.CompressionOutputStream;
3336
import org.apache.hadoop.util.NativeCodeLoader;
3437
import org.apache.hadoop.util.ReflectionUtils;
35-
import org.junit.ClassRule;
36-
import org.junit.Test;
37-
import org.junit.experimental.categories.Category;
38+
import org.junit.jupiter.api.Tag;
39+
import org.junit.jupiter.api.Test;
3840
import org.slf4j.Logger;
3941
import org.slf4j.LoggerFactory;
4042

41-
@Category({ MiscTests.class, SmallTests.class })
43+
@Tag(MiscTests.TAG)
44+
@Tag(SmallTests.TAG)
4245
public class TestCompressionTest {
4346

44-
@ClassRule
45-
public static final HBaseClassTestRule CLASS_RULE =
46-
HBaseClassTestRule.forClass(TestCompressionTest.class);
47-
4847
private static final Logger LOG = LoggerFactory.getLogger(TestCompressionTest.class);
4948

5049
@Test

hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestConfigurationUtil.java

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

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNull;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNull;
2222

2323
import java.util.List;
2424
import java.util.Map;
2525
import org.apache.hadoop.conf.Configuration;
26-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2726
import org.apache.hadoop.hbase.testclassification.SmallTests;
28-
import org.junit.Before;
29-
import org.junit.ClassRule;
30-
import org.junit.Test;
31-
import org.junit.experimental.categories.Category;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Tag;
29+
import org.junit.jupiter.api.Test;
3230

3331
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;
3432
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
3533

36-
@Category({ SmallTests.class })
34+
@Tag(SmallTests.TAG)
3735
public class TestConfigurationUtil {
3836

39-
@ClassRule
40-
public static final HBaseClassTestRule CLASS_RULE =
41-
HBaseClassTestRule.forClass(TestConfigurationUtil.class);
42-
4337
private Configuration conf;
4438
private Map<String, String> keyValues;
4539
private String key;
4640

47-
@Before
41+
@BeforeEach
4842
public void setUp() throws Exception {
4943
this.conf = new Configuration();
5044
this.keyValues = ImmutableMap.of("k1", "v1", "k2", "v2");

hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestConnectionCache.java

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

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

2222
import java.io.IOException;
23-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2423
import org.apache.hadoop.hbase.HBaseTestingUtility;
2524
import org.apache.hadoop.hbase.security.UserProvider;
2625
import org.apache.hadoop.hbase.testclassification.MediumTests;
2726
import org.apache.hadoop.hbase.testclassification.MiscTests;
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;
27+
import org.junit.jupiter.api.AfterAll;
28+
import org.junit.jupiter.api.BeforeAll;
29+
import org.junit.jupiter.api.Tag;
30+
import org.junit.jupiter.api.Test;
3331

34-
@Category({ MiscTests.class, MediumTests.class })
32+
@Tag(MiscTests.TAG)
33+
@Tag(MediumTests.TAG)
3534
public class TestConnectionCache {
3635

37-
@ClassRule
38-
public static final HBaseClassTestRule CLASS_RULE =
39-
HBaseClassTestRule.forClass(TestConnectionCache.class);
40-
4136
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
4237

43-
@BeforeClass
38+
@BeforeAll
4439
public static void setUp() throws Exception {
4540
UTIL.startMiniCluster();
4641
}
4742

48-
@AfterClass
43+
@AfterAll
4944
public static void tearDown() throws IOException {
5045
UTIL.shutdownMiniCluster();
5146
}

0 commit comments

Comments
 (0)