@@ -517,6 +517,50 @@ public void testCleaningRace() throws Exception {
517517 }
518518 }
519519
520+ @ Test
521+ public void testArchiveRegionTableAndRegionDirsNull () throws IOException {
522+ Path rootDir = UTIL .getDataTestDirOnTestFS ("testCleaningRace" );
523+ FileSystem fileSystem = UTIL .getTestFileSystem ();
524+ // Try to archive the file but with null regionDir, can't delete sourceFile
525+ assertFalse (HFileArchiver .archiveRegion (fileSystem , rootDir , null , null ));
526+ }
527+
528+ @ Test
529+ public void testArchiveRegionWithTableDirNull () throws IOException {
530+ Path regionDir = new Path (FSUtils .getTableDir (new Path ("./" ),
531+ TableName .valueOf (name .getMethodName ())), "xyzabc" );
532+ Path familyDir = new Path (regionDir , "rd" );
533+ Path rootDir = UTIL .getDataTestDirOnTestFS ("testCleaningRace" );
534+ Path file = new Path (familyDir , "1" );
535+ Path sourceFile = new Path (rootDir , file );
536+ FileSystem fileSystem = UTIL .getTestFileSystem ();
537+ fileSystem .createNewFile (sourceFile );
538+ Path sourceRegionDir = new Path (rootDir , regionDir );
539+ fileSystem .mkdirs (sourceRegionDir );
540+ // Try to archive the file
541+ assertFalse (HFileArchiver .archiveRegion (fileSystem , rootDir , null , sourceRegionDir ));
542+ assertFalse (fileSystem .exists (sourceRegionDir ));
543+ }
544+
545+ @ Test
546+ public void testArchiveRegionWithRegionDirNull () throws IOException {
547+ Path regionDir = new Path (FSUtils .getTableDir (new Path ("./" ),
548+ TableName .valueOf (name .getMethodName ())), "elgn4nf" );
549+ Path familyDir = new Path (regionDir , "rdar" );
550+ Path rootDir = UTIL .getDataTestDirOnTestFS ("testCleaningRace" );
551+ Path file = new Path (familyDir , "2" );
552+ Path sourceFile = new Path (rootDir , file );
553+ FileSystem fileSystem = UTIL .getTestFileSystem ();
554+ fileSystem .createNewFile (sourceFile );
555+ Path sourceRegionDir = new Path (rootDir , regionDir );
556+ fileSystem .mkdirs (sourceRegionDir );
557+ // Try to archive the file but with null regionDir, can't delete sourceFile
558+ assertFalse (HFileArchiver .archiveRegion (fileSystem , rootDir , sourceRegionDir .getParent (),
559+ null ));
560+ assertTrue (fileSystem .exists (sourceRegionDir ));
561+ fileSystem .delete (sourceRegionDir , true );
562+ }
563+
520564 private void clearArchiveDirectory () throws IOException {
521565 UTIL .getTestFileSystem ().delete (
522566 new Path (UTIL .getDefaultRootDirPath (), HConstants .HFILE_ARCHIVE_DIRECTORY ), true );
0 commit comments