Ejemplo n.º 1
0
        /// <summary>Verify that du returns expected used space for a file.</summary>
        /// <remarks>
        /// Verify that du returns expected used space for a file.
        /// We assume here that if a file system crates a file of size
        /// that is a multiple of the block size in this file system,
        /// then the used size for the file will be exactly that size.
        /// This is true for most file systems.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestDU()
        {
            int writtenSize = 32 * 1024;
            // writing 32K
            // Allow for extra 4K on-disk slack for local file systems
            // that may store additional file metadata (eg ext attrs).
            int      slack = 4 * 1024;
            FilePath file  = new FilePath(DuDir, "data");

            CreateFile(file, writtenSize);
            Thread.Sleep(5000);
            // let the metadata updater catch up
            DU du = new DU(file, 10000);

            du.Start();
            long duSize = du.GetUsed();

            du.Shutdown();
            Assert.True("Invalid on-disk size", duSize >= writtenSize && writtenSize
                        <= (duSize + slack));
            //test with 0 interval, will not launch thread
            du = new DU(file, 0);
            du.Start();
            duSize = du.GetUsed();
            du.Shutdown();
            Assert.True("Invalid on-disk size", duSize >= writtenSize && writtenSize
                        <= (duSize + slack));
            //test without launching thread
            du     = new DU(file, 10000);
            duSize = du.GetUsed();
            Assert.True("Invalid on-disk size", duSize >= writtenSize && writtenSize
                        <= (duSize + slack));
        }