/// <exception cref="System.Exception"/> public virtual void TestListDotReserved() { // Create a base file for comparison Path baseFileRaw = new Path("/.reserved/raw/base"); int len = 8192; DFSTestUtil.CreateFile(fs, baseFileRaw, len, (short)1, unchecked ((int)(0xFEED))); /* * Ensure that you can't list /.reserved. Ever. */ try { fs.ListStatus(new Path("/.reserved")); NUnit.Framework.Assert.Fail("expected FNFE"); } catch (FileNotFoundException e) { GenericTestUtils.AssertExceptionContains("/.reserved does not exist", e); } try { fs.ListStatus(new Path("/.reserved/.inodes")); NUnit.Framework.Assert.Fail("expected FNFE"); } catch (FileNotFoundException e) { GenericTestUtils.AssertExceptionContains("/.reserved/.inodes does not exist", e); } FileStatus[] fileStatuses = fs.ListStatus(new Path("/.reserved/raw")); NUnit.Framework.Assert.AreEqual("expected 1 entry", fileStatuses.Length, 1); GenericTestUtils.AssertMatches(fileStatuses[0].GetPath().ToString(), "/.reserved/raw/base" ); }
public virtual void TestSharedEditsMissingLogs() { RemoveStandbyNameDirs(); CheckpointSignature sig = nn0.GetRpcServer().RollEditLog(); NUnit.Framework.Assert.AreEqual(3, sig.GetCurSegmentTxId()); // Should have created edits_1-2 in shared edits dir URI editsUri = cluster.GetSharedEditsDir(0, 1); FilePath editsDir = new FilePath(editsUri); FilePath editsSegment = new FilePath(new FilePath(editsDir, "current"), NNStorage .GetFinalizedEditsFileName(1, 2)); GenericTestUtils.AssertExists(editsSegment); // Delete the segment. NUnit.Framework.Assert.IsTrue(editsSegment.Delete()); // Trying to bootstrap standby should now fail since the edit // logs aren't available in the shared dir. GenericTestUtils.LogCapturer logs = GenericTestUtils.LogCapturer.CaptureLogs(LogFactory .GetLog(typeof(BootstrapStandby))); try { int rc = BootstrapStandby.Run(new string[] { "-force" }, cluster.GetConfiguration (1)); NUnit.Framework.Assert.AreEqual(BootstrapStandby.ErrCodeLogsUnavailable, rc); } finally { logs.StopCapturing(); } GenericTestUtils.AssertMatches(logs.GetOutput(), "FATAL.*Unable to read transaction ids 1-3 from the configured shared" ); }
public virtual void TestServerSaslNoClientSasl() { HdfsConfiguration clusterConf = CreateSecureConfig("authentication,integrity,privacy" ); // Set short retry timeouts so this test runs faster clusterConf.SetInt(DFSConfigKeys.DfsClientRetryWindowBase, 10); StartCluster(clusterConf); HdfsConfiguration clientConf = new HdfsConfiguration(clusterConf); clientConf.Set(DFSConfigKeys.DfsDataTransferProtectionKey, string.Empty); GenericTestUtils.LogCapturer logs = GenericTestUtils.LogCapturer.CaptureLogs(LogFactory .GetLog(typeof(DataNode))); try { DoTest(clientConf); NUnit.Framework.Assert.Fail("Should fail if SASL data transfer protection is not " + "configured or not supported in client"); } catch (IOException e) { GenericTestUtils.AssertMatches(e.Message, "could only be replicated to 0 nodes"); } finally { logs.StopCapturing(); } GenericTestUtils.AssertMatches(logs.GetOutput(), "Failed to read expected SASL data transfer protection " + "handshake from client at"); }
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(); } } }
public virtual void TestEncryptedReadWithAES() { MiniDFSCluster cluster = null; try { Configuration conf = new Configuration(); conf.Set(DFSConfigKeys.DfsEncryptDataTransferCipherSuitesKey, "AES/CTR/NoPadding" ); cluster = new MiniDFSCluster.Builder(conf).Build(); FileSystem fs = GetFileSystem(conf); WriteTestDataToFile(fs); NUnit.Framework.Assert.AreEqual(PlainText, DFSTestUtil.ReadFile(fs, TestPath)); FileChecksum checksum = fs.GetFileChecksum(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); GenericTestUtils.LogCapturer logs = GenericTestUtils.LogCapturer.CaptureLogs(LogFactory .GetLog(typeof(SaslDataTransferServer))); GenericTestUtils.LogCapturer logs1 = GenericTestUtils.LogCapturer.CaptureLogs(LogFactory .GetLog(typeof(DataTransferSaslUtil))); try { NUnit.Framework.Assert.AreEqual(PlainText, DFSTestUtil.ReadFile(fs, TestPath)); NUnit.Framework.Assert.AreEqual(checksum, fs.GetFileChecksum(TestPath)); } finally { logs.StopCapturing(); logs1.StopCapturing(); } fs.Close(); if (resolverClazz == null) { // Test client and server negotiate cipher option GenericTestUtils.AssertMatches(logs.GetOutput(), "Server using cipher suite"); // Check the IOStreamPair GenericTestUtils.AssertMatches(logs1.GetOutput(), "Creating IOStreamPair of CryptoInputStream and CryptoOutputStream." ); } } finally { if (cluster != null) { cluster.Shutdown(); } } }
/// <exception cref="System.Exception"/> public virtual void TestListRecursive() { Path rootPath = new Path("/"); Path p = rootPath; for (int i = 0; i < 3; i++) { p = new Path(p, "dir" + i); fs.Mkdirs(p); } Path curPath = new Path("/.reserved/raw"); int cnt = 0; FileStatus[] fileStatuses = fs.ListStatus(curPath); while (fileStatuses != null && fileStatuses.Length > 0) { FileStatus f = fileStatuses[0]; GenericTestUtils.AssertMatches(f.GetPath().ToString(), "/.reserved/raw"); curPath = Path.GetPathWithoutSchemeAndAuthority(f.GetPath()); cnt++; fileStatuses = fs.ListStatus(curPath); } NUnit.Framework.Assert.AreEqual(3, cnt); }
public virtual void TestToString() { GenericTestUtils.AssertMatches(qjm.ToString(), "QJM to \\[127.0.0.1:\\d+, 127.0.0.1:\\d+, 127.0.0.1:\\d+\\]" ); }