Esempio n. 1
0
 /// <exception cref="System.IO.IOException"/>
 public static void TrashNonDefaultFS(Configuration conf)
 {
     conf.SetLong(FsTrashIntervalKey, 10);
     {
         // 10 minute
         // attempt non-default FileSystem trash
         FileSystem lfs = FileSystem.GetLocal(conf);
         Path       p   = TestDir;
         Path       f   = new Path(p, "foo/bar");
         if (lfs.Exists(p))
         {
             lfs.Delete(p, true);
         }
         try
         {
             FileSystemTestHelper.WriteFile(lfs, f, 10);
             FileSystem.CloseAll();
             FileSystem localFs = FileSystem.Get(URI.Create("file:///"), conf);
             Trash      lTrash  = new Trash(localFs, conf);
             lTrash.MoveToTrash(f.GetParent());
             CheckTrash(localFs, lTrash.GetCurrentTrashDir(), f);
         }
         finally
         {
             if (lfs.Exists(p))
             {
                 lfs.Delete(p, true);
             }
         }
     }
 }
Esempio n. 2
0
 /// <exception cref="System.IO.IOException"/>
 protected internal virtual Trash GetTrash()
 {
     if (this.trash == null)
     {
         this.trash = new Trash(GetConf());
     }
     return(this.trash);
 }
Esempio n. 3
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestPluggableTrash()
        {
            Configuration conf = new Configuration();

            // Test plugged TrashPolicy
            conf.SetClass("fs.trash.classname", typeof(TestTrash.TestTrashPolicy), typeof(TrashPolicy
                                                                                          ));
            Trash trash = new Trash(conf);

            Assert.True(trash.GetTrashPolicy().GetType().Equals(typeof(TestTrash.TestTrashPolicy
                                                                       )));
        }
Esempio n. 4
0
        /// <exception cref="System.Exception"/>
        public virtual void TestTrashEmptier()
        {
            Configuration conf = new Configuration();

            // Trash with 12 second deletes and 6 seconds checkpoints
            conf.Set(FsTrashIntervalKey, "0.2");
            // 12 seconds
            conf.SetClass("fs.file.impl", typeof(TestTrash.TestLFS), typeof(FileSystem));
            conf.Set(FsTrashCheckpointIntervalKey, "0.1");
            // 6 seconds
            FileSystem fs = FileSystem.GetLocal(conf);

            conf.Set("fs.default.name", fs.GetUri().ToString());
            Trash trash = new Trash(conf);
            // Start Emptier in background
            Runnable emptier       = trash.GetEmptier();
            Thread   emptierThread = new Thread(emptier);

            emptierThread.Start();
            FsShell shell = new FsShell();

            shell.SetConf(conf);
            shell.Init();
            // First create a new directory with mkdirs
            Path myPath = new Path(TestDir, "test/mkdirs");

            Mkdir(fs, myPath);
            int fileIndex = 0;
            ICollection <string> checkpoints = new HashSet <string>();

            while (true)
            {
                // Create a file with a new name
                Path myFile = new Path(TestDir, "test/mkdirs/myFile" + fileIndex++);
                FileSystemTestHelper.WriteFile(fs, myFile, 10);
                // Delete the file to trash
                string[] args = new string[2];
                args[0] = "-rm";
                args[1] = myFile.ToString();
                int val = -1;
                try
                {
                    val = shell.Run(args);
                }
                catch (Exception e)
                {
                    System.Console.Error.WriteLine("Exception raised from Trash.run " + e.GetLocalizedMessage
                                                       ());
                }
                Assert.True(val == 0);
                Path         trashDir = shell.GetCurrentTrashDir();
                FileStatus[] files    = fs.ListStatus(trashDir.GetParent());
                // Scan files in .Trash and add them to set of checkpoints
                foreach (FileStatus file in files)
                {
                    string fileName = file.GetPath().GetName();
                    checkpoints.AddItem(fileName);
                }
                // If checkpoints has 4 objects it is Current + 3 checkpoint directories
                if (checkpoints.Count == 4)
                {
                    // The actual contents should be smaller since the last checkpoint
                    // should've been deleted and Current might not have been recreated yet
                    Assert.True(checkpoints.Count > files.Length);
                    break;
                }
                Thread.Sleep(5000);
            }
            emptierThread.Interrupt();
            emptierThread.Join();
        }