/// <summary> /// Test /// <see cref="Snapshot.IdComparator"/> /// . /// </summary> public virtual void TestIdCmp() { PermissionStatus perm = PermissionStatus.CreateImmutable("user", "group", FsPermission .CreateImmutable((short)0)); INodeDirectory snapshottable = new INodeDirectory(0, DFSUtil.String2Bytes("foo"), perm, 0L); snapshottable.AddSnapshottableFeature(); Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot[] snapshots = new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot [] { new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot(1, "s1", snapshottable ), new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot(1, "s1", snapshottable ), new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot(2, "s2", snapshottable ), new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot(2, "s2", snapshottable ) }; NUnit.Framework.Assert.AreEqual(0, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .IdComparator.Compare(null, null)); foreach (Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s in snapshots) { NUnit.Framework.Assert.IsTrue(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .IdComparator.Compare(null, s) > 0); NUnit.Framework.Assert.IsTrue(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .IdComparator.Compare(s, null) < 0); foreach (Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot t in snapshots) { int expected = string.CompareOrdinal(s.GetRoot().GetLocalName(), t.GetRoot().GetLocalName ()); int computed = Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.IdComparator .Compare(s, t); NUnit.Framework.Assert.AreEqual(expected > 0, computed > 0); NUnit.Framework.Assert.AreEqual(expected == 0, computed == 0); NUnit.Framework.Assert.AreEqual(expected < 0, computed < 0); } } }
/// <exception cref="System.IO.IOException"/> private static INodeDirectory CreateINodeDirectory(INodeDirectory parent, string name, string owner, string group, short perm) { PermissionStatus permStatus = PermissionStatus.CreateImmutable(owner, group, FsPermission .CreateImmutable(perm)); INodeDirectory inodeDirectory = new INodeDirectory(INodeId.GrandfatherInodeId, Sharpen.Runtime.GetBytesForString (name, "UTF-8"), permStatus, 0L); parent.AddChild(inodeDirectory); return(inodeDirectory); }
/// <exception cref="System.IO.IOException"/> private static INodeFile CreateINodeFile(INodeDirectory parent, string name, string owner, string group, short perm) { PermissionStatus permStatus = PermissionStatus.CreateImmutable(owner, group, FsPermission .CreateImmutable(perm)); INodeFile inodeFile = new INodeFile(INodeId.GrandfatherInodeId, Sharpen.Runtime.GetBytesForString (name, "UTF-8"), permStatus, 0L, 0L, null, Replication, PreferredBlockSize, unchecked ( (byte)0)); parent.AddChild(inodeFile); return(inodeFile); }
/// <summary> /// Create an aborted in-progress log in the given directory, containing /// only a specified number of "mkdirs" operations. /// </summary> /// <exception cref="System.IO.IOException"/> public static void CreateAbortedLogWithMkdirs(FilePath editsLogDir, int numDirs, long firstTxId, long newInodeId) { FSEditLog editLog = FSImageTestUtil.CreateStandaloneEditLog(editsLogDir); editLog.SetNextTxId(firstTxId); editLog.OpenForWrite(); PermissionStatus perms = PermissionStatus.CreateImmutable("fakeuser", "fakegroup" , FsPermission.CreateImmutable((short)0x1ed)); for (int i = 1; i <= numDirs; i++) { string dirName = "dir" + i; INodeDirectory dir = new INodeDirectory(newInodeId + i - 1, DFSUtil.String2Bytes( dirName), perms, 0L); editLog.LogMkDir("/" + dirName, dir); } editLog.LogSync(); editLog.AbortCurrentLogSegment(); }