Skip to content

Commit e0feedf

Browse files
committed
HBASE-30057 Upgrade hbase-server to use junit5 Part5
1 parent 03f9f17 commit e0feedf

44 files changed

Lines changed: 729 additions & 933 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/TestCacheEviction.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import static org.apache.hadoop.hbase.io.hfile.CacheConfig.EVICT_BLOCKS_ON_CLOSE_KEY;
2424
import static org.apache.hadoop.hbase.io.hfile.CacheConfig.EVICT_BLOCKS_ON_SPLIT_KEY;
2525
import static org.apache.hadoop.hbase.io.hfile.CacheConfig.PREFETCH_BLOCKS_ON_OPEN_KEY;
26-
import static org.junit.Assert.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
2727

2828
import java.io.IOException;
2929
import java.util.ArrayList;
@@ -42,26 +42,18 @@
4242
import org.apache.hadoop.hbase.testclassification.MiscTests;
4343
import org.apache.hadoop.hbase.util.Bytes;
4444
import org.apache.hadoop.hbase.util.Pair;
45-
import org.junit.Before;
46-
import org.junit.BeforeClass;
47-
import org.junit.ClassRule;
48-
import org.junit.Test;
49-
import org.junit.experimental.categories.Category;
50-
import org.slf4j.Logger;
51-
import org.slf4j.LoggerFactory;
52-
53-
@Category({ MiscTests.class, LargeTests.class })
54-
public class TestCacheEviction {
55-
56-
@ClassRule
57-
public static final HBaseClassTestRule CLASS_RULE =
58-
HBaseClassTestRule.forClass(TestCacheEviction.class);
45+
import org.junit.jupiter.api.BeforeAll;
46+
import org.junit.jupiter.api.BeforeEach;
47+
import org.junit.jupiter.api.Tag;
48+
import org.junit.jupiter.api.Test;
5949

60-
private static final Logger LOG = LoggerFactory.getLogger(TestCacheEviction.class);
50+
@Tag(MiscTests.TAG)
51+
@Tag(LargeTests.TAG)
52+
public class TestCacheEviction {
6153

6254
private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
6355

64-
@BeforeClass
56+
@BeforeAll
6557
public static void setUp() throws Exception {
6658
UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 1000);
6759
UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
@@ -71,7 +63,7 @@ public static void setUp() throws Exception {
7163
UTIL.getConfiguration().set(StoreFileTrackerFactory.TRACKER_IMPL, "FILE");
7264
}
7365

74-
@Before
66+
@BeforeEach
7567
public void testSetup() {
7668
UTIL.getConfiguration().set(BUCKET_CACHE_IOENGINE_KEY,
7769
"file:" + UTIL.getDataTestDir() + "/bucketcache");

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

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

Lines changed: 36 additions & 37 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.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
2024
import java.io.IOException;
2125
import java.util.EnumSet;
2226
import java.util.List;
@@ -34,33 +38,29 @@
3438
import org.apache.hadoop.hbase.master.HMaster;
3539
import org.apache.hadoop.hbase.regionserver.HRegionServer;
3640
import org.apache.hadoop.hbase.testclassification.MediumTests;
41+
import org.apache.hadoop.hbase.testclassification.MiscTests;
3742
import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread;
3843
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
3944
import org.junit.AfterClass;
40-
import org.junit.Assert;
41-
import org.junit.BeforeClass;
42-
import org.junit.ClassRule;
43-
import org.junit.Test;
44-
import org.junit.experimental.categories.Category;
45+
import org.junit.jupiter.api.BeforeAll;
46+
import org.junit.jupiter.api.Tag;
47+
import org.junit.jupiter.api.Test;
4548

4649
/**
4750
* Test the ClusterStatus.
4851
*/
49-
@Category(MediumTests.class)
52+
@Tag(MiscTests.TAG)
53+
@Tag(MediumTests.TAG)
5054
public class TestClientClusterStatus {
5155

52-
@ClassRule
53-
public static final HBaseClassTestRule CLASS_RULE =
54-
HBaseClassTestRule.forClass(TestClientClusterStatus.class);
55-
5656
private static HBaseTestingUtil UTIL;
5757
private static Admin ADMIN;
5858
private final static int SLAVES = 5;
5959
private final static int MASTERS = 3;
6060
private static SingleProcessHBaseCluster CLUSTER;
6161
private static HRegionServer DEAD;
6262

63-
@BeforeClass
63+
@BeforeAll
6464
public static void setUpBeforeClass() throws Exception {
6565
Configuration conf = HBaseConfiguration.create();
6666
conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MyObserver.class.getName());
@@ -87,8 +87,7 @@ public void testNone() throws Exception {
8787
ClusterMetrics status1 = ADMIN.getClusterMetrics(EnumSet.noneOf(Option.class));
8888
// Do a rough compare. More specific compares can fail because all regions not deployed yet
8989
// or more requests than expected.
90-
Assert.assertEquals(status0.getLiveServerMetrics().size(),
91-
status1.getLiveServerMetrics().size());
90+
assertEquals(status0.getLiveServerMetrics().size(), status1.getLiveServerMetrics().size());
9291
}
9392

9493
@Test
@@ -108,29 +107,29 @@ public void testLiveAndDeadServersStatus() throws Exception {
108107
@Override
109108
public boolean evaluate() throws Exception {
110109
ClusterMetrics status = ADMIN.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
111-
Assert.assertNotNull(status);
110+
assertNotNull(status);
112111
return status.getRegionCount() > 0;
113112
}
114113
});
115114
// Retrieve live servers and dead servers info.
116115
EnumSet<Option> options =
117116
EnumSet.of(Option.LIVE_SERVERS, Option.DEAD_SERVERS, Option.SERVERS_NAME);
118117
ClusterMetrics status = ADMIN.getClusterMetrics(options);
119-
Assert.assertNotNull(status);
120-
Assert.assertNotNull(status.getLiveServerMetrics().keySet());
118+
assertNotNull(status);
119+
assertNotNull(status.getLiveServerMetrics().keySet());
121120
// exclude a dead region server
122-
Assert.assertEquals(SLAVES - 1, numRs);
121+
assertEquals(SLAVES - 1, numRs);
123122
// live servers = nums of regionservers
124123
// By default, HMaster don't carry any regions so it won't report its load.
125124
// Hence, it won't be in the server list.
126-
Assert.assertEquals(status.getLiveServerMetrics().keySet().size(), numRs);
127-
Assert.assertTrue(status.getRegionCount() > 0);
128-
Assert.assertNotNull(status.getDeadServerNames());
129-
Assert.assertEquals(1, status.getDeadServerNames().size());
125+
assertEquals(status.getLiveServerMetrics().keySet().size(), numRs);
126+
assertTrue(status.getRegionCount() > 0);
127+
assertNotNull(status.getDeadServerNames());
128+
assertEquals(1, status.getDeadServerNames().size());
130129
ServerName deadServerName = status.getDeadServerNames().iterator().next();
131-
Assert.assertEquals(DEAD.getServerName(), deadServerName);
132-
Assert.assertNotNull(status.getServersName());
133-
Assert.assertEquals(numRs, status.getServersName().size());
130+
assertEquals(DEAD.getServerName(), deadServerName);
131+
assertNotNull(status.getServersName());
132+
assertEquals(numRs, status.getServersName().size());
134133
}
135134

136135
@Test
@@ -149,26 +148,26 @@ public void testMasterAndBackupMastersStatus() throws Exception {
149148
activeName = active.getServerName();
150149
}
151150
}
152-
Assert.assertNotNull(active);
153-
Assert.assertEquals(1, numActive);
154-
Assert.assertEquals(MASTERS, masterThreads.size());
151+
assertNotNull(active);
152+
assertEquals(1, numActive);
153+
assertEquals(MASTERS, masterThreads.size());
155154
// Retrieve master and backup masters infos only.
156155
EnumSet<Option> options = EnumSet.of(Option.MASTER, Option.BACKUP_MASTERS);
157156
ClusterMetrics status = ADMIN.getClusterMetrics(options);
158-
Assert.assertTrue(status.getMasterName().equals(activeName));
159-
Assert.assertEquals(MASTERS - 1, status.getBackupMasterNames().size());
157+
assertTrue(status.getMasterName().equals(activeName));
158+
assertEquals(MASTERS - 1, status.getBackupMasterNames().size());
160159
}
161160

