Skip to content

Commit 420525e

Browse files
committed
HBASE-30039 Upgrade hbase-server to use junit5 Part3 (#7999)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent 2d5b5ff commit 420525e

55 files changed

Lines changed: 859 additions & 1238 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/quotas/SpaceQuotaHelperForTests.java

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

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

2424
import java.io.IOException;
2525
import java.util.ArrayList;
@@ -65,7 +65,6 @@
6565
import org.apache.hadoop.hbase.util.Pair;
6666
import org.apache.hadoop.util.StringUtils;
6767
import org.apache.yetus.audience.InterfaceAudience;
68-
import org.junit.rules.TestName;
6968
import org.slf4j.Logger;
7069
import org.slf4j.LoggerFactory;
7170

@@ -84,11 +83,11 @@ public class SpaceQuotaHelperForTests {
8483
public static final long ONE_GIGABYTE = ONE_MEGABYTE * ONE_KILOBYTE;
8584

8685
private final HBaseTestingUtility testUtil;
87-
private final TestName testName;
86+
private final String testName;
8887
private final AtomicLong counter;
8988
private static final int NUM_RETRIES = 10;
9089

91-
public SpaceQuotaHelperForTests(HBaseTestingUtility testUtil, TestName testName,
90+
public SpaceQuotaHelperForTests(HBaseTestingUtility testUtil, String testName,
9291
AtomicLong counter) {
9392
this.testUtil = Objects.requireNonNull(testUtil);
9493
this.testName = Objects.requireNonNull(testName);
@@ -232,12 +231,13 @@ void verifyViolation(SpaceViolationPolicy policyToViolate, TableName tn, Mutatio
232231
assertTrue(
233232
msg.contains("TableNotEnabledException") || msg.contains(policyToViolate.name()));
234233
} else {
235-
assertTrue("Expected exception message to contain the word '" + policyToViolate.name()
236-
+ "', but was " + msg, msg.contains(policyToViolate.name()));
234+
assertTrue(msg.contains(policyToViolate.name()),
235+
"Expected exception message to contain the word '" + policyToViolate.name()
236+
+ "', but was " + msg);
237237
}
238238
}
239-
assertTrue("Expected to see an exception writing data to a table exceeding its quota",
240-
sawError);
239+
assertTrue(sawError,
240+
"Expected to see an exception writing data to a table exceeding its quota");
241241
}
242242

243243
/**
@@ -277,7 +277,7 @@ void verifyNoViolation(TableName tn, Mutation m) throws Exception {
277277
scanner.close();
278278
}
279279
}
280-
assertTrue("Expected to succeed in writing data to a table not having quota ", sawSuccess);
280+
assertTrue(sawSuccess, "Expected to succeed in writing data to a table not having quota ");
281281
}
282282

283283
/**
@@ -290,8 +290,8 @@ void verifyTableUsageSnapshotForSpaceQuotaExist(TableName tn) throws Exception {
290290
ResultScanner rs = quotaTable.getScanner(s);
291291
sawUsageSnapshot = (rs.next() != null);
292292
}
293-
assertTrue("Expected to succeed in getting table usage snapshots for space quota",
294-
sawUsageSnapshot);
293+
assertTrue(sawUsageSnapshot,
294+
"Expected to succeed in getting table usage snapshots for space quota");
295295
}
296296

297297
/**
@@ -336,7 +336,7 @@ ClientServiceCallable<Void> generateFileToLoad(TableName tn, int numFiles, int n
336336
Connection conn = testUtil.getConnection();
337337
FileSystem fs = testUtil.getTestFileSystem();
338338
Configuration conf = testUtil.getConfiguration();
339-
Path baseDir = new Path(fs.getHomeDirectory(), testName.getMethodName() + "_files");
339+
Path baseDir = new Path(fs.getHomeDirectory(), testName + "_files");
340340
fs.mkdirs(baseDir);
341341
final List<Pair<byte[], String>> famPaths = new ArrayList<Pair<byte[], String>>();
342342
for (int i = 1; i <= numFiles; i++) {
@@ -365,44 +365,6 @@ public Void rpcCall() throws Exception {
365365
};
366366
}
367367

368-
/**
369-
* Bulk-loads a number of files with a number of rows to the given table.
370-
*/
371-
// ClientServiceCallable<Boolean> generateFileToLoad(
372-
// TableName tn, int numFiles, int numRowsPerFile) throws Exception {
373-
// Connection conn = testUtil.getConnection();
374-
// FileSystem fs = testUtil.getTestFileSystem();
375-
// Configuration conf = testUtil.getConfiguration();
376-
// Path baseDir = new Path(fs.getHomeDirectory(), testName.getMethodName() + "_files");
377-
// fs.mkdirs(baseDir);
378-
// final List<Pair<byte[], String>> famPaths = new ArrayList<>();
379-
// for (int i = 1; i <= numFiles; i++) {
380-
// Path hfile = new Path(baseDir, "file" + i);
381-
// TestHRegionServerBulkLoad.createHFile(
382-
// fs, hfile, Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("my"),
383-
// Bytes.toBytes("file"), numRowsPerFile);
384-
// famPaths.add(new Pair<>(Bytes.toBytes(SpaceQuotaHelperForTests.F1), hfile.toString()));
385-
// }
386-
//
387-
// // bulk load HFiles
388-
// Table table = conn.getTable(tn);
389-
// final String bulkToken = new SecureBulkLoadClient(conf, table).prepareBulkLoad(conn);
390-
// return new ClientServiceCallable<Boolean>(
391-
// conn, tn, Bytes.toBytes("row"), new RpcControllerFactory(conf).newController(),
392-
// HConstants.PRIORITY_UNSET) {
393-
// @Override
394-
// public Boolean rpcCall() throws Exception {
395-
// SecureBulkLoadClient secureClient = null;
396-
// byte[] regionName = getLocation().getRegion().getRegionName();
397-
// try (Table table = conn.getTable(getTableName())) {
398-
// secureClient = new SecureBulkLoadClient(conf, table);
399-
// return secureClient.secureBulkLoadHFiles(getStub(), famPaths, regionName,
400-
// true, null, bulkToken);
401-
// }
402-
// }
403-
// };
404-
// }
405-
406368
/**
407369
* Removes the space quota from the given namespace
408370
*/
@@ -466,14 +428,14 @@ QuotaSettings getTableSpaceQuota(Connection conn, TableName tn) throws IOExcepti
466428
/**
467429
* Waits 30seconds for the HBase quota table to exist.
468430
*/
469-
public void waitForQuotaTable(Connection conn) throws IOException {
431+
void waitForQuotaTable(Connection conn) throws IOException {
470432
waitForQuotaTable(conn, 30_000);
471433
}
472434

473435
/**
474436
* Waits {@code timeout} milliseconds for the HBase quota table to exist.
475437
*/
476-
public void waitForQuotaTable(Connection conn, long timeout) throws IOException {
438+
void waitForQuotaTable(Connection conn, long timeout) throws IOException {
477439
testUtil.waitFor(timeout, 1000, new Predicate<IOException>() {
478440
@Override
479441
public boolean evaluate() throws IOException {
@@ -598,7 +560,7 @@ TableName getNextTableName() {
598560
}
599561

600562
TableName getNextTableName(String namespace) {
601-
return TableName.valueOf(namespace, testName.getMethodName() + counter.getAndIncrement());
563+
return TableName.valueOf(namespace, testName + counter.getAndIncrement());
602564
}
603565

604566
TableName createTable() throws Exception {
@@ -647,8 +609,7 @@ TableName createTableWithRegions(Admin admin, String namespace, int numRegions,
647609

648610
TableName createTableInNamespace(NamespaceDescriptor nd) throws Exception {
649611
final Admin admin = testUtil.getAdmin();
650-
final TableName tn =
651-
TableName.valueOf(nd.getName(), testName.getMethodName() + counter.getAndIncrement());
612+
final TableName tn = TableName.valueOf(nd.getName(), testName + counter.getAndIncrement());
652613

653614
// Delete the old table
654615
if (admin.tableExists(tn)) {
@@ -658,7 +619,7 @@ TableName createTableInNamespace(NamespaceDescriptor nd) throws Exception {
658619

659620
// Create the table
660621
TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tn)
661-
.addColumnFamily(ColumnFamilyDescriptorBuilder.of(F1)).build();
622+
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(F1)).build();
662623

663624
admin.createTable(tableDesc);
664625
return tn;

hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestActivePolicyEnforcement.java

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

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

2626
import java.util.Collections;
2727
import java.util.HashMap;
2828
import java.util.Map;
2929
import java.util.Map.Entry;
30-
import org.apache.hadoop.hbase.HBaseClassTestRule;
3130
import org.apache.hadoop.hbase.TableName;
3231
import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus;
3332
import org.apache.hadoop.hbase.quotas.policies.DefaultViolationPolicyEnforcement;
3433
import org.apache.hadoop.hbase.quotas.policies.MissingSnapshotViolationPolicyEnforcement;
3534
import org.apache.hadoop.hbase.quotas.policies.NoWritesViolationPolicyEnforcement;
3635
import org.apache.hadoop.hbase.regionserver.RegionServerServices;
3736
import org.apache.hadoop.hbase.testclassification.SmallTests;
38-
import org.junit.Before;
39-
import org.junit.ClassRule;
40-
import org.junit.Test;
41-
import org.junit.experimental.categories.Category;
37+
import org.junit.jupiter.api.BeforeEach;
38+
import org.junit.jupiter.api.Tag;
39+
import org.junit.jupiter.api.Test;
4240

4341
/**
4442
* Test class for {@link ActivePolicyEnforcement}.
4543
*/
46-
@Category(SmallTests.class)
44+
@Tag(SmallTests.TAG)
4745
public class TestActivePolicyEnforcement {
4846

49-
@ClassRule
50-
public static final HBaseClassTestRule CLASS_RULE =
51-
HBaseClassTestRule.forClass(TestActivePolicyEnforcement.class);
52-
5347
private RegionServerServices rss;
5448

55-
@Before
49+
@BeforeEach
5650
public void setup() {
5751
rss = mock(RegionServerServices.class);
5852
}
@@ -73,8 +67,9 @@ public void testNoPolicyReturnsNoopEnforcement() {
7367
SpaceViolationPolicyEnforcement enforcement =
7468
ape.getPolicyEnforcement(TableName.valueOf("nonexistent"));
7569
assertNotNull(enforcement);
76-
assertTrue("Expected an instance of MissingSnapshotViolationPolicyEnforcement, but got "
77-
+ enforcement.getClass(), enforcement instanceof MissingSnapshotViolationPolicyEnforcement);
70+
assertTrue(enforcement instanceof MissingSnapshotViolationPolicyEnforcement,
71+
"Expected an instance of MissingSnapshotViolationPolicyEnforcement, but got "
72+
+ enforcement.getClass());
7873
}
7974

8075
@Test
@@ -84,7 +79,7 @@ public void testNoBulkLoadChecksOnNoSnapshot() {
8479
Collections.<TableName, SpaceQuotaSnapshot> emptyMap(), mock(RegionServerServices.class));
8580
SpaceViolationPolicyEnforcement enforcement =
8681
ape.getPolicyEnforcement(TableName.valueOf("nonexistent"));
87-
assertFalse("Should not check bulkloads", enforcement.shouldCheckBulkLoads());
82+
assertFalse(enforcement.shouldCheckBulkLoads(), "Should not check bulkloads");
8883
}
8984

9085
@Test
@@ -109,10 +104,10 @@ public void testNonViolatingQuotaCachesPolicyEnforcment() {
109104
final ActivePolicyEnforcement ape =
110105
new ActivePolicyEnforcement(Collections.emptyMap(), snapshots, rss);
111106
SpaceViolationPolicyEnforcement policyEnforcement = ape.getPolicyEnforcement(tableName);
112-
assertTrue("Found the wrong class: " + policyEnforcement.getClass(),
113-
policyEnforcement instanceof DefaultViolationPolicyEnforcement);
107+
assertTrue(policyEnforcement instanceof DefaultViolationPolicyEnforcement,
108+
"Found the wrong class: " + policyEnforcement.getClass());
114109
SpaceViolationPolicyEnforcement copy = ape.getPolicyEnforcement(tableName);
115-
assertTrue("Expected the instance to be cached", policyEnforcement == copy);
110+
assertTrue(policyEnforcement == copy, "Expected the instance to be cached");
116111
Entry<TableName, SpaceViolationPolicyEnforcement> entry =
117112
ape.getLocallyCachedPolicies().entrySet().iterator().next();
118113
assertTrue(policyEnforcement == entry.getValue());

hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestAtomicReadQuota.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.List;
2323
import java.util.UUID;
2424
import java.util.concurrent.TimeUnit;
25-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2625
import org.apache.hadoop.hbase.HBaseTestingUtility;
2726
import org.apache.hadoop.hbase.HConstants;
2827
import org.apache.hadoop.hbase.TableName;
@@ -40,34 +39,31 @@
4039
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
4140
import org.apache.hadoop.hbase.util.Bytes;
4241
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
43-
import org.junit.AfterClass;
44-
import org.junit.BeforeClass;
45-
import org.junit.ClassRule;
46-
import org.junit.Test;
47-
import org.junit.experimental.categories.Category;
42+
import org.junit.jupiter.api.AfterAll;
43+
import org.junit.jupiter.api.BeforeAll;
44+
import org.junit.jupiter.api.Tag;
45+
import org.junit.jupiter.api.Test;
4846
import org.slf4j.Logger;
4947
import org.slf4j.LoggerFactory;
5048

51-
@Category({ RegionServerTests.class, MediumTests.class })
49+
@Tag(RegionServerTests.TAG)
50+
@Tag(MediumTests.TAG)
5251
public class TestAtomicReadQuota {
53-
@ClassRule
54-
public static final HBaseClassTestRule CLASS_RULE =
55-
HBaseClassTestRule.forClass(TestAtomicReadQuota.class);
5652
private static final Logger LOG = LoggerFactory.getLogger(TestAtomicReadQuota.class);
5753
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
5854
private static final TableName TABLE_NAME = TableName.valueOf(UUID.randomUUID().toString());
5955
private static final byte[] FAMILY = Bytes.toBytes("cf");
6056
private static final byte[] QUALIFIER = Bytes.toBytes("q");
6157

62-
@AfterClass
58+
@AfterAll
6359
public static void tearDown() throws Exception {
6460
ThrottleQuotaTestUtil.clearQuotaCache(TEST_UTIL);
6561
EnvironmentEdgeManager.reset();
6662
TEST_UTIL.deleteTable(TABLE_NAME);
6763
TEST_UTIL.shutdownMiniCluster();
6864
}
6965

70-
@BeforeClass
66+
@BeforeAll
7167
public static void setUpBeforeClass() throws Exception {
7268
TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 1);
7369
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);

hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestBlockBytesScannedQuota.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.doScans;
2424
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerUserCacheRefresh;
2525
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.waitMinuteQuota;
26-
import static org.junit.Assert.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
2727

2828
import java.util.concurrent.Callable;
2929
import java.util.concurrent.TimeUnit;
30-
import org.apache.hadoop.hbase.HBaseClassTestRule;
3130
import org.apache.hadoop.hbase.HBaseTestingUtility;
3231
import org.apache.hadoop.hbase.HConstants;
3332
import org.apache.hadoop.hbase.TableName;
@@ -38,20 +37,17 @@
3837
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
3938
import org.apache.hadoop.hbase.util.Bytes;
4039
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
41-
import org.junit.After;
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;
40+
import org.junit.jupiter.api.AfterAll;
41+
import org.junit.jupiter.api.AfterEach;
42+
import org.junit.jupiter.api.BeforeAll;
43+
import org.junit.jupiter.api.Tag;
44+
import org.junit.jupiter.api.Test;
4745
import org.slf4j.Logger;
4846
import org.slf4j.LoggerFactory;
4947

50-
@Category({ RegionServerTests.class, LargeTests.class })
48+
@Tag(RegionServerTests.TAG)
49+
@Tag(LargeTests.TAG)
5150
public class TestBlockBytesScannedQuota {
52-
@ClassRule
53-
public static final HBaseClassTestRule CLASS_RULE =
54-
HBaseClassTestRule.forClass(TestBlockBytesScannedQuota.class);
5551

5652
private final static Logger LOG = LoggerFactory.getLogger(TestBlockBytesScannedQuota.class);
5753

@@ -63,7 +59,7 @@ public class TestBlockBytesScannedQuota {
6359
private static final TableName TABLE_NAME = TableName.valueOf("BlockBytesScannedQuotaTest");
6460
private static final long MAX_SCANNER_RESULT_SIZE = 100 * 1024 * 1024;
6561

66-
@BeforeClass
62+
@BeforeAll
6763
public static void setUpBeforeClass() throws Exception {
6864
// client should fail fast
6965
TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 10);
@@ -86,14 +82,14 @@ public static void setUpBeforeClass() throws Exception {
8682
TEST_UTIL.waitTableAvailable(TABLE_NAME);
8783
}
8884

89-
@AfterClass
85+
@AfterAll
9086
public static void tearDownAfterClass() throws Exception {
9187
EnvironmentEdgeManager.reset();
9288
TEST_UTIL.deleteTable(TABLE_NAME);
9389
TEST_UTIL.shutdownMiniCluster();
9490
}
9591

96-
@After
92+
@AfterEach
9793
public void tearDown() throws Exception {
9894
ThrottleQuotaTestUtil.clearQuotaCache(TEST_UTIL);
9995
}

0 commit comments

Comments
 (0)