public virtual void TestTryFailoverToSafeMode() { conf.Set(DFSConfigKeys.DfsHaFenceMethodsKey, TestDFSHAAdmin.GetFencerTrueCommand( )); tool.SetConf(conf); NameNodeAdapter.EnterSafeMode(cluster.GetNameNode(0), false); NUnit.Framework.Assert.AreEqual(-1, RunTool("-failover", "nn2", "nn1")); NUnit.Framework.Assert.IsTrue("Bad output: " + errOutput, errOutput.Contains("is not ready to become active: " + "The NameNode is in safemode")); }
public virtual void TestFencer() { // Test failover with no fencer NUnit.Framework.Assert.AreEqual(-1, RunTool("-failover", "nn1", "nn2")); // Set up fencer to write info about the fencing target into a // tmp file, so we can verify that the args were substituted right FilePath tmpFile = FilePath.CreateTempFile("testFencer", ".txt"); tmpFile.DeleteOnExit(); if (Shell.Windows) { conf.Set(DFSConfigKeys.DfsHaFenceMethodsKey, "shell(echo %target_nameserviceid%.%target_namenodeid% " + "%target_port% %dfs_ha_namenode_id% > " + tmpFile.GetAbsolutePath() + ")"); } else { conf.Set(DFSConfigKeys.DfsHaFenceMethodsKey, "shell(echo -n $target_nameserviceid.$target_namenodeid " + "$target_port $dfs_ha_namenode_id > " + tmpFile.GetAbsolutePath() + ")"); } // Test failover with fencer tool.SetConf(conf); NUnit.Framework.Assert.AreEqual(0, RunTool("-transitionToActive", "nn1")); NUnit.Framework.Assert.AreEqual(0, RunTool("-failover", "nn1", "nn2")); // Test failover with fencer and nameservice NUnit.Framework.Assert.AreEqual(0, RunTool("-ns", "minidfs-ns", "-failover", "nn2" , "nn1")); // Fencer has not run yet, since none of the above required fencing NUnit.Framework.Assert.AreEqual(string.Empty, Files.ToString(tmpFile, Charsets.Utf8 )); // Test failover with fencer and forcefence option NUnit.Framework.Assert.AreEqual(0, RunTool("-failover", "nn1", "nn2", "--forcefence" )); // The fence script should run with the configuration from the target // node, rather than the configuration from the fencing node. Strip // out any trailing spaces and CR/LFs which may be present on Windows. string fenceCommandOutput = Files.ToString(tmpFile, Charsets.Utf8).ReplaceAll(" *[\r\n]+" , string.Empty); NUnit.Framework.Assert.AreEqual("minidfs-ns.nn1 " + nn1Port + " nn1", fenceCommandOutput ); tmpFile.Delete(); // Test failover with forceactive option NUnit.Framework.Assert.AreEqual(0, RunTool("-failover", "nn2", "nn1", "--forceactive" )); // Fencing should not occur, since it was graceful NUnit.Framework.Assert.IsFalse(tmpFile.Exists()); // Test failover with not fencer and forcefence option conf.Unset(DFSConfigKeys.DfsHaFenceMethodsKey); tool.SetConf(conf); NUnit.Framework.Assert.AreEqual(-1, RunTool("-failover", "nn1", "nn2", "--forcefence" )); NUnit.Framework.Assert.IsFalse(tmpFile.Exists()); // Test failover with bad fencer and forcefence option conf.Set(DFSConfigKeys.DfsHaFenceMethodsKey, "foobar!"); tool.SetConf(conf); NUnit.Framework.Assert.AreEqual(-1, RunTool("-failover", "nn1", "nn2", "--forcefence" )); NUnit.Framework.Assert.IsFalse(tmpFile.Exists()); // Test failover with force fence listed before the other arguments conf.Set(DFSConfigKeys.DfsHaFenceMethodsKey, TestDFSHAAdmin.GetFencerTrueCommand( )); tool.SetConf(conf); NUnit.Framework.Assert.AreEqual(0, RunTool("-failover", "--forcefence", "nn1", "nn2" )); }