Mercurial > stress-tester
changeset 1246:e0a246f43a80
upgraded to commons-cli 1.4
author | Devel 1 |
---|---|
date | Wed, 01 Jul 2020 10:06:34 +0200 |
parents | a8494e56ba41 |
children | 1deac0382914 |
files | stress-tester/pom.xml stress-tester/src/main/java/com/passus/st/Main.java stress-tester/src/main/java/com/passus/st/Main2.java stress-tester/src/main/java/com/passus/st/PcapReporter.java stress-tester/src/main/java/com/passus/st/PcapScanner.java stress-tester/src/main/java/com/passus/st/ReaderMain.java stress-tester/src/main/java/com/passus/st/converter/Converter.java |
diffstat | 7 files changed, 42 insertions(+), 168 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/pom.xml Wed Jul 01 09:09:40 2020 +0200 +++ b/stress-tester/pom.xml Wed Jul 01 10:06:34 2020 +0200 @@ -142,7 +142,7 @@ <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli</artifactId> - <version>1.3.1</version> + <version>1.4</version> </dependency> <dependency> <groupId>commons-lang</groupId>
--- a/stress-tester/src/main/java/com/passus/st/Main.java Wed Jul 01 09:09:40 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/Main.java Wed Jul 01 10:06:34 2020 +0200 @@ -44,7 +44,6 @@ System.exit(1); } - private Options createOptions() { CliOptions options = cliHelper.options(); @@ -54,52 +53,20 @@ options.addHttpClientOptions(); options.addLookupsFileOptions(); - options.addOption(option("pr", "parallelReplays").desc("Number of parallel replays. Works only for one pcap file.") - .hasArg().argName("replays") - .build()); - - options.addOption(option("ca", "cache").desc("Cache (and preprocess) input file.") - .hasArg(false) - .build()); - - options.addOption(option("lp", "loops").desc("Loops number (default 1).") - .hasArg().argName("loop") - .build() - ); - - options.addOption(option("rd", "reporterDirectory").desc("Reporter directory.") - .hasArg().argName("ip") - .build() - ); - options.addOption(option("ri", "reporterIp").desc("Reporter ip address.") - .hasArg().argName("ip") - .build() - ); - options.addOption(option("nrt", "numReporterThreads").desc("Number of sending threads. (range 1 - 8, default 2)") - .hasArg().argName("threads") - .build() - ); - + options.addOption(option("pr", "parallelReplays", "Number of parallel replays. Works only for one pcap file.", "replays")); + options.addOption(option("ca", "cache", "Cache (and preprocess) input file.")); + options.addOption(option("lp", "loops", "Loops number (default 1).", "loop")); + options.addOption(option("rd", "reporterDirectory", "Reporter directory.", "ip")); + options.addOption(option("ri", "reporterIp", "Reporter ip address.", "ip")); + options.addOption(option("nrt", "numReporterThreads", "Number of sending threads. (range 1 - 8, default 2)", "threads")); + options.addOption(option("wd", "writeDirectory", "Write HTTP messages to separate files.", "directory")); + options.addOption(option("wdro", "writeDirectoryRequestsOnly", "Write only HTTP requests.")); + options.addOption(option("wm", "writeMetrics", "Write metrics to file.", "file")); options.addOption(option("wf", "writeFile").desc("Write result to file.") .hasArg().argName("file").optionalArg(true) .build() ); - options.addOption(option("wd", "writeDirectory").desc("Write HTTP messages to separate files.") - .hasArg().argName("directory") - .build() - ); - - options.addOption(option("wdro", "writeDirectoryRequestsOnly").desc("Write only HTTP requests.") - .hasArg(false) - .build() - ); - - options.addOption(option("wm", "writeMetrics").desc("Write metrics to file.") - .hasArg().argName("file") - .build() - ); - return options; }
--- a/stress-tester/src/main/java/com/passus/st/Main2.java Wed Jul 01 09:09:40 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/Main2.java Wed Jul 01 10:06:34 2020 +0200 @@ -89,55 +89,18 @@ options.addHttpClientOptions(); options.addLookupsFileOptions(); - options.addOption(option("pr", "parallelReplays").desc("Number of parallel replays. Works only for one pcap file.") - .hasArg().argName("replays") - .build()); - - options.addOption(option("ca", "cache").desc("Cache (and preprocess) input file.") - .hasArg(false) - .build()); - - options.addOption(option("lp", "loops").desc("Loops number (default 1).") - .hasArg().argName("loop") - .build() - ); - - options.addOption(option("wt", "workerType").desc("Worker type: synch|asynch|parallel (default synch).") - .hasArg().argName("type") - .build() - ); - - options.addOption(option("rd", "reporterDirectory").desc("Reporter directory.") - .hasArg().argName("ip") - .build() - ); - options.addOption(option("ri", "reporterIp").desc("Reporter ip address.") - .hasArg().argName("ip") - .build() - ); - options.addOption(option("nrt", "numReporterThreads").desc("Number of sending threads. (range 1 - 8, default 2)") - .hasArg().argName("threads") - .build() - ); - + options.addOption(option("pr", "parallelReplays", "Number of parallel replays. Works only for one pcap file.", "replays")); + options.addOption(option("ca", "cache", "Cache (and preprocess) input file.")); + options.addOption(option("lp", "loops", "Loops number (default 1).", "loop")); + options.addOption(option("wt", "workerType", "Worker type: synch|asynch|parallel (default synch).", "type")); + options.addOption(option("rd", "reporterDirectory", "Reporter directory.", "ip")); + options.addOption(option("ri", "reporterIp", "Reporter ip address.", "ip")); + options.addOption(option("nrt", "numReporterThreads", "Number of sending threads. (range 1 - 8, default 2)", "threads")); + options.addOption(option("wd", "writeDirectory", "Write HTTP messages to separate files.", "directory")); + options.addOption(option("wdro", "writeDirectoryRequestsOnly", "Write only HTTP requests.")); + options.addOption(option("wm", "writeMetrics", "Write metrics to file.", "file")); options.addOption(option("wf", "writeFile").desc("Write result to file.") - .hasArg().argName("file").optionalArg(true) - .build() - ); - - options.addOption(option("wd", "writeDirectory").desc("Write HTTP messages to separate files.") - .hasArg().argName("directory") - .build() - ); - - options.addOption(option("wdro", "writeDirectoryRequestsOnly").desc("Write only HTTP requests.") - .hasArg(false) - .build() - ); - - options.addOption(option("wm", "writeMetrics").desc("Write metrics to file.") - .hasArg().argName("file") - .build() + .hasArg().argName("file").optionalArg(true).build() ); try { @@ -163,7 +126,7 @@ startTime = System.currentTimeMillis(); } }); - + if (cl.hasOption("pr")) { if (clArgs.length != 1) { throw new IllegalArgumentException("Parameter \"parallelReplays\" works only for one pcap file."); @@ -257,7 +220,7 @@ eventSrcs[i] = eventSrc; } - /* if (cl.hasOption("hp")) { + /* if (cl.hasOption("hp")) { for (int i = 0; i < clArgs.length; i++) { PcapSessionEventSource eventSrc = eventSrcs[i]; PortRangeSet portsRanges = eventSrc.getPortsRange(); @@ -269,7 +232,6 @@ } } }*/ - int loops = Integer.parseInt(cl.getOptionValue("lp", "1")); if (loops <= 0) { throw new Exception("Loop should be greater than zero.");
--- a/stress-tester/src/main/java/com/passus/st/PcapReporter.java Wed Jul 01 09:09:40 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/PcapReporter.java Wed Jul 01 10:06:34 2020 +0200 @@ -16,6 +16,7 @@ import com.passus.st.utils.PeriodFormatter; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.logging.log4j.LogManager; @@ -44,26 +45,12 @@ AppUtils.registerAll(); final Options options = new Options(); - options.addOption(option("l", "logLevel").desc("Log level.") - .hasArg().argName("level") - .build() - ); - - options.addOption(option("ps", "allowPartialSession").desc("Allow partial sessions.") - .hasArg(false) - .build() - ); - - options.addOption(option("hp", "httpPorts").desc("Specify HTTP ports in input file (default: 80, 8080)") - .hasArg().argName("ports") - .build() - ); - - options.addOption(option("ri", "reporterIp").desc("Reporter ip address.") - .required() - .hasArg().argName("ip") - .build() - ); + options.addOption(option("l", "logLevel", "Log level.", "level")); + options.addOption(option("ps", "allowPartialSession","Allow partial sessions.")); + options.addOption(option("hp", "httpPorts","Specify HTTP ports in input file (default: 80, 8080)","ports")); + Option ipOption = option("ri", "reporterIp","Reporter ip address.", "ip"); + ipOption.setRequired(true); + options.addOption(ipOption); try { CommandLine cl = new DefaultParser().parse(options, args);
--- a/stress-tester/src/main/java/com/passus/st/PcapScanner.java Wed Jul 01 09:09:40 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/PcapScanner.java Wed Jul 01 10:06:34 2020 +0200 @@ -129,21 +129,10 @@ AppUtils.registerAll(); final Options options = new Options(); - options.addOption(option("l", "logLevel").desc("Log level.") - .hasArg().argName("level") - .build()); - - options.addOption(option("ips", "ignorePartialSession").desc("Ignore partial sessions.") - .hasArg(false) - .build()); - - options.addOption(option("e", "extractor").desc("Extraction expression, default " + DEFAULT_EXTRACTOR) - .hasArg().argName("expression") - .build()); - - options.addOption(option("hp", "httpPorts").desc("Specify HTTP ports in input file (default: 80, 8080)") - .hasArg().argName("ports") - .build()); + options.addOption(option("l", "logLevel", "Log level.", "level")); + options.addOption(option("ips", "ignorePartialSession", "Ignore partial sessions.")); + options.addOption(option("e", "extractor", "Extraction expression, default " + DEFAULT_EXTRACTOR, "expression")); + options.addOption(option("hp", "httpPorts", "Specify HTTP ports in input file (default: 80, 8080)", "ports")); try { CommandLine cl = new DefaultParser().parse(options, args);
--- a/stress-tester/src/main/java/com/passus/st/ReaderMain.java Wed Jul 01 09:09:40 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/ReaderMain.java Wed Jul 01 10:06:34 2020 +0200 @@ -60,35 +60,12 @@ options.addAllowPartialSessionOption(); options.addHttpPortsOption(); - options.addOption(option("f", "filter").desc("Filter out messages.") - .hasArg().argName("filter") - .build() - ); - - options.addOption(option("w", "file").desc("Write output to file.") - .hasArg().argName("file") - .build() - ); - - options.addOption(option("hdc", "httpDecodeContent").desc("Decode HTTP content if needed.") - .hasArg(false) - .build() - ); - - options.addOption(option("hoh", "httpOnlyHeaders").desc("Print only HTTP message headers.") - .hasArg(false) - .build() - ); - - options.addOption(option("hbc", "httpBinaryContent").desc("Print binary HTTP content.") - .hasArg(false) - .build() - ); - - options.addOption(option("c", "count").desc("Exit after printing count events.") - .hasArg().argName("int") - .build() - ); + options.addOption(option("f", "filter", "Filter out messages.", "filter")); + options.addOption(option("w", "file", "Write output to file.", "file")); + options.addOption(option("hdc", "httpDecodeContent", "Decode HTTP content if needed.")); + options.addOption(option("hoh", "httpOnlyHeaders", "Print only HTTP message headers.")); + options.addOption(option("hbc", "httpBinaryContent", "Print binary HTTP content.")); + options.addOption(option("c", "count", "Exit after printing count events.", "int")); return options; }
--- a/stress-tester/src/main/java/com/passus/st/converter/Converter.java Wed Jul 01 09:09:40 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/converter/Converter.java Wed Jul 01 10:06:34 2020 +0200 @@ -42,16 +42,8 @@ options.addLogLevelOption(); options.addAllowPartialSessionOption(); - - options.addOption(option("do", "").desc("Destination override ([ask]|yes|no)") - .hasArg().argName("") - .build() - ); - - options.addOption(option("sr", "save-response").desc("Save only requests (default false).") - .hasArg().argName("") - .build() - ); + options.addOption(option("do", "","Destination override ([ask]|yes|no)","")); + options.addOption(option("sr", "save-response","Save only requests (default false).","")); return options; }