/// <summary>Compare the actual output with the expected output</summary> /// <param name="compdata"/> /// <returns/> private bool CompareTestOutput(ComparatorData compdata, CommandExecutor.Result cmdResult ) { // Compare the output based on the comparator string comparatorType = compdata.GetComparatorType(); Type comparatorClass = null; // If testMode is "test", then run the command and compare the output // If testMode is "nocompare", then run the command and dump the output. // Do not compare bool compareOutput = false; if (testMode.Equals(TestmodeTest)) { try { // Initialize the comparator class and run its compare method comparatorClass = Runtime.GetType("org.apache.hadoop.cli.util." + comparatorType ); ComparatorBase comp = (ComparatorBase)System.Activator.CreateInstance(comparatorClass ); compareOutput = comp.Compare(cmdResult.GetCommandOutput(), ExpandCommand(compdata .GetExpectedOutput())); } catch (Exception e) { Log.Info("Error in instantiating the comparator" + e); } } return(compareOutput); }
/// <summary>TESTS RUNNER</summary> public virtual void TestAll() { Assert.True("Number of tests has to be greater then zero", testsFromConfigFile .Count > 0); Log.Info("TestAll"); // Run the tests defined in the testConf.xml config file. for (int index = 0; index < testsFromConfigFile.Count; index++) { CLITestData testdata = testsFromConfigFile[index]; // Execute the test commands AList <CLICommand> testCommands = testdata.GetTestCommands(); CommandExecutor.Result cmdResult = null; foreach (CLICommand cmd in testCommands) { try { cmdResult = Execute(cmd); } catch (Exception e) { NUnit.Framework.Assert.Fail(StringUtils.StringifyException(e)); } } bool overallTCResult = true; // Run comparators AList <ComparatorData> compdata = testdata.GetComparatorData(); foreach (ComparatorData cd in compdata) { string comptype = cd.GetComparatorType(); bool compareOutput = false; if (!Runtime.EqualsIgnoreCase(comptype, "none")) { compareOutput = CompareTestOutput(cd, cmdResult); overallTCResult &= compareOutput; } cd.SetExitCode(cmdResult.GetExitCode()); cd.SetActualOutput(cmdResult.GetCommandOutput()); cd.SetTestResult(compareOutput); } testdata.SetTestResult(overallTCResult); // Execute the cleanup commands AList <CLICommand> cleanupCommands = testdata.GetCleanupCommands(); foreach (CLICommand cmd_1 in cleanupCommands) { try { Execute(cmd_1); } catch (Exception e) { NUnit.Framework.Assert.Fail(StringUtils.StringifyException(e)); } } } }
public virtual void TestDfsAdminCmd() { cluster = new MiniDFSCluster.Builder(config).NumDataNodes(2).ManageNameDfsDirs(false ).Build(); cluster.WaitActive(); try { FSImage fsi = cluster.GetNameNode().GetFSImage(); // it is started with dfs.namenode.name.dir.restore set to true (in SetUp()) bool restore = fsi.GetStorage().GetRestoreFailedStorage(); Log.Info("Restore is " + restore); NUnit.Framework.Assert.AreEqual(restore, true); // now run DFSAdmnin command string cmd = "-fs NAMENODE -restoreFailedStorage false"; string namenode = config.Get(DFSConfigKeys.FsDefaultNameKey, "file:///"); CommandExecutor executor = new CLITestCmdDFS(cmd, new CLICommandDFSAdmin()).GetExecutor (namenode); executor.ExecuteCommand(cmd); restore = fsi.GetStorage().GetRestoreFailedStorage(); NUnit.Framework.Assert.IsFalse("After set true call restore is " + restore, restore ); // run one more time - to set it to true again cmd = "-fs NAMENODE -restoreFailedStorage true"; executor.ExecuteCommand(cmd); restore = fsi.GetStorage().GetRestoreFailedStorage(); NUnit.Framework.Assert.IsTrue("After set false call restore is " + restore, restore ); // run one more time - no change in value cmd = "-fs NAMENODE -restoreFailedStorage check"; CommandExecutor.Result cmdResult = executor.ExecuteCommand(cmd); restore = fsi.GetStorage().GetRestoreFailedStorage(); NUnit.Framework.Assert.IsTrue("After check call restore is " + restore, restore); string commandOutput = cmdResult.GetCommandOutput(); commandOutput.Trim(); NUnit.Framework.Assert.IsTrue(commandOutput.Contains("restoreFailedStorage is set to true" )); } finally { cluster.Shutdown(); } }