3232import java .util .Random ;
3333import java .util .Set ;
3434import java .util .concurrent .atomic .AtomicInteger ;
35+ import java .util .function .Supplier ;
3536
3637import org .junit .After ;
3738import org .junit .Before ;
@@ -579,7 +580,6 @@ public void testExistingFileTrash() throws IOException {
579580 conf .setClass ("fs.file.impl" , TestLFS .class , FileSystem .class );
580581 FileSystem fs = FileSystem .getLocal (conf );
581582 conf .set ("fs.defaultFS" , fs .getUri ().toString ());
582- conf .setBoolean (FS_TRASH_CLEAN_TRASHROOT_ENABLE_KEY , true );
583583 conf .setLong (FS_TRASH_INTERVAL_KEY , 0 ); // disabled
584584 assertFalse (new Trash (conf ).isEnabled ());
585585
@@ -636,7 +636,6 @@ public void testNonDefaultFS() throws IOException {
636636 Configuration conf = new Configuration ();
637637 conf .setClass ("fs.file.impl" , TestLFS .class , FileSystem .class );
638638 conf .set ("fs.defaultFS" , "invalid://host/bar/foo" );
639- conf .setBoolean (FS_TRASH_CLEAN_TRASHROOT_ENABLE_KEY , true );
640639 trashNonDefaultFS (conf );
641640 }
642641
@@ -646,7 +645,6 @@ public void testPluggableTrash() throws IOException {
646645
647646 // Test plugged TrashPolicy
648647 conf .setClass ("fs.trash.classname" , TestTrashPolicy .class , TrashPolicy .class );
649- conf .setBoolean (FS_TRASH_CLEAN_TRASHROOT_ENABLE_KEY , true );
650648 Trash trash = new Trash (conf );
651649 assertTrue (trash .getTrashPolicy ().getClass ().equals (TestTrashPolicy .class ));
652650 }
@@ -678,7 +676,6 @@ public void testMoveEmptyDirToTrash() throws Exception {
678676 RawLocalFileSystem .class ,
679677 FileSystem .class );
680678 conf .setLong (FS_TRASH_INTERVAL_KEY , 1 ); // 1 min
681- conf .setBoolean (FS_TRASH_CLEAN_TRASHROOT_ENABLE_KEY , true );
682679 FileSystem fs = FileSystem .get (conf );
683680 verifyMoveEmptyDirToTrash (fs , conf );
684681 }
@@ -696,7 +693,6 @@ public void testTrashRestarts() throws Exception {
696693 TrashPolicy .class );
697694 conf .setClass ("fs.file.impl" , TestLFS .class , FileSystem .class );
698695 conf .set (FS_TRASH_INTERVAL_KEY , "50" ); // in milliseconds for test
699- conf .setBoolean (FS_TRASH_CLEAN_TRASHROOT_ENABLE_KEY , true );
700696 Trash trash = new Trash (conf );
701697 // create 5 checkpoints
702698 for (int i =0 ; i <5 ; i ++) {
@@ -725,7 +721,6 @@ public void testTrashPermission() throws IOException {
725721 TrashPolicy .class );
726722 conf .setClass ("fs.file.impl" , TestLFS .class , FileSystem .class );
727723 conf .set (FS_TRASH_INTERVAL_KEY , "0.2" );
728- conf .setBoolean (FS_TRASH_CLEAN_TRASHROOT_ENABLE_KEY , true );
729724 verifyTrashPermission (FileSystem .getLocal (conf ), conf );
730725 }
731726
@@ -738,7 +733,6 @@ public void testTrashEmptier() throws Exception {
738733 conf .set (FS_TRASH_CHECKPOINT_INTERVAL_KEY , "0.1" ); // 6 seconds
739734 FileSystem fs = FileSystem .getLocal (conf );
740735 conf .set ("fs.default.name" , fs .getUri ().toString ());
741- conf .setBoolean (FS_TRASH_CLEAN_TRASHROOT_ENABLE_KEY , true );
742736
743737 Trash trash = new Trash (conf );
744738
@@ -797,10 +791,10 @@ public void testTrashEmptier() throws Exception {
797791 * Test trash emptier can whether delete non-checkpoint dir or not.
798792 * @throws Exception
799793 */
800- @ Test
801- public void testTrashEmptierWithNonCheckpointDir () throws Exception {
794+ @ Test ()
795+ public void testTrashEmptierCleanDirNotInCheckpointDir () throws Exception {
802796 Configuration conf = new Configuration ();
803- // Trash with 12 second deletes and 6 seconds checkpoints
797+ // Trash with 12 second deletes and 6 seconds checkpoints.
804798 conf .set (FS_TRASH_INTERVAL_KEY , "0.2" ); // 12 seconds
805799 conf .setClass ("fs.file.impl" , TestLFS .class , FileSystem .class );
806800 conf .set (FS_TRASH_CHECKPOINT_INTERVAL_KEY , "0.1" ); // 6 seconds
@@ -810,7 +804,7 @@ public void testTrashEmptierWithNonCheckpointDir() throws Exception {
810804
811805 Trash trash = new Trash (conf );
812806
813- // Start Emptier in background
807+ // Start Emptier in background.
814808 Runnable emptier = trash .getEmptier ();
815809 Thread emptierThread = new Thread (emptier );
816810 emptierThread .start ();
@@ -819,39 +813,25 @@ public void testTrashEmptierWithNonCheckpointDir() throws Exception {
819813 shell .setConf (conf );
820814 shell .init ();
821815
822- // First create a new directory with mkdirs
823- Path myPath = new Path (TEST_DIR , "test/mkdirs" );
824- mkdir (fs , myPath );
825816 // Make sure the .Trash dir existed.
826817 mkdir (fs , shell .getCurrentTrashDir ());
827818 assertTrue (fs .exists (shell .getCurrentTrashDir ()));
819+ // Create a directory under .Trash directly.
820+ Path myPath = new Path (shell .getCurrentTrashDir ().getParent (), "test_dirs" );
821+ mkdir (fs , myPath );
822+ assertTrue (fs .exists (myPath ));
828823
829- int fileIndex = 0 ;
830- int loopCount = 10 ;
831- while (fileIndex < loopCount ) {
832- // Create a file with a new name
833- Path myFile = new Path (TEST_DIR , "test/mkdirs/myFile" + fileIndex ++);
834- writeFile (fs , myFile , 10 );
835-
836- // Move the file to trash root.
837- String [] args = new String [3 ];
838- args [0 ] = "-mv" ;
839- args [1 ] = myFile .toString ();
840- args [2 ] = shell .getCurrentTrashDir ().getParent ().toString ();
841- int val = -1 ;
842- try {
843- val = shell .run (args );
844- } catch (Exception e ) {
845- System .err .println ("Exception raised from Trash.run " +
846- e .getLocalizedMessage ());
824+ GenericTestUtils .waitFor (new Supplier <Boolean >() {
825+ @ Override
826+ public Boolean get () {
827+ try {
828+ return !fs .exists (myPath );
829+ } catch (IOException e ) {
830+ // Do nothing.
831+ }
832+ return false ;
847833 }
848- assertTrue (val == 0 );
849- }
850- Thread .sleep (18000 );
851-
852- Path trashDir = shell .getCurrentTrashDir ();
853- FileStatus [] files = fs .listStatus (trashDir .getParent ());
854- assertTrue (files .length <= 1 );
834+ }, 6000 , 60000 );
855835 emptierThread .interrupt ();
856836 emptierThread .join ();
857837 }
0 commit comments