162161
@Test
163162
public void testOtherStatusInfos() throws Exception {
164163
EnumSet<Option> options = EnumSet.of(Option.MASTER_COPROCESSORS, Option.HBASE_VERSION,
165164
Option.CLUSTER_ID, Option.BALANCER_ON);
166165
ClusterMetrics status = ADMIN.getClusterMetrics(options);
167-
Assert.assertTrue(status.getMasterCoprocessorNames().size() == 1);
168-
Assert.assertNotNull(status.getHBaseVersion());
169-
Assert.assertNotNull(status.getClusterId());
170-
Assert.assertTrue(status.getAverageLoad() == 0.0);
171-
Assert.assertNotNull(status.getBalancerOn());
166+
assertTrue(status.getMasterCoprocessorNames().size() == 1);
167+
assertNotNull(status.getHBaseVersion());
168+
assertNotNull(status.getClusterId());
169+
assertTrue(status.getAverageLoad() == 0.0);
170+
assertNotNull(status.getBalancerOn());
172171
}
173172

174173
@AfterClass
@@ -181,10 +180,10 @@ public static void tearDownAfterClass() throws Exception {
181180
public void testObserver() throws IOException {
182181
int preCount = MyObserver.PRE_COUNT.get();
183182
int postCount = MyObserver.POST_COUNT.get();
184-
Assert.assertTrue(ADMIN.getClusterMetrics().getMasterCoprocessorNames().stream()
183+
assertTrue(ADMIN.getClusterMetrics().getMasterCoprocessorNames().stream()
185184
.anyMatch(s -> s.equals(MyObserver.class.getSimpleName())));
186-
Assert.assertEquals(preCount + 1, MyObserver.PRE_COUNT.get());
187-
Assert.assertEquals(postCount + 1, MyObserver.POST_COUNT.get());
185+
assertEquals(preCount + 1, MyObserver.PRE_COUNT.get());
186+
assertEquals(postCount + 1, MyObserver.POST_COUNT.get());
188187
}
189188

190189
public static class MyObserver implements MasterCoprocessor, MasterObserver {

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import static org.hamcrest.CoreMatchers.instanceOf;
2121
import static org.hamcrest.MatcherAssert.assertThat;
22-
import static org.junit.Assert.fail;
22+
import static org.junit.jupiter.api.Assertions.fail;
2323

2424
import java.io.IOException;
2525
import java.net.SocketTimeoutException;
@@ -43,12 +43,11 @@
4343
import org.apache.hadoop.hbase.testclassification.ClientTests;
4444
import org.apache.hadoop.hbase.testclassification.MediumTests;
4545
import org.apache.hadoop.hbase.util.Bytes;
46-
import org.junit.AfterClass;
47-
import org.junit.Before;
48-
import org.junit.BeforeClass;
49-
import org.junit.ClassRule;
50-
import org.junit.Test;
51-
import org.junit.experimental.categories.Category;
46+
import org.junit.jupiter.api.AfterAll;
47+
import org.junit.jupiter.api.BeforeAll;
48+
import org.junit.jupiter.api.BeforeEach;
49+
import org.junit.jupiter.api.Tag;
50+
import org.junit.jupiter.api.Test;
5251
import org.slf4j.Logger;
5352
import org.slf4j.LoggerFactory;
5453

@@ -71,15 +70,12 @@
7170
* specified for scan related operations such as openScanner(), next(). If that times out
7271
* {@link RetriesExhaustedException} will be thrown.
7372
*/
74-
@Category({ ClientTests.class, MediumTests.class })
73+
@Tag(ClientTests.TAG)
74+
@Tag(MediumTests.TAG)
7575
public class TestClientOperationTimeout {
7676

7777
private static final Logger LOG = LoggerFactory.getLogger(TestClientOperationTimeout.class);
7878

79-
@ClassRule
80-
public static final HBaseClassTestRule CLASS_RULE =
81-
HBaseClassTestRule.forClass(TestClientOperationTimeout.class);
82-
8379
private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
8480

8581
// Activate the delays after table creation to test get/scan/put
@@ -97,7 +93,7 @@ public class TestClientOperationTimeout {
9793
private static Connection CONN;
9894
private static Table TABLE;
9995

100-
@BeforeClass
96+
@BeforeAll
10197
public static void setUp() throws Exception {
10298
// Set RegionServer class and use default values for other options.
10399
StartTestingClusterOption option =
@@ -115,14 +111,14 @@ public static void setUp() throws Exception {
115111
TABLE = CONN.getTable(TABLE_NAME);
116112
}
117113

118-
@AfterClass
114+
@AfterAll
119115
public static void tearDown() throws Exception {
120116
Closeables.close(TABLE, true);
121117
Closeables.close(CONN, true);
122118
UTIL.shutdownMiniCluster();
123119
}
124120

125-
@Before
121+
@BeforeEach
126122
public void setUpBeforeTest() throws Exception {
127123
DELAY_GET = 0;
128124
DELAY_SCAN = 0;

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

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

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

2222
import org.apache.hadoop.hbase.testclassification.MediumTests;
2323
import org.apache.hadoop.hbase.testclassification.MiscTests;
2424
import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread;
2525
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
26-
import org.junit.After;
27-
import org.junit.Before;
28-
import org.junit.ClassRule;
29-
import org.junit.Test;
30-
import org.junit.experimental.categories.Category;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Tag;
29+
import org.junit.jupiter.api.Test;
3130

3231
/**
3332
* Tests the boot order indifference between regionserver and master
3433
*/
35-
@Category({ MiscTests.class, MediumTests.class })
34+
@Tag(MiscTests.TAG)
35+
@Tag(MediumTests.TAG)
3636
public class TestClusterBootOrder {
3737

38-
@ClassRule
39-
public static final HBaseClassTestRule CLASS_RULE =
40-
HBaseClassTestRule.forClass(TestClusterBootOrder.class);
41-
4238
private static final long SLEEP_INTERVAL = 1000;
4339
private static final long SLEEP_TIME = 4000;
4440

@@ -47,7 +43,7 @@ public class TestClusterBootOrder {
4743
private RegionServerThread rs;
4844
private MasterThread master;
4945

50-
@Before
46+
@BeforeEach
5147
public void setUp() throws Exception {
5248
testUtil = new HBaseTestingUtil();
5349
testUtil.startMiniDFSCluster(1);
@@ -56,7 +52,7 @@ public void setUp() throws Exception {
5652
cluster = new LocalHBaseCluster(testUtil.getConfiguration(), 0, 0);
5753
}
5854

59-
@After
55+
@AfterEach
6056
public void tearDown() throws Exception {
6157
cluster.shutdown();
6258
cluster.join();

0 commit comments

Comments
 (0)