public virtual void TestSmallAppendRace() { Path file = new Path("/testSmallAppendRace"); string fName = file.ToUri().GetPath(); // Create the file and write a small amount of data. FSDataOutputStream stm = fs.Create(file); AppendTestUtil.Write(stm, 0, 123); stm.Close(); // Introduce a delay between getFileInfo and calling append() against NN. DFSClient client = DFSClientAdapter.GetDFSClient(fs); DFSClient spyClient = Org.Mockito.Mockito.Spy(client); Org.Mockito.Mockito.When(spyClient.GetFileInfo(fName)).ThenAnswer(new _Answer_548 (client, fName)); DFSClientAdapter.SetDFSClient(fs, spyClient); // Create two threads for doing appends to the same file. Sharpen.Thread worker1 = new _Thread_564(this, file); Sharpen.Thread worker2 = new _Thread_574(this, file); worker1.Start(); worker2.Start(); // append will fail when the file size crosses the checksum chunk boundary, // if append was called with a stale file stat. DoSmallAppends(file, fs, 20); }
public virtual void TestClientThatDoesNotSupportEncryption() { MiniDFSCluster cluster = null; try { Configuration conf = new Configuration(); // Set short retry timeouts so this test runs faster conf.SetInt(DFSConfigKeys.DfsClientRetryWindowBase, 10); cluster = new MiniDFSCluster.Builder(conf).Build(); FileSystem fs = GetFileSystem(conf); WriteTestDataToFile(fs); NUnit.Framework.Assert.AreEqual(PlainText, DFSTestUtil.ReadFile(fs, TestPath)); fs.Close(); cluster.Shutdown(); SetEncryptionConfigKeys(conf); cluster = new MiniDFSCluster.Builder(conf).ManageDataDfsDirs(false).ManageNameDfsDirs (false).Format(false).StartupOption(HdfsServerConstants.StartupOption.Regular).Build (); fs = GetFileSystem(conf); DFSClient client = DFSClientAdapter.GetDFSClient((DistributedFileSystem)fs); DFSClient spyClient = Org.Mockito.Mockito.Spy(client); Org.Mockito.Mockito.DoReturn(false).When(spyClient).ShouldEncryptData(); DFSClientAdapter.SetDFSClient((DistributedFileSystem)fs, spyClient); GenericTestUtils.LogCapturer logs = GenericTestUtils.LogCapturer.CaptureLogs(LogFactory .GetLog(typeof(DataNode))); try { NUnit.Framework.Assert.AreEqual(PlainText, DFSTestUtil.ReadFile(fs, TestPath)); if (resolverClazz != null && !resolverClazz.EndsWith("TestTrustedChannelResolver" )) { NUnit.Framework.Assert.Fail("Should not have been able to read without encryption enabled." ); } } catch (IOException ioe) { GenericTestUtils.AssertExceptionContains("Could not obtain block:", ioe); } finally { logs.StopCapturing(); } fs.Close(); if (resolverClazz == null) { GenericTestUtils.AssertMatches(logs.GetOutput(), "Failed to read expected encryption handshake from client at" ); } } finally { if (cluster != null) { cluster.Shutdown(); } } }