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));
        }
Ejemplo n.º 2
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestDUGetUsedWillNotReturnNegative()
        {
            FilePath file = new FilePath(DuDir, "data");

            Assert.True(file.CreateNewFile());
            Configuration conf = new Configuration();

            conf.SetLong(CommonConfigurationKeys.FsDuIntervalKey, 10000L);
            DU du = new DU(file, conf);

            du.DecDfsUsed(long.MaxValue);
            long duSize = du.GetUsed();

            Assert.True(duSize.ToString(), duSize >= 0L);
        }
Ejemplo n.º 3
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestDUSetInitialValue()
        {
            FilePath file = new FilePath(DuDir, "dataX");

            CreateFile(file, 8192);
            DU du = new DU(file, 3000, 1024);

            du.Start();
            Assert.True("Initial usage setting not honored", du.GetUsed() ==
                        1024);
            // wait until the first du runs.
            try
            {
                Thread.Sleep(5000);
            }
            catch (Exception)
            {
            }
            Assert.True("Usage didn't get updated", du.GetUsed() == 8192);
        }
Ejemplo n.º 4
0
 internal DURefreshThread(DU _enclosing)
 {
     this._enclosing = _enclosing;
 }