Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNTR] Add CLI switches to show help and version number #4925

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/core/Akka.MultiNodeTestRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ class Program
/// </summary>
static void Main(string[] args)
{
// Force load the args
CommandLine.GetPropertyOrDefault("force load", null);
if (CommandLine.ShowHelp)
{
PrintHelp();
return;
}

if (CommandLine.ShowVersion)
{
var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
Console.WriteLine($"Version: {version}");
return;
}

OutputDirectory = CommandLine.GetPropertyOrDefault("multinode.output-directory", string.Empty);
FailedSpecsDirectory = CommandLine.GetPropertyOrDefault("multinode.failed-specs-directory", "FAILED_SPECS_LOGS");

Expand Down Expand Up @@ -522,6 +537,49 @@ private static void PublishToAllSinks(string message)
{
SinkCoordinator.Tell(message, ActorRefs.NoSender);
}

private static void PrintHelp()
{
var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
Console.WriteLine($@"Akka.NET Multi Node Test Runner ({version})
Usage: MultiNodeTestRunner [path-to-test-dll] [runtime-options]

Run a compiled Akka.NET multi node test

runtime-options:
-Dmultinode.output-directory=<path>
Folder where the test report will be exported.
Default value : current working directory.
-Dmultinode.failed-specs-directory=<folder-name>
Folder name inside the output directory where failed test log will be exported, if a test should fail.
Default value : FAILED_SPECS_LOG.
-Dmultinode.loglevel=<debug-level>
Sets the minimum reported log level used within the test.
Valid values : DEBUG, INFO, WARNING, ERROR.
Default value: WARNING.
-Dmultinode.listen-address=<host|ip-address>
The TCP/IP address or host name the multi node test runner should listen for test node reports/logs.
Default value: 127.0.0.1.
-Dmultinode.listen-port=<port>
The TCP/IP port the multi node test runner should listen for test node reports/logs.
Default value: 6577.
-Dmultinode.reporter=<reporter>
The report type this runner should export in. Note that report files are exported to the current directory for trx.
Valid values : trx, teamcity, console.
Default value: console.
-Dmultinode.clear-output=<0|1>
This flag will clear the output folder before any test is run when it is set to 1.
Default value: 0.
-Dmultinode.spec=<spec-name>
Apply a filter to the test class names within the dll. Any fully qualified test class name that contains this string will run.
Default value: (all).
-Dmultinode.include=<filter>
A comma separated list of wildcard pattern to be matched and included in the tests. The filter is applied on the name of the test method.
Default value: * (all).
-Dmultinode.exclude=<filter>
A comma separated list of wildcard pattern to be matched and excluded in the tests. The filter is applied on the name of the test method.
Default value: (none).");
}
}

internal class TcpLoggingServer : ReceiveActor
Expand Down
37 changes: 28 additions & 9 deletions src/core/Akka.Remote.TestKit/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,53 @@ namespace Akka.Remote.TestKit
/// </summary>
public class CommandLine
{
private static readonly Lazy<StringDictionary> Values = new Lazy<StringDictionary>(() =>
private static readonly StringDictionary Values;

static CommandLine()
{
var dictionary = new StringDictionary();
Values = new StringDictionary();
foreach (var arg in Environment.GetCommandLineArgs())
{
if (!arg.StartsWith("-D")) continue;
if (!arg.StartsWith("-D"))
{
var a = arg.Trim().ToLowerInvariant();
if (a.Equals("-h") || a.Equals("--help"))
{
ShowHelp = true;
return;
}
if (a.Equals("-v") || a.Equals("--version"))
{
ShowVersion = true;
return;
}
continue;
}

var tokens = arg.Substring(2).Split('=');

if (tokens.Length == 2)
{
dictionary.Add(tokens[0], tokens[1]);
Values.Add(tokens[0], tokens[1]);
}
else
{
throw new ConfigurationException($"Command line parameter '{arg}' should follow the pattern [-Dmultinode.<key>=<value>].");
}
}
return dictionary;
});
}

public static bool ShowHelp { get; private set; }
public static bool ShowVersion { get; private set; }

public static string GetProperty(string key)
{
return Values.Value[key];
return Values[key];
}

public static string GetPropertyOrDefault(string key, string defaultStr)
{
return Values.Value.ContainsKey(key) ? Values.Value[key] : defaultStr;
return Values.ContainsKey(key) ? Values[key] : defaultStr;
}

public static int GetInt32(string key)
Expand All @@ -64,7 +83,7 @@ public static int GetInt32(string key)

public static int GetInt32OrDefault(string key, int defaultInt)
{
return Values.Value.ContainsKey(key) ? GetInt32(key) : defaultInt;
return Values.ContainsKey(key) ? GetInt32(key) : defaultInt;
}
}
}
Expand Down