/// <summary> /// Test case that stops a writer after finalizing a block but /// before calling completeFile, recovers a file from another writer, /// starts writing from that writer, and then has the old lease holder /// call completeFile /// </summary> /// <exception cref="System.Exception"/> public virtual void TestCompleteOtherLeaseHoldersFile() { cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(5).Build(); try { cluster.WaitActive(); NamenodeProtocols preSpyNN = cluster.GetNameNodeRpc(); NamenodeProtocols spyNN = Org.Mockito.Mockito.Spy(preSpyNN); // Delay completeFile GenericTestUtils.DelayAnswer delayer = new GenericTestUtils.DelayAnswer(Log); Org.Mockito.Mockito.DoAnswer(delayer).When(spyNN).Complete(Matchers.AnyString(), Matchers.AnyString(), (ExtendedBlock)Matchers.AnyObject(), Matchers.AnyLong()); DFSClient client = new DFSClient(null, spyNN, conf, null); file1 = new Path("/testCompleteOtherLease"); OutputStream stm = client.Create("/testCompleteOtherLease", true); // write 1/2 block AppendTestUtil.Write(stm, 0, 4096); AtomicReference <Exception> err = new AtomicReference <Exception>(); Sharpen.Thread t = new _Thread_242(stm, err); t.Start(); Log.Info("Waiting for close to get to latch..."); delayer.WaitForCall(); // At this point, the block is finalized on the DNs, but the file // has not been completed in the NN. // Lose the leases Log.Info("Killing lease checker"); client.GetLeaseRenewer().InterruptAndJoin(); FileSystem fs1 = cluster.GetFileSystem(); FileSystem fs2 = AppendTestUtil.CreateHdfsWithDifferentUsername(fs1.GetConf()); Log.Info("Recovering file"); RecoverFile(fs2); Log.Info("Opening file for append from new fs"); FSDataOutputStream appenderStream = fs2.Append(file1); Log.Info("Writing some data from new appender"); AppendTestUtil.Write(appenderStream, 0, 4096); Log.Info("Telling old close to proceed."); delayer.Proceed(); Log.Info("Waiting for close to finish."); t.Join(); Log.Info("Close finished."); // We expect that close will get a "Lease mismatch" // error. Exception thrownByClose = err.Get(); NUnit.Framework.Assert.IsNotNull(thrownByClose); NUnit.Framework.Assert.IsTrue(thrownByClose is IOException); if (!thrownByClose.Message.Contains("Lease mismatch")) { throw thrownByClose; } // The appender should be able to close properly appenderStream.Close(); } finally { cluster.Shutdown(); } }
public virtual void TestAppend2Twice() { Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).Build(); DistributedFileSystem fs1 = cluster.GetFileSystem(); FileSystem fs2 = AppendTestUtil.CreateHdfsWithDifferentUsername(conf); try { Path p = new Path("/testAppendTwice/foo"); int len = 1 << 16; byte[] fileContents = AppendTestUtil.InitBuffer(len); { // create a new file with a full block. FSDataOutputStream @out = fs2.Create(p, true, 4096, (short)1, len); @out.Write(fileContents, 0, len); @out.Close(); } //1st append does not add any data so that the last block remains full //and the last block in INodeFileUnderConstruction is a BlockInfo //but not BlockInfoUnderConstruction. ((DistributedFileSystem)fs2).Append(p, EnumSet.Of(CreateFlag.Append, CreateFlag.NewBlock ), 4096, null); // 2nd append should get AlreadyBeingCreatedException fs1.Append(p); NUnit.Framework.Assert.Fail(); } catch (RemoteException re) { AppendTestUtil.Log.Info("Got an exception:", re); NUnit.Framework.Assert.AreEqual(typeof(AlreadyBeingCreatedException).FullName, re .GetClassName()); } finally { fs2.Close(); fs1.Close(); cluster.Shutdown(); } }
public virtual void TestTC5() { Path p = new Path("/TC5/foo"); System.Console.Out.WriteLine("p=" + p); { //a. Create file on Machine M1. Write half block to it. Close file. FSDataOutputStream @out = fs.Create(p, false, buffersize, Replication, BlockSize); AppendTestUtil.Write(@out, 0, (int)(BlockSize / 2)); @out.Close(); } //b. Reopen file in "append" mode on Machine M1. FSDataOutputStream out_1 = fs.Append(p); //c. On Machine M2, reopen file in "append" mode. This should fail. try { AppendTestUtil.CreateHdfsWithDifferentUsername(conf).Append(p); NUnit.Framework.Assert.Fail("This should fail."); } catch (IOException ioe) { AppendTestUtil.Log.Info("GOOD: got an exception", ioe); } try { ((DistributedFileSystem)AppendTestUtil.CreateHdfsWithDifferentUsername(conf)).Append (p, EnumSet.Of(CreateFlag.Append, CreateFlag.NewBlock), 4096, null); NUnit.Framework.Assert.Fail("This should fail."); } catch (IOException ioe) { AppendTestUtil.Log.Info("GOOD: got an exception", ioe); } //d. On Machine M1, close file. out_1.Close(); }