Example #1
0
        public virtual void TestMkdir()
        {
            Configuration         conf    = new HdfsConfiguration();
            MiniDFSCluster        cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(2).Build();
            DistributedFileSystem dfs     = cluster.GetFileSystem();

            try
            {
                // Create a dir in root dir, should succeed
                NUnit.Framework.Assert.IsTrue(dfs.Mkdir(new Path("/mkdir-" + Time.Now()), FsPermission
                                                        .GetDefault()));
                // Create a dir when parent dir exists as a file, should fail
                IOException expectedException = null;
                string      filePath          = "/mkdir-file-" + Time.Now();
                DFSTestUtil.WriteFile(dfs, new Path(filePath), "hello world");
                try
                {
                    dfs.Mkdir(new Path(filePath + "/mkdir"), FsPermission.GetDefault());
                }
                catch (IOException e)
                {
                    expectedException = e;
                }
                NUnit.Framework.Assert.IsTrue("Create a directory when parent dir exists as file using"
                                              + " mkdir() should throw ParentNotDirectoryException ", expectedException != null &&
                                              expectedException is ParentNotDirectoryException);
                // Create a dir in a non-exist directory, should fail
                expectedException = null;
                try
                {
                    dfs.Mkdir(new Path("/non-exist/mkdir-" + Time.Now()), FsPermission.GetDefault());
                }
                catch (IOException e)
                {
                    expectedException = e;
                }
                NUnit.Framework.Assert.IsTrue("Create a directory in a non-exist parent dir using"
                                              + " mkdir() should throw FileNotFoundException ", expectedException != null &&
                                              expectedException is FileNotFoundException);
            }
            finally
            {
                dfs.Close();
                cluster.Shutdown();
            }
        }
        /// <summary>Test that encryption zones are properly tracked by the standby.</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestEncryptionZonesTrackedOnStandby()
        {
            int  len      = 8196;
            Path dir      = new Path("/enc");
            Path dirChild = new Path(dir, "child");
            Path dirFile  = new Path(dir, "file");

            fs.Mkdir(dir, FsPermission.GetDirDefault());
            dfsAdmin0.CreateEncryptionZone(dir, TestKey);
            fs.Mkdir(dirChild, FsPermission.GetDirDefault());
            DFSTestUtil.CreateFile(fs, dirFile, len, (short)1, unchecked ((int)(0xFEED)));
            string contents = DFSTestUtil.ReadFile(fs, dirFile);

            // Failover the current standby to active.
            HATestUtil.WaitForStandbyToCatchUp(nn0, nn1);
            cluster.ShutdownNameNode(0);
            cluster.TransitionToActive(1);
            NUnit.Framework.Assert.AreEqual("Got unexpected ez path", dir.ToString(), dfsAdmin1
                                            .GetEncryptionZoneForPath(dir).GetPath().ToString());
            NUnit.Framework.Assert.AreEqual("Got unexpected ez path", dir.ToString(), dfsAdmin1
                                            .GetEncryptionZoneForPath(dirChild).GetPath().ToString());
            NUnit.Framework.Assert.AreEqual("File contents after failover were changed", contents
                                            , DFSTestUtil.ReadFile(fs, dirFile));
        }