Skip to content

Commit aae26c8

Browse files
authored
HBASE-30039 Upgrade hbase-server to use junit5 Part3 (#8090)
Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit 39f5903) (cherry picked from commit b369b38)
1 parent 1d0ddcf commit aae26c8

46 files changed

Lines changed: 733 additions & 1078 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: 16 additions & 55 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;
@@ -64,7 +64,6 @@
6464
import org.apache.hadoop.hbase.util.Pair;
6565
import org.apache.hadoop.util.StringUtils;
6666
import org.apache.yetus.audience.InterfaceAudience;
67-
import org.junit.rules.TestName;
6867
import org.slf4j.Logger;
6968
import org.slf4j.LoggerFactory;
7069

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

8584
private final HBaseTestingUtility testUtil;
86-
private final TestName testName;
85+
private final String testName;
8786
private final AtomicLong counter;
8887
private static final int NUM_RETRIES = 10;
8988

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

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

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

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

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

598560
TableName getNextTableName(String namespace) {
599-
return TableName.valueOf(namespace, testName.getMethodName() + counter.getAndIncrement());
561+
return TableName.valueOf(namespace, testName + counter.getAndIncrement());
600562
}
601563

602564
TableName createTable() throws Exception {
@@ -645,8 +607,7 @@ TableName createTableWithRegions(Admin admin, String namespace, int numRegions,
645607

646608
TableName createTableInNamespace(NamespaceDescriptor nd) throws Exception {
647609
final Admin admin = testUtil.getAdmin();
648-
final TableName tn =
649-
TableName.valueOf(nd.getName(), testName.getMethodName() + counter.getAndIncrement());
610+
final TableName tn = TableName.valueOf(nd.getName(), testName + counter.getAndIncrement());
650611

651612
// Delete the old table
652613
if (admin.tableExists(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/TestClusterScopeQuotaThrottle.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerNamespaceCacheRefresh;
2323
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerTableCacheRefresh;
2424
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerUserCacheRefresh;
25-
import static org.junit.Assert.assertEquals;
26-
import static org.junit.Assert.assertTrue;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
2727

2828
import java.util.concurrent.TimeUnit;
29-
import org.apache.hadoop.hbase.HBaseClassTestRule;
3029
import org.apache.hadoop.hbase.HBaseTestingUtility;
3130
import org.apache.hadoop.hbase.NamespaceDescriptor;
3231
import org.apache.hadoop.hbase.TableName;
@@ -38,20 +37,16 @@
3837
import org.apache.hadoop.hbase.util.Bytes;
3938
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
4039
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
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;
47-
48-
@Category({ RegionServerTests.class, LargeTests.class })
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;
45+
46+
@Tag(RegionServerTests.TAG)
47+
@Tag(LargeTests.TAG)
4948
public class TestClusterScopeQuotaThrottle {
5049

51-
@ClassRule
52-
public static final HBaseClassTestRule CLASS_RULE =
53-
HBaseClassTestRule.forClass(TestClusterScopeQuotaThrottle.class);
54-
5550
private final static int REFRESH_TIME = 30 * 60000;
5651
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
5752

@@ -67,7 +62,7 @@ public class TestClusterScopeQuotaThrottle {
6762
private final static TableName TABLE_NAME = TableName.valueOf(NAMESPACE, "TestTable");
6863
private static Table table;
6964

70-
@BeforeClass
65+
@BeforeAll
7166
public static void setUpBeforeClass() throws Exception {
7267
TEST_UTIL.getConfiguration().setBoolean(QuotaUtil.QUOTA_CONF_KEY, true);
7368
TEST_UTIL.getConfiguration().setInt(QuotaCache.REFRESH_CONF_KEY, REFRESH_TIME);
@@ -93,7 +88,7 @@ public static void setUpBeforeClass() throws Exception {
9388
.build();
9489
}
9590

96-
@AfterClass
91+
@AfterAll
9792
public static void tearDownAfterClass() throws Exception {
9893
EnvironmentEdgeManager.reset();
9994
for (int i = 0; i < tables.length; ++i) {
@@ -107,7 +102,7 @@ public static void tearDownAfterClass() throws Exception {
107102
TEST_UTIL.shutdownMiniCluster();
108103
}
109104

110-
@After
105+
@AfterEach
111106
public void tearDown() throws Exception {
112107
ThrottleQuotaTestUtil.clearQuotaCache(TEST_UTIL);
113108
}

0 commit comments

Comments
 (0)