Esempio n. 1
0
        /// <summary>Ensure mtime and atime can be loaded from fsimage.</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestLoadMtimeAtime()
        {
            Configuration  conf    = new Configuration();
            MiniDFSCluster cluster = null;

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();
                cluster.WaitActive();
                DistributedFileSystem hdfs = cluster.GetFileSystem();
                string userDir             = hdfs.GetHomeDirectory().ToUri().GetPath().ToString();
                Path   file = new Path(userDir, "file");
                Path   dir  = new Path(userDir, "/dir");
                Path   link = new Path(userDir, "/link");
                hdfs.CreateNewFile(file);
                hdfs.Mkdirs(dir);
                hdfs.CreateSymlink(file, link, false);
                long mtimeFile = hdfs.GetFileStatus(file).GetModificationTime();
                long atimeFile = hdfs.GetFileStatus(file).GetAccessTime();
                long mtimeDir  = hdfs.GetFileStatus(dir).GetModificationTime();
                long mtimeLink = hdfs.GetFileLinkStatus(link).GetModificationTime();
                long atimeLink = hdfs.GetFileLinkStatus(link).GetAccessTime();
                // save namespace and restart cluster
                hdfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter);
                hdfs.SaveNamespace();
                hdfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave);
                cluster.Shutdown();
                cluster = new MiniDFSCluster.Builder(conf).Format(false).NumDataNodes(1).Build();
                cluster.WaitActive();
                hdfs = cluster.GetFileSystem();
                NUnit.Framework.Assert.AreEqual(mtimeFile, hdfs.GetFileStatus(file).GetModificationTime
                                                    ());
                NUnit.Framework.Assert.AreEqual(atimeFile, hdfs.GetFileStatus(file).GetAccessTime
                                                    ());
                NUnit.Framework.Assert.AreEqual(mtimeDir, hdfs.GetFileStatus(dir).GetModificationTime
                                                    ());
                NUnit.Framework.Assert.AreEqual(mtimeLink, hdfs.GetFileLinkStatus(link).GetModificationTime
                                                    ());
                NUnit.Framework.Assert.AreEqual(atimeLink, hdfs.GetFileLinkStatus(link).GetAccessTime
                                                    ());
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }