public virtual void TestCreate() { string src = "/testNamenodeRetryCache/testCreate/file"; // Two retried calls succeed NewCall(); HdfsFileStatus status = nnRpc.Create(src, perm, "holder", new EnumSetWritable <CreateFlag >(EnumSet.Of(CreateFlag.Create)), true, (short)1, BlockSize, null); NUnit.Framework.Assert.AreEqual(status, nnRpc.Create(src, perm, "holder", new EnumSetWritable <CreateFlag>(EnumSet.Of(CreateFlag.Create)), true, (short)1, BlockSize, null)); NUnit.Framework.Assert.AreEqual(status, nnRpc.Create(src, perm, "holder", new EnumSetWritable <CreateFlag>(EnumSet.Of(CreateFlag.Create)), true, (short)1, BlockSize, null)); // A non-retried call fails NewCall(); try { nnRpc.Create(src, perm, "holder", new EnumSetWritable <CreateFlag>(EnumSet.Of(CreateFlag .Create)), true, (short)1, BlockSize, null); NUnit.Framework.Assert.Fail("testCreate - expected exception is not thrown"); } catch (IOException) { } }
public virtual void TestAddBlockRetryShouldReturnBlockWithLocations() { string src = "/testAddBlockRetryShouldReturnBlockWithLocations"; NamenodeProtocols nameNodeRpc = cluster.GetNameNodeRpc(); // create file nameNodeRpc.Create(src, FsPermission.GetFileDefault(), "clientName", new EnumSetWritable <CreateFlag>(EnumSet.Of(CreateFlag.Create)), true, (short)3, 1024, null); // start first addBlock() Log.Info("Starting first addBlock for " + src); LocatedBlock lb1 = nameNodeRpc.AddBlock(src, "clientName", null, null, INodeId.GrandfatherInodeId , null); NUnit.Framework.Assert.IsTrue("Block locations should be present", lb1.GetLocations ().Length > 0); cluster.RestartNameNode(); nameNodeRpc = cluster.GetNameNodeRpc(); LocatedBlock lb2 = nameNodeRpc.AddBlock(src, "clientName", null, null, INodeId.GrandfatherInodeId , null); NUnit.Framework.Assert.AreEqual("Blocks are not equal", lb1.GetBlock(), lb2.GetBlock ()); NUnit.Framework.Assert.IsTrue("Wrong locations with retry", lb2.GetLocations().Length > 0); }
public virtual void TestRetryAddBlockWhileInChooseTarget() { string src = "/testRetryAddBlockWhileInChooseTarget"; FSNamesystem ns = cluster.GetNamesystem(); NamenodeProtocols nn = cluster.GetNameNodeRpc(); // create file nn.Create(src, FsPermission.GetFileDefault(), "clientName", new EnumSetWritable <CreateFlag >(EnumSet.Of(CreateFlag.Create)), true, (short)3, 1024, null); // start first addBlock() Log.Info("Starting first addBlock for " + src); LocatedBlock[] onRetryBlock = new LocatedBlock[1]; DatanodeStorageInfo[] targets = ns.GetNewBlockTargets(src, INodeId.GrandfatherInodeId , "clientName", null, null, null, onRetryBlock); NUnit.Framework.Assert.IsNotNull("Targets must be generated", targets); // run second addBlock() Log.Info("Starting second addBlock for " + src); nn.AddBlock(src, "clientName", null, null, INodeId.GrandfatherInodeId, null); NUnit.Framework.Assert.IsTrue("Penultimate block must be complete", CheckFileProgress (src, false)); LocatedBlocks lbs = nn.GetBlockLocations(src, 0, long.MaxValue); NUnit.Framework.Assert.AreEqual("Must be one block", 1, lbs.GetLocatedBlocks().Count ); LocatedBlock lb2 = lbs.Get(0); NUnit.Framework.Assert.AreEqual("Wrong replication", Replication, lb2.GetLocations ().Length); // continue first addBlock() LocatedBlock newBlock = ns.StoreAllocatedBlock(src, INodeId.GrandfatherInodeId, "clientName" , null, targets); NUnit.Framework.Assert.AreEqual("Blocks are not equal", lb2.GetBlock(), newBlock. GetBlock()); // check locations lbs = nn.GetBlockLocations(src, 0, long.MaxValue); NUnit.Framework.Assert.AreEqual("Must be one block", 1, lbs.GetLocatedBlocks().Count ); LocatedBlock lb1 = lbs.Get(0); NUnit.Framework.Assert.AreEqual("Wrong replication", Replication, lb1.GetLocations ().Length); NUnit.Framework.Assert.AreEqual("Blocks are not equal", lb1.GetBlock(), lb2.GetBlock ()); }