Skip to content

Commit 35e6564

Browse files
committed
HBASE-30041 Upgrade hbase-server to use junit5 Part4 (apache#8000)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent 50fc7bb commit 35e6564

74 files changed

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,34 @@
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.HBaseTestingUtil;
2625
import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
2726
import org.apache.hadoop.hbase.TableName;
2827
import org.apache.hadoop.hbase.Waiter;
2928
import org.apache.hadoop.hbase.master.HMaster;
3029
import org.apache.hadoop.hbase.master.ServerManager;
31-
import org.apache.hadoop.hbase.testclassification.LargeTests;
30+
import org.apache.hadoop.hbase.testclassification.MediumTests;
3231
import org.apache.hadoop.hbase.testclassification.RSGroupTests;
3332
import org.apache.hadoop.hbase.util.compaction.TestMajorCompactorTTL;
34-
import org.junit.After;
35-
import org.junit.Before;
36-
import org.junit.ClassRule;
37-
import org.junit.Test;
38-
import org.junit.experimental.categories.Category;
33+
import org.junit.jupiter.api.AfterEach;
34+
import org.junit.jupiter.api.BeforeEach;
35+
import org.junit.jupiter.api.Tag;
36+
import org.junit.jupiter.api.Test;
37+
import org.junit.jupiter.api.TestInfo;
3938

4039
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
4140

42-
@Category({ RSGroupTests.class, LargeTests.class })
41+
@Tag(RSGroupTests.TAG)
42+
@Tag(MediumTests.TAG)
4343
public class TestRSGroupMajorCompactionTTL extends TestMajorCompactorTTL {
44-
@ClassRule
45-
public static final HBaseClassTestRule CLASS_RULE =
46-
HBaseClassTestRule.forClass(TestRSGroupMajorCompactionTTL.class);
4744

4845
private final static int NUM_SLAVES_BASE = 6;
4946

50-
@Before
47+
@BeforeEach
5148
@Override
5249
public void setUp() throws Exception {
5350
utility = new HBaseTestingUtil();
@@ -70,17 +67,17 @@ public boolean evaluate() {
7067
admin = utility.getAdmin();
7168
}
7269

73-
@After
70+
@AfterEach
7471
@Override
7572
public void tearDown() throws Exception {
7673
utility.shutdownMiniCluster();
7774
}
7875

7976
@Test
80-
public void testCompactingTables() throws Exception {
77+
public void testCompactingTables(TestInfo testInfo) throws Exception {
8178
List<TableName> tableNames = Lists.newArrayList();
8279
for (int i = 0; i < 10; i++) {
83-
tableNames.add(createTable(name.getMethodName() + "___" + i));
80+
tableNames.add(createTable(testInfo.getTestMethod().get().getName() + "___" + i));
8481
}
8582

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

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

Lines changed: 3 additions & 5 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;
@@ -66,7 +66,6 @@
6666
import org.apache.hadoop.hbase.mob.MobUtils;
6767
import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;
6868
import org.apache.hadoop.hbase.util.hbck.HFileCorruptionChecker;
69-
import org.junit.rules.TestName;
7069
import org.slf4j.Logger;
7170
import org.slf4j.LoggerFactory;
7271

@@ -544,8 +543,7 @@ protected void deleteMetaRegion(Configuration conf, boolean unassign, boolean hd
544543
}
545544
}
546545

547-
@org.junit.Rule
548-
public TestName name = new TestName();
546+
protected String testMethodName;
549547

550548
public static class MasterSyncCoprocessor implements MasterCoprocessor, MasterObserver {
551549
volatile CountDownLatch tableCreationLatch = 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.HBaseTestingUtil;
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 HBaseTestingUtil UTIL = new HBaseTestingUtil();
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)