/// <exception cref="System.IO.IOException"/>
        private void TestXAttr(bool persistNamespace)
        {
            Path path = new Path("/p");
            DistributedFileSystem fs = cluster.GetFileSystem();

            fs.Create(path).Close();
            fs.SetXAttr(path, name1, value1, EnumSet.Of(XAttrSetFlag.Create));
            fs.SetXAttr(path, name2, value2, EnumSet.Of(XAttrSetFlag.Create));
            fs.SetXAttr(path, name3, null, EnumSet.Of(XAttrSetFlag.Create));
            Restart(fs, persistNamespace);
            IDictionary <string, byte[]> xattrs = fs.GetXAttrs(path);

            NUnit.Framework.Assert.AreEqual(xattrs.Count, 3);
            Assert.AssertArrayEquals(value1, xattrs[name1]);
            Assert.AssertArrayEquals(value2, xattrs[name2]);
            Assert.AssertArrayEquals(value3, xattrs[name3]);
            fs.SetXAttr(path, name1, newValue1, EnumSet.Of(XAttrSetFlag.Replace));
            Restart(fs, persistNamespace);
            xattrs = fs.GetXAttrs(path);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 3);
            Assert.AssertArrayEquals(newValue1, xattrs[name1]);
            Assert.AssertArrayEquals(value2, xattrs[name2]);
            Assert.AssertArrayEquals(value3, xattrs[name3]);
            fs.RemoveXAttr(path, name1);
            fs.RemoveXAttr(path, name2);
            fs.RemoveXAttr(path, name3);
            Restart(fs, persistNamespace);
            xattrs = fs.GetXAttrs(path);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 0);
        }
Esempio n. 2
0
 public virtual void TestGetXAttrs()
 {
     InitCluster(true, false);
     fs.Mkdirs(Path);
     ExpectException();
     fs.GetXAttrs(Path);
 }
        /// <summary>Tests modifying xattrs on a directory that has been snapshotted</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestModifyReadsCurrentState()
        {
            // Init
            FileSystem.Mkdirs(hdfs, path, FsPermission.CreateImmutable((short)0x1c0));
            SnapshotTestHelper.CreateSnapshot(hdfs, path, snapshotName);
            hdfs.SetXAttr(path, name1, value1);
            hdfs.SetXAttr(path, name2, value2);
            // Verify that current path reflects xattrs, snapshot doesn't
            IDictionary <string, byte[]> xattrs = hdfs.GetXAttrs(path);

            NUnit.Framework.Assert.AreEqual(xattrs.Count, 2);
            Assert.AssertArrayEquals(value1, xattrs[name1]);
            Assert.AssertArrayEquals(value2, xattrs[name2]);
            xattrs = hdfs.GetXAttrs(snapshotPath);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 0);
            // Modify each xattr and make sure it's reflected
            hdfs.SetXAttr(path, name1, value2, EnumSet.Of(XAttrSetFlag.Replace));
            xattrs = hdfs.GetXAttrs(path);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 2);
            Assert.AssertArrayEquals(value2, xattrs[name1]);
            Assert.AssertArrayEquals(value2, xattrs[name2]);
            hdfs.SetXAttr(path, name2, value1, EnumSet.Of(XAttrSetFlag.Replace));
            xattrs = hdfs.GetXAttrs(path);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 2);
            Assert.AssertArrayEquals(value2, xattrs[name1]);
            Assert.AssertArrayEquals(value1, xattrs[name2]);
            // Paranoia checks
            xattrs = hdfs.GetXAttrs(snapshotPath);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 0);
            hdfs.RemoveXAttr(path, name1);
            hdfs.RemoveXAttr(path, name2);
            xattrs = hdfs.GetXAttrs(path);
            NUnit.Framework.Assert.AreEqual(xattrs.Count, 0);
        }