Mercurial > stress-tester
changeset 703:68d12f09c3a1
converter - allowOverwrite
author | Devel 1 |
---|---|
date | Tue, 28 Nov 2017 14:14:01 +0100 |
parents | aa0a94b0469d |
children | b5062e521212 |
files | stress-tester/src/main/java/com/passus/st/ConverterHttpClient.java stress-tester/src/main/java/com/passus/st/ConverterMain.java stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockWriter.java stress-tester/src/main/java/com/passus/st/source/NcEventDestination.java stress-tester/src/test/java/com/passus/st/source/NcEventDestinationTest.java |
diffstat | 5 files changed, 54 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/ConverterHttpClient.java Tue Nov 28 13:30:08 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/ConverterHttpClient.java Tue Nov 28 14:14:01 2017 +0100 @@ -23,12 +23,17 @@ private final HttpFilterChain filterChain = new HttpFilterChain(); private NcEventDestination dst; + private boolean allowOverwrite; private boolean started; public ConverterHttpClient(String ncFile) { this.ncFile = ncFile; } + void setAllowOverwrite(boolean overwrite) { + this.allowOverwrite = overwrite; + } + @Override public boolean isStarted() { return started; @@ -41,7 +46,7 @@ } dst = new NcEventDestination(ncFile); -// dst.setAllowOverride(true); + dst.setAllowOverwrite(allowOverwrite); dst.start(); started = true;
--- a/stress-tester/src/main/java/com/passus/st/ConverterMain.java Tue Nov 28 13:30:08 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/ConverterMain.java Tue Nov 28 14:14:01 2017 +0100 @@ -22,6 +22,17 @@ */ public class ConverterMain { + private boolean askOverwriteIfExists(String output) { + File f = new File(output); + if (f.exists()) { + System.out.format("Destination file '%s' already exists. Overwrite? [y]/n\n", f.getAbsolutePath()); + String line = System.console().readLine(); + char yn = line.length() > 0 ? line.charAt(0) : 'y'; + return yn == 'y' || yn == 'Y'; + } + return true; + } + static void printHelp(Options options) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("[options] <input pcap> <output nc>", "description", options, ""); @@ -35,15 +46,16 @@ .build() ); + options.addOption(option("do", "").desc("Destination override ([ask]|yes|no)") + .hasArg().argName("") + .build() + ); + options.addOption(option("ff", "filtersFile").desc("Filters file.") .hasArg().argName("file") .build() ); -// options.addOption(option("mr", "mapperRule").desc("Session mapper rule.") -// .hasArg().argName("rule") -// .build() -// ); options.addOption(option("ps", "allowPartialSession").desc("Allow partial sessions.") .hasArg(false) .build() @@ -54,27 +66,6 @@ .build() ); -//// options.addOption(option("rs", "replaySpeed").desc("Speedup factor (default 0 - top speed)") -//// .hasArg().argName("speed") -//// .build()); -// -//// 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() @@ -134,11 +125,6 @@ Log4jConfigurationFactory.enableFactory(logLevel); } - // mapper - // emitter - // client - // reporter - // filter file - dostaje w argumencie klienta !!! ConverterHttpClient client = new ConverterHttpClient(output); if (cl.hasOption("ff")) { @@ -155,6 +141,24 @@ System.exit(1); } } + + boolean overwrite; + String overwriteOption = cl.getOptionValue("do", "ask").toLowerCase(); + switch (overwriteOption) { + case "yes": + overwrite = true; + break; + case "ask": + overwrite = askOverwriteIfExists(output); + break; + case "no": + overwrite = false; + break; + default: + throw new ParseException("Invalid override option value: " + overwriteOption); + } + client.setAllowOverwrite(overwrite); + client.start(); PcapSessionEventSource eventSrc = new PcapSessionEventSource();
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockWriter.java Tue Nov 28 13:30:08 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockWriter.java Tue Nov 28 14:14:01 2017 +0100 @@ -41,7 +41,7 @@ private boolean opened; - private boolean allowOverride; + private boolean allowOverwrite; private int bufferSize = DEFAULT_BYTE_BUFFER; @@ -78,12 +78,12 @@ this.path = path; } - public boolean isAllowOverride() { - return allowOverride; + public boolean isAllowOverwrite() { + return allowOverwrite; } - public void setAllowOverride(boolean allowOverride) { - this.allowOverride = allowOverride; + public void setAllowOverwrite(boolean allowOverwrite) { + this.allowOverwrite = allowOverwrite; } public int getMaxSegmentBlocks() { @@ -144,7 +144,7 @@ @Override public void open() throws IOException { try { - StandardOpenOption createOption = allowOverride ? StandardOpenOption.CREATE : StandardOpenOption.CREATE_NEW; + StandardOpenOption createOption = allowOverwrite ? StandardOpenOption.CREATE : StandardOpenOption.CREATE_NEW; ch = FileChannel.open(path, StandardOpenOption.WRITE, createOption); writeHeader(); openSegmentBlock();
--- a/stress-tester/src/main/java/com/passus/st/source/NcEventDestination.java Tue Nov 28 13:30:08 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/source/NcEventDestination.java Tue Nov 28 14:14:01 2017 +0100 @@ -35,7 +35,7 @@ private boolean encodeData = true; - private boolean allowOverride; + private boolean allowOverwrite; public NcEventDestination() { } @@ -69,12 +69,12 @@ this.encodeData = encodeData; } - public boolean isAllowOverride() { - return allowOverride; + public boolean isAllowOverwrite() { + return allowOverwrite; } - public void setAllowOverride(boolean allowOverride) { - this.allowOverride = allowOverride; + public void setAllowOverwrite(boolean allowOverwrite) { + this.allowOverwrite = allowOverwrite; } @Override @@ -85,7 +85,7 @@ try { writer = new NcDataBlockWriter(ncFile); - writer.setAllowOverride(allowOverride); + writer.setAllowOverwrite(allowOverwrite); writer.open(); started = true;
--- a/stress-tester/src/test/java/com/passus/st/source/NcEventDestinationTest.java Tue Nov 28 13:30:08 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/source/NcEventDestinationTest.java Tue Nov 28 14:14:01 2017 +0100 @@ -17,6 +17,8 @@ import java.util.Properties; import static org.testng.AssertJUnit.assertEquals; import org.testng.annotations.Test; +import static com.passus.commons.utils.ResourceUtils.createTmpFile; +import static com.passus.commons.utils.ResourceUtils.createTmpFile; /** *