/// <exception cref="System.Exception"/> public virtual void TestGenericOptionsParser() { GenericOptionsParser parser = new GenericOptionsParser(new Configuration(), new string [] { "-jt" }); Assert.Equal(0, parser.GetRemainingArgs().Length); // test if -D accepts -Dx=y=z parser = new GenericOptionsParser(new Configuration(), new string[] { "-Dx=y=z" } ); Assert.Equal("Options parser gets entire ='s expresion", "y=z" , parser.GetConfiguration().Get("x")); }
/// <summary> /// Runs the given <code>Tool</code> by /// <see cref="Tool.Run(string[])"/> /// , after /// parsing with the given generic arguments. Uses the given /// <code>Configuration</code>, or builds one if null. /// Sets the <code>Tool</code>'s configuration with the possibly modified /// version of the <code>conf</code>. /// </summary> /// <param name="conf"><code>Configuration</code> for the <code>Tool</code>.</param> /// <param name="tool"><code>Tool</code> to run.</param> /// <param name="args">command-line arguments to the tool.</param> /// <returns> /// exit code of the /// <see cref="Tool.Run(string[])"/> /// method. /// </returns> /// <exception cref="System.Exception"/> public static int Run(Configuration conf, Tool tool, string[] args) { if (conf == null) { conf = new Configuration(); } GenericOptionsParser parser = new GenericOptionsParser(conf, args); //set the configuration back, so that Tool can configure itself tool.SetConf(conf); //get the args w/o generic hadoop args string[] toolArgs = parser.GetRemainingArgs(); return(tool.Run(toolArgs)); }
/// <exception cref="System.Exception"/> private void AssertDOptionParsing(string[] args, IDictionary <string, string> expectedMap , string[] expectedRemainingArgs) { foreach (KeyValuePair <string, string> entry in expectedMap) { NUnit.Framework.Assert.IsNull(conf.Get(entry.Key)); } Configuration conf = new Configuration(); GenericOptionsParser parser = new GenericOptionsParser(conf, args); string[] remainingArgs = parser.GetRemainingArgs(); foreach (KeyValuePair <string, string> entry_1 in expectedMap) { Assert.Equal(entry_1.Value, conf.Get(entry_1.Key)); } Assert.AssertArrayEquals(Arrays.ToString(remainingArgs) + Arrays.ToString(expectedRemainingArgs ), expectedRemainingArgs, remainingArgs); }
/// <summary>Test passing null as args.</summary> /// <remarks> /// Test passing null as args. Some classes still call /// Tool interface from java passing null. /// </remarks> /// <exception cref="System.IO.IOException"/> public virtual void TestNullArgs() { GenericOptionsParser parser = new GenericOptionsParser(conf, null); parser.GetRemainingArgs(); }