Mercurial > stress-tester
changeset 783:a4b90beadbe2
ReaderMain new options
author | Devel 2 |
---|---|
date | Wed, 20 Dec 2017 10:29:41 +0100 |
parents | 2ad0c7dbe571 |
children | 263f92f87cbc |
files | stress-tester/src/main/java/com/passus/st/ReaderMain.java |
diffstat | 1 files changed, 83 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/ReaderMain.java Tue Dec 19 15:43:21 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/ReaderMain.java Wed Dec 20 10:29:41 2017 +0100 @@ -1,6 +1,8 @@ package com.passus.st; import com.passus.data.DataSourceUtils; +import com.passus.data.PooledAllocator; +import com.passus.net.http.HttpMessageHelper; import com.passus.net.http.HttpRequest; import com.passus.net.http.HttpRequestEncoder; import com.passus.net.http.HttpResponse; @@ -36,8 +38,18 @@ private final CliHelper cliHelper = new CliHelper(); + private final HttpMessageHelper messageHelper = HttpMessageHelper.get(); + private HttpMessagePredicate filter; + private boolean decodeContent = false; + + private boolean printContent = true; + + private boolean printBinaryContent = false; + + private int count = -1; + private void printHelp(Options options) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("[options] <file>", "description", options, ""); @@ -60,6 +72,26 @@ .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() + ); + return options; } @@ -69,6 +101,13 @@ } private void printEvent(Event event, PrintStream ps) { + if (count != -1) { + count--; + if (count == 0) { + System.exit(0); + } + } + if (event.getType() == SessionStatusEvent.TYPE) { SessionStatusEvent statusEvent = (SessionStatusEvent) event; printSessionInfo(statusEvent.getSessionInfo(), ps); @@ -87,7 +126,19 @@ if (req != null) { try { - HttpRequestEncoder.INSTANCE.encode(req, ps); + HttpRequestEncoder.INSTANCE.encodeHeaders(req, ps); + if (printContent) { + if (!printBinaryContent && messageHelper.hasBinaryContent(req)) { + ps.println("<binary content>"); + } else { + if (decodeContent) { + messageHelper.decodeContent(req, false); + } + + HttpRequestEncoder.INSTANCE.encodeContent(req, ps); + } + } + ps.println(""); } catch (IOException ex) { logger.debug(ex.getMessage(), ex); @@ -98,7 +149,19 @@ if (resp != null) { try { - HttpResponseEncoder.INSTANCE.encode(resp, ps); + HttpResponseEncoder.INSTANCE.encodeHeaders(resp, ps); + if (printContent) { + if (!printBinaryContent && messageHelper.hasBinaryContent(req)) { + ps.println("<binary content>"); + } else { + if (decodeContent) { + messageHelper.decodeContent(resp, false); + } + + HttpResponseEncoder.INSTANCE.encodeContent(resp, ps); + } + } + ps.println(""); } catch (IOException ex) { logger.debug(ex.getMessage(), ex); @@ -111,7 +174,7 @@ private void readNcFile(NcEventSource src, PrintStream ps) throws Exception { src.setParallel(false); - //src.setAllocator(new PooledAllocator(64 * 1024, 100, 0)); + src.setAllocator(new PooledAllocator(64 * 1024, 100, 0)); src.setHandler((event) -> printEvent(event, ps)); try { @@ -168,6 +231,23 @@ } } + decodeContent = cl.hasOption("hdc"); + printContent = !cl.hasOption("hoh"); + printBinaryContent = !cl.hasOption("hbc"); + + if (cl.hasOption("c")) { + String countStr = cl.getOptionValue("c"); + try { + count = Integer.parseInt(countStr); + if (count <= 0) { + cliHelper.printError("Invalid count value '" + countStr + "'. Sould be integer greater than zero."); + } + } catch (Exception e) { + cliHelper.printError("Invalid count value '" + countStr + "'. Sould be integer greater than zero."); + } + + } + try { if (eventSource instanceof NcEventSource) { readNcFile((NcEventSource) eventSource, ps);