Mercurial > stress-tester
changeset 770:fdff2d086ce5
in progress
author | Devel 1 |
---|---|
date | Mon, 18 Dec 2017 11:09:10 +0100 |
parents | 6300f55ac52b |
children | 8bac181dfdfb |
files | stress-tester/src/main/java/com/passus/st/CliHelper.java stress-tester/src/main/java/com/passus/st/CliOptions.java stress-tester/src/main/java/com/passus/st/ConverterMain.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersConfigurator.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpVarsFilter.java stress-tester/src/test/java/com/passus/st/utils/TestHttpUtils.java |
diffstat | 6 files changed, 95 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/CliHelper.java Mon Dec 18 10:08:00 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/CliHelper.java Mon Dec 18 11:09:10 2017 +0100 @@ -10,6 +10,7 @@ import com.passus.st.client.http.HttpClient; import com.passus.st.client.http.filter.HttpFilter; import com.passus.st.client.http.filter.HttpFiltersConfigurator; +import com.passus.st.client.http.filter.HttpVarsFilter; import com.passus.st.emitter.Emitter; import com.passus.st.emitter.PassThroughSessionMapper; import com.passus.st.emitter.RuleBasedSessionMapper; @@ -19,11 +20,9 @@ import com.passus.st.source.EventSource; import com.passus.st.source.NcEventSource; import com.passus.st.source.PcapSessionEventSource; -import com.passus.st.vars.HttpVarsFilter; import java.io.File; import java.io.InputStream; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import org.apache.commons.cli.CommandLine; import static org.apache.commons.io.FileUtils.openInputStream;
--- a/stress-tester/src/main/java/com/passus/st/CliOptions.java Mon Dec 18 10:08:00 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/CliOptions.java Mon Dec 18 11:09:10 2017 +0100 @@ -66,6 +66,12 @@ ); } + public CliOptions addVarsFileOption() { + return addOption(option("vf", "varsFile").desc("Vars file.") + .hasArg().argName("file") + .build()); + } + public CliOptions addHttpPortsOption() { return addOption(option("hp", "httpPorts").desc("Specify HTTP ports in input file (default: 80, 8080)") .hasArg().argName("ports") @@ -75,18 +81,18 @@ public CliOptions addHttpClientOptions() { addHttpFiltersFileOption(); - + addVarsFileOption(); + addOption(option("rs", "replaySpeed").desc("Speedup factor (default 0 - top speed)") .hasArg().argName("speed") .build()); - + addOption(option("wt", "workerType").desc("Worker type: synch|asynch|parallel (default synch).") .hasArg().argName("type") .build() ); - + return addHttpPortsOption(); } - }
--- a/stress-tester/src/main/java/com/passus/st/ConverterMain.java Mon Dec 18 10:08:00 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/ConverterMain.java Mon Dec 18 11:09:10 2017 +0100 @@ -88,6 +88,7 @@ options.addLogLevelOption(); options.addAllowPartialSessionOption(); options.addHttpFiltersFileOption(); + options.addVarsFileOption(); options.addHttpPortsOption(); options.addOption(option("do", "").desc("Destination override ([ask]|yes|no)")
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersConfigurator.java Mon Dec 18 10:08:00 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersConfigurator.java Mon Dec 18 11:09:10 2017 +0100 @@ -6,18 +6,17 @@ import com.passus.config.Configuration; import com.passus.config.ConfigurationContext; import com.passus.config.ConfigurationImpl; +import static com.passus.config.ConfigurationUtils.tupleNodeStringValue; import com.passus.config.Configurator; +import com.passus.config.NodeException; +import com.passus.config.YamlConfigurationReader; import com.passus.config.schema.ConfigurationSchema; import com.passus.config.schema.ConfigurationSchemaImpl; import com.passus.config.validation.Errors; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; -import static com.passus.config.ConfigurationUtils.tupleNodeStringValue; -import com.passus.config.NodeException; -import com.passus.config.YamlConfigurationReader; -import java.io.File; -import java.io.IOException; -import java.util.Collections; /** *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpVarsFilter.java Mon Dec 18 11:09:10 2017 +0100 @@ -0,0 +1,75 @@ +package com.passus.st.client.http.filter; + +import com.passus.commons.Assert; +import com.passus.data.ByteBuff; +import com.passus.data.HeapByteBuff; +import com.passus.net.http.HttpMessageHelper; +import com.passus.net.http.HttpRequest; +import com.passus.net.http.HttpResponse; +import com.passus.st.client.http.HttpFlowContext; +import com.passus.st.client.http.filter.HttpFilter; +import com.passus.st.client.http.filter.HttpMessageWrapper; +import com.passus.st.vars.Var; +import com.passus.st.vars.VarsCompiler; +import com.passus.st.vars.VarsExecutor; +import java.io.IOException; +import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * + * @author Mirosław Hawrot + */ +public class HttpVarsFilter extends HttpFilter { + + private static final Logger LOGGER = LogManager.getLogger(HttpVarsFilter.class); + + private final HttpMessageHelper helper = HttpMessageHelper.get(); + + private final VarsCompiler compiler; + + private final VarsExecutor executor; + + public HttpVarsFilter() { + compiler = new VarsCompiler(); + executor = new VarsExecutor(); + } + + public HttpVarsFilter(VarsCompiler compiler, VarsExecutor executor) { + Assert.notNull(compiler, "compiler"); + Assert.notNull(executor, "executor"); + this.compiler = compiler; + this.executor = executor; + } + + @Override + public HttpFilter instanceForWorker(int index) { + return new HttpVarsFilter(); + } + + @Override + public int filterOutbound(HttpRequest req, HttpResponse resp, HttpFlowContext context) { + //Przetwarzamy tylko requesty, response'a nie ma sensu + if (req != null) { + try { + helper.decodeContent(req, true); + ByteBuff buffer = req.getContentByteBuff(); + if (buffer != null) { + List<Var> vars = compiler.search(buffer); + if (vars != null && !vars.isEmpty()) { + ByteBuff result = new HeapByteBuff(buffer.readableBytes()); + executor.execute(buffer, result, vars, new HttpMessageWrapper(req, resp, context)); + } + } + } catch (IOException e) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(e.getMessage(), e); + } + } + } + + return DUNNO; + } + +}
--- a/stress-tester/src/test/java/com/passus/st/utils/TestHttpUtils.java Mon Dec 18 10:08:00 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/utils/TestHttpUtils.java Mon Dec 18 11:09:10 2017 +0100 @@ -1,5 +1,6 @@ package com.passus.st.utils; +import com.passus.data.DataDecoder; import com.passus.net.http.HttpFullMessageDecoder; import com.passus.net.http.HttpMessage; import com.passus.net.http.HttpRequest; @@ -35,6 +36,7 @@ if (state == HttpFullMessageDecoder.STATE_FINISHED && consumed == bs.length) { return decoder.getResult(); } - throw new IllegalArgumentException(); + throw new IllegalArgumentException("state=" + DataDecoder.stateString(state) + " consumed=" + + consumed + " len=" + bs.length + " error=" + decoder.getLastError()); } }