Mercurial > stress-tester
changeset 519:7178dc5af601
minor refactoring
author | Devel 1 |
---|---|
date | Tue, 22 Aug 2017 15:29:16 +0200 |
parents | 3ca6df6dd9cb |
children | 31fae01b09d6 |
files | stress-tester/src/main/java/com/passus/st/PcapScanner.java stress-tester/src/main/java/com/passus/st/client/http/HttpSynchClientWorker.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilter.java stress-tester/src/test/java/com/passus/st/PcapScannerTest.java |
diffstat | 5 files changed, 30 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/PcapScanner.java Tue Aug 22 15:03:36 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/PcapScanner.java Tue Aug 22 15:29:16 2017 +0200 @@ -22,6 +22,7 @@ public class PcapScanner implements EventHandler { private static final int MOD = 100; + private static final String DEFAULT_EXTRACTOR = "respHdr:Set-Cookie"; private final HashSet<String> values = new HashSet<>(); private final Extractor extractor; @@ -99,8 +100,8 @@ .build() ); - options.addOption(option("e", "extractor").desc("Extraction expression, default resph:Set-Cookie") - .hasArg().argName("message") + options.addOption(option("e", "extractor").desc("Extraction expression, default " + DEFAULT_EXTRACTOR) + .hasArg().argName("expression") .build() ); @@ -124,8 +125,7 @@ port = Integer.parseInt(cl.getOptionValue("hp")); } - final String defaultExtractor = "respHdr:Set-Cookie"; - String extractorSpec = cl.getOptionValue("e", defaultExtractor); + String extractorSpec = cl.getOptionValue("e", DEFAULT_EXTRACTOR); Extractor extractor = createExtractor(extractorSpec); PcapScanner scanner = new PcapScanner(extractor); @@ -149,11 +149,10 @@ return null; } } - + // private static Object msgExtract(HttpMessage event, MessageExtractor me) { // return // } - private static Extractor createExtractor(String spec) throws ParseException { int idx = spec.indexOf(':'); String type;
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpSynchClientWorker.java Tue Aug 22 15:03:36 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpSynchClientWorker.java Tue Aug 22 15:29:16 2017 +0200 @@ -38,6 +38,7 @@ return working; } + @Override protected void closeSession(HttpFlowContext flowContext, boolean remove) { if (flowContext != null) { super.closeSession(flowContext, remove);
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java Tue Aug 22 15:03:36 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java Tue Aug 22 15:29:16 2017 +0200 @@ -5,12 +5,16 @@ import com.passus.config.Configuration; import com.passus.config.annotations.NodeDefinitionCreate; import static com.passus.config.schema.ConfigurationSchemaBuilder.listDef; +import static com.passus.config.schema.ConfigurationSchemaBuilder.mapDef; import static com.passus.config.schema.ConfigurationSchemaBuilder.mixedDef; import static com.passus.config.schema.ConfigurationSchemaBuilder.tupleDef; +import static com.passus.config.schema.ConfigurationSchemaBuilder.valueDef; import com.passus.config.schema.KeyNameVaryListNodeDefinition; import com.passus.config.schema.NodeDefinition; import com.passus.config.schema.NodeDefinitionCreator; import com.passus.data.ByteString; +import com.passus.filter.UnmutableValueExtractor; +import com.passus.filter.ValueExtractor; import com.passus.net.http.HttpMessageHelper; import com.passus.net.http.HttpParameters; import com.passus.net.http.HttpRequest; @@ -19,16 +23,12 @@ import com.passus.st.config.HeaderOperationNodeDefinition; import com.passus.st.plugin.PluginConstants; import com.passus.st.validation.HeaderNameValidator; +import java.text.ParseException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.text.ParseException; -import com.passus.filter.UnmutableValueExtractor; -import com.passus.filter.ValueExtractor; -import static com.passus.config.schema.ConfigurationSchemaBuilder.mapDef; -import static com.passus.config.schema.ConfigurationSchemaBuilder.valueDef; -import java.util.Collections; /** * @@ -45,7 +45,6 @@ public abstract static class Operation { private Operation() { - } public abstract void process(HttpRequest req, HttpResponse resp, HttpFlowContext context); @@ -64,7 +63,7 @@ private static abstract class AbstractRemoveOperation extends Operation { - protected final ValueExtractor extractor; + protected final ValueExtractor nameExtractor; public AbstractRemoveOperation(CharSequence headerName) { this(new UnmutableValueExtractor(ByteString.create(headerName))); @@ -72,16 +71,16 @@ public AbstractRemoveOperation(ValueExtractor extractor) { Assert.notNull(extractor, "extractor"); - this.extractor = extractor; + this.nameExtractor = extractor; } - public ValueExtractor getExtractor() { - return extractor; + public ValueExtractor getNameExtractor() { + return nameExtractor; } @Override public void process(HttpRequest req, HttpResponse resp, HttpFlowContext context) { - CharSequence name = extractValue(extractor, req, resp, context); + CharSequence name = extractValue(nameExtractor, req, resp, context); if (name != null) { doProcess(name, req, resp, context); } @@ -310,7 +309,7 @@ } protected boolean doRemove(HttpParameters params, HttpRequest req, HttpResponse resp, HttpFlowContext context) { - CharSequence name = extractValue(extractor, req, resp, context); + CharSequence name = extractValue(nameExtractor, req, resp, context); if (name != null) { return params.remove(name); }
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilter.java Tue Aug 22 15:03:36 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpScopeModificationFilter.java Tue Aug 22 15:29:16 2017 +0200 @@ -118,7 +118,6 @@ public boolean isCheckValueExists() { return checkValueExists; } - }
--- a/stress-tester/src/test/java/com/passus/st/PcapScannerTest.java Tue Aug 22 15:03:36 2017 +0200 +++ b/stress-tester/src/test/java/com/passus/st/PcapScannerTest.java Tue Aug 22 15:29:16 2017 +0200 @@ -13,16 +13,20 @@ public static void main(String[] args) { String ST = "C:\\Users\\mikolaj.podbielski\\Desktop\\hg\\stress-tester\\stress-tester\\"; PcapScanner.main(ST + "ndiag.pcap"); +// scanAll(); } - @Test - public void testScanAll() throws InterruptedException { - Log4jConfigurationFactory.enableFactory(Level.INFO); - PcapScanner.Extractor extractor = (event) -> event.getResponse().getHeaders().get(HttpHeaders.SET_COOKIE); - PcapScanner scanner = new PcapScanner(extractor); - scanAll(scanner); - System.out.println("\n --== Scanned values:"); - scanner.getValues().forEach(System.out::println); + public static void scanAll() { + try { + Log4jConfigurationFactory.enableFactory(Level.INFO); + PcapScanner.Extractor extractor = (event) -> event.getResponse().getHeaders().get(HttpHeaders.SET_COOKIE); + PcapScanner scanner = new PcapScanner(extractor); + scanAll(scanner); + System.out.println("\n --== Scanned values:"); + scanner.getValues().forEach(System.out::println); + } catch (Exception e) { + e.printStackTrace(System.out); + } } private static void scanAll(PcapScanner scanner) throws InterruptedException {