You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2016/11/28 13:48:40 UTC
ignite git commit: IGNITE-3169 .NET: Provide error messages for
incorrect Apache.Ignite.exe command line arguments
Repository: ignite
Updated Branches:
refs/heads/master 0139ed50c -> ca1644468
IGNITE-3169 .NET: Provide error messages for incorrect Apache.Ignite.exe command line arguments
This closes #1287
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ca164446
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ca164446
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ca164446
Branch: refs/heads/master
Commit: ca164446830067fa2204022fe1efd8899367b2da
Parents: 0139ed5
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Mon Nov 28 16:48:26 2016 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Mon Nov 28 16:48:26 2016 +0300
----------------------------------------------------------------------
.../Apache.Ignite.Core.Tests/ExecutableTest.cs | 64 +++++++++++++++++++-
.../Apache.Ignite/Config/ArgsConfigurator.cs | 7 +--
.../dotnet/Apache.Ignite/Config/Configurator.cs | 10 +++
3 files changed, 76 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/ca164446/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
index 299c987..3b24b2e 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/ExecutableTest.cs
@@ -23,6 +23,7 @@ namespace Apache.Ignite.Core.Tests
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
+ using System.Linq;
using Apache.Ignite.Core.Binary;
using Apache.Ignite.Core.Compute;
using Apache.Ignite.Core.Impl;
@@ -309,6 +310,55 @@ namespace Apache.Ignite.Core.Tests
}
/// <summary>
+ /// Tests invalid command arguments.
+ /// </summary>
+ [Test]
+ public void TestInvalidCmdArgs()
+ {
+ Action<string, string> checkError = (args, err) =>
+ {
+ var reader = new ListDataReader();
+ var proc = new IgniteProcess(reader, args);
+
+ int exitCode;
+ Assert.IsTrue(proc.Join(3000, out exitCode));
+ Assert.AreEqual(-1, exitCode);
+
+ lock (reader.List)
+ {
+ Assert.AreEqual(err, reader.List.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)));
+ }
+ };
+
+ checkError("blabla", "ERROR: Apache.Ignite.Core.Common.IgniteException: Missing argument value: " +
+ "'blabla'. See 'Apache.Ignite.exe /help'");
+
+ checkError("blabla=foo", "ERROR: Apache.Ignite.Core.Common.IgniteException: " +
+ "Unknown argument: 'blabla'. See 'Apache.Ignite.exe /help'");
+
+ checkError("assembly=", "ERROR: Apache.Ignite.Core.Common.IgniteException: Missing argument value: " +
+ "'assembly'. See 'Apache.Ignite.exe /help'");
+
+ checkError("assembly=x.dll", "ERROR: Apache.Ignite.Core.Common.IgniteException: " +
+ "Failed to load assembly: x.dll");
+
+ checkError("configFileName=wrong.config", "ERROR: System.Configuration.ConfigurationErrorsException: " +
+ "Specified config file does not exist: wrong.config");
+
+ checkError("configSectionName=wrongSection", "ERROR: System.Configuration.ConfigurationErrorsException: " +
+ "Could not find IgniteConfigurationSection " +
+ "in current application configuration");
+
+ checkError("JvmInitialMemoryMB=A_LOT", "ERROR: System.InvalidOperationException: Failed to configure " +
+ "Ignite: property 'JvmInitialMemoryMB' has value 'A_LOT', " +
+ "which is not an integer.");
+
+ checkError("JvmMaxMemoryMB=ALL_OF_IT", "ERROR: System.InvalidOperationException: Failed to configure " +
+ "Ignite: property 'JvmMaxMemoryMB' has value 'ALL_OF_IT', " +
+ "which is not an integer.");
+ }
+
+ /// <summary>
/// Get remote node configuration.
/// </summary>
/// <returns>Configuration.</returns>
@@ -405,7 +455,7 @@ namespace Apache.Ignite.Core.Tests
public RemoteConfiguration Invoke()
{
- var grid0 = (Ignite) ((IgniteProxy) _grid).Target;
+ var grid0 = ((IgniteProxy) _grid).Target;
var cfg = grid0.Configuration;
@@ -471,7 +521,19 @@ namespace Apache.Ignite.Core.Tests
/// Maximum JVM memory (Xms).
/// </summary>
public int JvmMaxMemoryMb { get; set; }
+ }
+
+ private class ListDataReader : IIgniteProcessOutputReader
+ {
+ public readonly List<string> List = new List<string>();
+ public void OnOutput(System.Diagnostics.Process proc, string data, bool err)
+ {
+ lock (List)
+ {
+ List.Add(data);
+ }
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/ca164446/modules/platforms/dotnet/Apache.Ignite/Config/ArgsConfigurator.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite/Config/ArgsConfigurator.cs b/modules/platforms/dotnet/Apache.Ignite/Config/ArgsConfigurator.cs
index c7dae66..a9fa011 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Config/ArgsConfigurator.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Config/ArgsConfigurator.cs
@@ -32,12 +32,11 @@ namespace Apache.Ignite.Config
public static IEnumerable<Tuple<string, string>> GetArgs(IEnumerable<string> args)
{
return args
- .Select(x => x.TrimStart('-'))
+ .Select(x => x.Trim().TrimStart('-'))
.Select(x => x.StartsWith(Configurator.CmdJvmOpt + "-")
? new[] {Configurator.CmdJvmOpt, x.Substring(Configurator.CmdJvmOpt.Length)}
- : x.Split('='))
- .Where(x => x.Length == 2)
- .Select(x => Tuple.Create(x[0], x[1]));
+ : x.Split(new[] {'='}, 2))
+ .Select(x => Tuple.Create(x[0], x.Length > 1 ? x[1] : string.Empty));
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/ca164446/modules/platforms/dotnet/Apache.Ignite/Config/Configurator.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite/Config/Configurator.cs b/modules/platforms/dotnet/Apache.Ignite/Config/Configurator.cs
index 5f73a6d..785334a 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Config/Configurator.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Config/Configurator.cs
@@ -23,6 +23,7 @@ namespace Apache.Ignite.Config
using System.IO;
using System.Linq;
using Apache.Ignite.Core;
+ using Apache.Ignite.Core.Common;
/// <summary>
/// Configurator which uses arguments array.
@@ -75,6 +76,10 @@ namespace Apache.Ignite.Config
foreach (var arg in args)
{
+ if (string.IsNullOrWhiteSpace(arg.Item2))
+ throw new IgniteException(string.Format(
+ "Missing argument value: '{0}'. See 'Apache.Ignite.exe /help'", arg.Item1));
+
var arg0 = arg; // copy captured variable
Func<string, bool> argIs = x => arg0.Item1.Equals(x, StringComparison.OrdinalIgnoreCase);
@@ -100,6 +105,11 @@ namespace Apache.Ignite.Config
assemblies.Add(arg.Item2);
else if (argIs(CmdForceTestClasspath) && arg.Item2 == "true")
Environment.SetEnvironmentVariable("IGNITE_NATIVE_TEST_CLASSPATH", "true");
+ else if (!argIs(CmdConfigFile) && !argIs(CmdConfigSection))
+ {
+ throw new IgniteException(string.Format(
+ "Unknown argument: '{0}'. See 'Apache.Ignite.exe /help'", arg.Item1));
+ }
}
if (jvmOpts.Count > 0)