1717 */
1818package 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
2424import java .io .IOException ;
2525import java .util .ArrayList ;
6565import org .apache .hadoop .hbase .util .Pair ;
6666import org .apache .hadoop .util .StringUtils ;
6767import org .apache .yetus .audience .InterfaceAudience ;
68- import org .junit .rules .TestName ;
6968import org .slf4j .Logger ;
7069import 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 ;
0 commit comments