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 ;
2626import java .util .Collection ;
27- import java .util .Collections ;
2827import java .util .List ;
28+ import java .util .Map ;
2929import java .util .Map .Entry ;
3030import java .util .Objects ;
3131import java .util .Set ;
32+ import java .util .TreeMap ;
3233import java .util .concurrent .atomic .AtomicLong ;
34+ import java .util .function .Supplier ;
3335import org .apache .hadoop .conf .Configuration ;
3436import org .apache .hadoop .fs .FileSystem ;
3537import org .apache .hadoop .fs .Path ;
3638import org .apache .hadoop .hbase .HBaseTestingUtility ;
37- import org .apache .hadoop .hbase .HConstants ;
38- import org .apache .hadoop .hbase .MiniHBaseCluster ;
3939import org .apache .hadoop .hbase .NamespaceDescriptor ;
40+ import org .apache .hadoop .hbase .MiniHBaseCluster ;
4041import org .apache .hadoop .hbase .TableName ;
4142import org .apache .hadoop .hbase .TableNotEnabledException ;
4243import org .apache .hadoop .hbase .Waiter .Predicate ;
4344import org .apache .hadoop .hbase .client .Admin ;
4445import org .apache .hadoop .hbase .client .Append ;
45- import org .apache .hadoop .hbase .client .ClientServiceCallable ;
4646import org .apache .hadoop .hbase .client .ColumnFamilyDescriptorBuilder ;
4747import org .apache .hadoop .hbase .client .Connection ;
4848import org .apache .hadoop .hbase .client .Delete ;
5252import org .apache .hadoop .hbase .client .Result ;
5353import org .apache .hadoop .hbase .client .ResultScanner ;
5454import org .apache .hadoop .hbase .client .Scan ;
55- import org .apache .hadoop .hbase .client .SecureBulkLoadClient ;
5655import org .apache .hadoop .hbase .client .Table ;
5756import org .apache .hadoop .hbase .client .TableDescriptor ;
5857import org .apache .hadoop .hbase .client .TableDescriptorBuilder ;
59- import org .apache .hadoop .hbase .ipc .RpcControllerFactory ;
6058import org .apache .hadoop .hbase .regionserver .HRegion ;
6159import org .apache .hadoop .hbase .regionserver .HStore ;
6260import org .apache .hadoop .hbase .regionserver .HStoreFile ;
6361import org .apache .hadoop .hbase .regionserver .TestHRegionServerBulkLoad ;
6462import org .apache .hadoop .hbase .util .Bytes ;
65- import org .apache .hadoop .hbase .util .Pair ;
6663import org .apache .hadoop .util .StringUtils ;
6764import org .apache .yetus .audience .InterfaceAudience ;
68- import org .junit .rules .TestName ;
6965import org .slf4j .Logger ;
7066import org .slf4j .LoggerFactory ;
7167
@@ -84,11 +80,11 @@ public class SpaceQuotaHelperForTests {
8480 public static final long ONE_GIGABYTE = ONE_MEGABYTE * ONE_KILOBYTE ;
8581
8682 private final HBaseTestingUtility testUtil ;
87- private final TestName testName ;
83+ private final Supplier < String > testName ;
8884 private final AtomicLong counter ;
8985 private static final int NUM_RETRIES = 10 ;
9086
91- public SpaceQuotaHelperForTests (HBaseTestingUtility testUtil , TestName testName ,
87+ public SpaceQuotaHelperForTests (HBaseTestingUtility testUtil , Supplier < String > testName ,
9288 AtomicLong counter ) {
9389 this .testUtil = Objects .requireNonNull (testUtil );
9490 this .testName = Objects .requireNonNull (testName );
@@ -232,12 +228,13 @@ void verifyViolation(SpaceViolationPolicy policyToViolate, TableName tn, Mutatio
232228 assertTrue (
233229 msg .contains ("TableNotEnabledException" ) || msg .contains (policyToViolate .name ()));
234230 } else {
235- assertTrue ("Expected exception message to contain the word '" + policyToViolate .name ()
236- + "', but was " + msg , msg .contains (policyToViolate .name ()));
231+ assertTrue (msg .contains (policyToViolate .name ()),
232+ "Expected exception message to contain the word '" + policyToViolate .name ()
233+ + "', but was " + msg );
237234 }
238235 }
239- assertTrue ("Expected to see an exception writing data to a table exceeding its quota" ,
240- sawError );
236+ assertTrue (sawError ,
237+ "Expected to see an exception writing data to a table exceeding its quota" );
241238 }
242239
243240 /**
@@ -277,7 +274,7 @@ void verifyNoViolation(TableName tn, Mutation m) throws Exception {
277274 scanner .close ();
278275 }
279276 }
280- assertTrue ("Expected to succeed in writing data to a table not having quota " , sawSuccess );
277+ assertTrue (sawSuccess , "Expected to succeed in writing data to a table not having quota " );
281278 }
282279
283280 /**
@@ -290,8 +287,8 @@ void verifyTableUsageSnapshotForSpaceQuotaExist(TableName tn) throws Exception {
290287 ResultScanner rs = quotaTable .getScanner (s );
291288 sawUsageSnapshot = (rs .next () != null );
292289 }
293- assertTrue ("Expected to succeed in getting table usage snapshots for space quota" ,
294- sawUsageSnapshot );
290+ assertTrue (sawUsageSnapshot ,
291+ "Expected to succeed in getting table usage snapshots for space quota" );
295292 }
296293
297294 /**
@@ -324,85 +321,6 @@ void removeQuotaFromtable(final TableName tn) throws Exception {
324321 LOG .debug ("Space quota settings removed from the table " , tn );
325322 }
326323
327- /**
328- * @param tn the tablename
329- * @param numFiles number of files
330- * @param numRowsPerFile number of rows per file
331- * @return a clientServiceCallable which can be used with the Caller factory for bulk load
332- * @throws Exception when failed to get connection, table or preparation of the bulk load
333- */
334- ClientServiceCallable <Void > generateFileToLoad (TableName tn , int numFiles , int numRowsPerFile )
335- throws Exception {
336- Connection conn = testUtil .getConnection ();
337- FileSystem fs = testUtil .getTestFileSystem ();
338- Configuration conf = testUtil .getConfiguration ();
339- Path baseDir = new Path (fs .getHomeDirectory (), testName .getMethodName () + "_files" );
340- fs .mkdirs (baseDir );
341- final List <Pair <byte [], String >> famPaths = new ArrayList <Pair <byte [], String >>();
342- for (int i = 1 ; i <= numFiles ; i ++) {
343- Path hfile = new Path (baseDir , "file" + i );
344- TestHRegionServerBulkLoad .createHFile (fs , hfile , Bytes .toBytes (SpaceQuotaHelperForTests .F1 ),
345- Bytes .toBytes ("to" ), Bytes .toBytes ("reject" ), numRowsPerFile );
346- famPaths .add (new Pair <>(Bytes .toBytes (SpaceQuotaHelperForTests .F1 ), hfile .toString ()));
347- }
348-
349- // bulk load HFiles
350- Table table = conn .getTable (tn );
351- final String bulkToken = new SecureBulkLoadClient (conf , table ).prepareBulkLoad (conn );
352- return new ClientServiceCallable <Void >(conn , tn , Bytes .toBytes ("row" ),
353- new RpcControllerFactory (conf ).newController (), HConstants .PRIORITY_UNSET ,
354- Collections .emptyMap ()) {
355- @ Override
356- public Void rpcCall () throws Exception {
357- SecureBulkLoadClient secureClient = null ;
358- byte [] regionName = getLocation ().getRegionInfo ().getRegionName ();
359- try (Table table = conn .getTable (getTableName ())) {
360- secureClient = new SecureBulkLoadClient (conf , table );
361- secureClient .secureBulkLoadHFiles (getStub (), famPaths , regionName , true , null , bulkToken );
362- }
363- return null ;
364- }
365- };
366- }
367-
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-
406324 /**
407325 * Removes the space quota from the given namespace
408326 */
@@ -466,14 +384,14 @@ QuotaSettings getTableSpaceQuota(Connection conn, TableName tn) throws IOExcepti
466384 /**
467385 * Waits 30seconds for the HBase quota table to exist.
468386 */
469- public void waitForQuotaTable (Connection conn ) throws IOException {
387+ void waitForQuotaTable (Connection conn ) throws IOException {
470388 waitForQuotaTable (conn , 30_000 );
471389 }
472390
473391 /**
474392 * Waits {@code timeout} milliseconds for the HBase quota table to exist.
475393 */
476- public void waitForQuotaTable (Connection conn , long timeout ) throws IOException {
394+ void waitForQuotaTable (Connection conn , long timeout ) throws IOException {
477395 testUtil .waitFor (timeout , 1000 , new Predicate <IOException >() {
478396 @ Override
479397 public boolean evaluate () throws IOException {
@@ -598,7 +516,7 @@ TableName getNextTableName() {
598516 }
599517
600518 TableName getNextTableName (String namespace ) {
601- return TableName .valueOf (namespace , testName .getMethodName () + counter .getAndIncrement ());
519+ return TableName .valueOf (namespace , testName .get () + counter .getAndIncrement ());
602520 }
603521
604522 TableName createTable () throws Exception {
@@ -648,7 +566,7 @@ TableName createTableWithRegions(Admin admin, String namespace, int numRegions,
648566 TableName createTableInNamespace (NamespaceDescriptor nd ) throws Exception {
649567 final Admin admin = testUtil .getAdmin ();
650568 final TableName tn =
651- TableName .valueOf (nd .getName (), testName .getMethodName () + counter .getAndIncrement ());
569+ TableName .valueOf (nd .getName (), testName .get () + counter .getAndIncrement ());
652570
653571 // Delete the old table
654572 if (admin .tableExists (tn )) {
@@ -658,7 +576,7 @@ TableName createTableInNamespace(NamespaceDescriptor nd) throws Exception {
658576
659577 // Create the table
660578 TableDescriptor tableDesc = TableDescriptorBuilder .newBuilder (tn )
661- .addColumnFamily (ColumnFamilyDescriptorBuilder .of (F1 )).build ();
579+ .setColumnFamily (ColumnFamilyDescriptorBuilder .of (F1 )).build ();
662580
663581 admin .createTable (tableDesc );
664582 return tn ;
@@ -683,6 +601,26 @@ void partitionTablesByQuotaTarget(Multimap<TableName, QuotaSettings> quotas,
683601 }
684602 }
685603
604+ /**
605+ * Bulk-loads a number of files with a number of rows to the given table.
606+ */
607+ Map <byte [], List <Path >> generateFileToLoad (TableName tn , int numFiles , int numRowsPerFile )
608+ throws Exception {
609+ FileSystem fs = testUtil .getTestFileSystem ();
610+ Path baseDir = new Path (fs .getHomeDirectory (), testName .get () + "_files" );
611+ fs .mkdirs (baseDir );
612+ List <Path > hfiles = new ArrayList <>();
613+ for (int i = 1 ; i <= numFiles ; i ++) {
614+ Path hfile = new Path (baseDir , "file" + i );
615+ TestHRegionServerBulkLoad .createHFile (fs , hfile , Bytes .toBytes (SpaceQuotaHelperForTests .F1 ),
616+ Bytes .toBytes ("my" ), Bytes .toBytes ("file" ), numRowsPerFile );
617+ hfiles .add (hfile );
618+ }
619+ Map <byte [], List <Path >> family2Files = new TreeMap <>(Bytes .BYTES_COMPARATOR );
620+ family2Files .put (Bytes .toBytes (SpaceQuotaHelperForTests .F1 ), hfiles );
621+ return family2Files ;
622+ }
623+
686624 /**
687625 * Abstraction to simplify the case where a test needs to verify a certain state on a
688626 * {@code SpaceQuotaSnapshot}. This class fails-fast when there is no such snapshot obtained from
0 commit comments