Mercurial > stress-tester
changeset 961:21c0c419d112
Refactorization in progress
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/ConverterMain.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/ConverterMain.java Fri May 31 09:12:08 2019 +0200 @@ -1,6 +1,7 @@ package com.passus.st; import com.passus.config.ConfigurationContext; +import com.passus.st.client.FlowFilter; import com.passus.st.client.http.filter.HttpFilter; import com.passus.st.reader.nc.HttpWriteMode; import com.passus.st.source.NcEventDestination; @@ -135,9 +136,9 @@ cliHelper.readLookupsToContext(cl, context); - List<HttpFilter> httpFilters = cliHelper.readFilters(cl, context); - if (httpFilters != null) { - httpFilters.forEach(client::addFilter); + List<FlowFilter> flowFilters = cliHelper.readFilters(cl, context); + if (flowFilters != null) { + flowFilters.forEach(client::addFilter); } client.start();
--- a/stress-tester/src/main/java/com/passus/st/Main.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/Main.java Fri May 31 09:12:08 2019 +0200 @@ -165,9 +165,9 @@ emitter.setSessionMapper(mapper); emitter.setCollectMetrics(true); - List<ClientListener> executorListeners = new ArrayList<>(); - FlowExecutor executor = cliHelper.createFlowExecutor(emitter, cl); - executorListeners.add((request, response, context) -> { + List<ClientListener> flowExecutorListeners = new ArrayList<>(); + FlowExecutor flowExecutor = cliHelper.createFlowExecutor(emitter, cl); + flowExecutorListeners.add((request, response, context) -> { if (startTime == 0) { startTime = System.currentTimeMillis(); } @@ -181,13 +181,13 @@ int parallelReplays = Integer.parseInt(cl.getOptionValue("pr")); if (parallelReplays > 0 && parallelReplays <= 100) { emitter.setMaxThreads(parallelReplays); - executor.setWorkersNum(parallelReplays); + flowExecutor.setWorkersNum(parallelReplays); } else { throw new IllegalArgumentException("Parameter \"parallelReplays\" should be in range 1-100."); } } else { - executor.setWorkersNum(clArgs.length); - executor.setDispatcher(new SourceNameAwareFlowWorkerDispatcher()); + flowExecutor.setWorkersNum(clArgs.length); + flowExecutor.setDispatcher(new SourceNameAwareFlowWorkerDispatcher()); } emitter.start(); @@ -202,7 +202,7 @@ } writerListener.write(Arrays.asList(args).toString()); writerListener.write("\n"); - executorListeners.add(writerListener); + flowExecutorListeners.add(writerListener); } SummaryHttpClientListener summaryListener = null; @@ -213,14 +213,14 @@ dumper.setDecodeContent(true); File directory = dumper.getDirectory(); if (directory.isDirectory() || directory.mkdirs()) { - executorListeners.add(dumper); + flowExecutorListeners.add(dumper); summaryListener = new SummaryHttpClientListener(new File(directory, "summary.txt")); File file = new File(directory, "cmd." + new File(clArgs[0]).getName() + ".txt"); String cmd = String.join(" ", args); try (FileOutputStream fos = new FileOutputStream(file)) { IOUtils.write(cmd, fos); } - executorListeners.add(summaryListener); + flowExecutorListeners.add(summaryListener); } else { throw new Exception("Cannot create directory: " + directory.getAbsolutePath()); } @@ -241,7 +241,7 @@ if (reporterDestination != null) { reporterDestination.start(); Registry.getInstance().add(ReporterDestination.SERVICE_NAME, reporterDestination); - executorListeners.add(reporterDestination); + flowExecutorListeners.add(reporterDestination); collector.addHandler(reporterDestination); } @@ -249,13 +249,13 @@ cliHelper.readLookupsToContext(cl, context); - List<HttpFilter> httpFilters = cliHelper.readHttpClientFilters(cl, context); + List<FlowFilter> httpFilters = cliHelper.readHttpClientFilters(cl, context); if (httpFilters != null) { - httpFilters.forEach(executor::addFilter); + httpFilters.forEach(flowExecutor::addFilter); } - executor.setListener(new MultipleClientListener(executorListeners)); - executor.start(); + flowExecutor.setListener(new MultipleClientListener(flowExecutorListeners)); + flowExecutor.start(); EventSource[] eventSrcs = new EventSource[clArgs.length]; for (int i = 0; i < clArgs.length; i++) { @@ -289,7 +289,7 @@ } collector.register(emitter); - collector.register(executor); + collector.register(flowExecutor); collector.start(); if (cl.hasOption("ca")) { @@ -299,7 +299,7 @@ sourcesName.add(eventSrc.getName()); } - MemoryEventsCache cache = new MemoryEventsCache(executor, sourcesName); + MemoryEventsCache cache = new MemoryEventsCache(flowExecutor, sourcesName); for (int i = 0; i < clArgs.length; i++) { EventSource eventSrc = eventSrcs[i]; eventSrc.setHandler(cache); @@ -311,7 +311,7 @@ } else { for (int i = 0; i < clArgs.length; i++) { EventSource eventSrc = eventSrcs[i]; - eventSrc.setHandler(executor); + eventSrc.setHandler(flowExecutor); eventSrc.setLoops(loops); eventSrc.start(); } @@ -320,7 +320,7 @@ ScheduledExecutorService scheduleExecutor = Executors.newSingleThreadScheduledExecutor(); scheduleExecutor.scheduleAtFixedRate(this::printMetrics, 5, 5, TimeUnit.SECONDS); - executor.join(); + flowExecutor.join(); long endTime = System.currentTimeMillis(); System.out.println("Broadcast finished. Duration " + PeriodFormatter.INSTANCE.reverseTransform(endTime - startTime) + "."); @@ -332,7 +332,7 @@ eventSrcs[i].stop(); } - executor.stop(); + flowExecutor.stop(); emitter.stop(); if (reporterDestination != null) { if (reporterDestination instanceof ReporterRemoteDestination) {
--- a/stress-tester/src/main/java/com/passus/st/Main2.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/Main2.java Fri May 31 09:12:08 2019 +0200 @@ -4,16 +4,8 @@ import com.passus.commons.metric.Metric; import com.passus.commons.service.Registry; import com.passus.config.ConfigurationContext; -import com.passus.st.client.MemoryEventsCache; -import com.passus.st.client.http.DumperHttpClientListener; -import com.passus.st.client.http.HttpClient; -import com.passus.st.client.http.HttpSourceNameAwareClientWorkerDispatcher; -import com.passus.st.client.http.ReporterDestination; -import com.passus.st.client.http.ReporterFileDestination; -import com.passus.st.client.http.ReporterRemoteDestination; -import com.passus.st.client.http.SummaryHttpClientListener; -import com.passus.st.client.http.WriterHttpClientListener; -import com.passus.st.client.http.filter.HttpFilter; +import com.passus.st.client.*; +import com.passus.st.client.http.*; import com.passus.st.emitter.SessionMapper; import com.passus.st.emitter.nio.NioEmitter; import com.passus.st.emitter.nio.NioEmitterWorker2; @@ -21,28 +13,21 @@ import com.passus.st.metric.ScheduledMetricsCollector; import com.passus.st.metric.SummaryMetricsCollectionHandler; import com.passus.st.source.PcapSessionEventSource; -import static com.passus.st.utils.CliUtils.option; import com.passus.st.utils.PeriodFormatter; +import org.apache.commons.cli.*; +import org.apache.commons.io.IOUtils; + import java.io.File; import java.io.FileOutputStream; import java.io.Serializable; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.commons.io.IOUtils; + +import static com.passus.st.utils.CliUtils.option; /** - * * @author Mirosław Hawrot */ public class Main2 { @@ -170,12 +155,14 @@ emitter.setSessionMapper(mapper); emitter.setCollectMetrics(true); - HttpClient client = cliHelper.createFlowExecutor(emitter, cl); - client.addListener((request, response, context) -> { + List<ClientListener> flowExecutorListeners = new ArrayList<>(); + FlowExecutor flowExecutor = cliHelper.createFlowExecutor(emitter, cl); + flowExecutorListeners.add((request, response, context) -> { if (startTime == 0) { startTime = System.currentTimeMillis(); } }); + if (cl.hasOption("pr")) { if (clArgs.length != 1) { throw new IllegalArgumentException("Parameter \"parallelReplays\" works only for one pcap file."); @@ -184,13 +171,13 @@ int parallelReplays = Integer.parseInt(cl.getOptionValue("pr")); if (parallelReplays > 0 && parallelReplays <= 100) { emitter.setMaxThreads(parallelReplays); - client.setWorkersNum(parallelReplays); + flowExecutor.setWorkersNum(parallelReplays); } else { throw new IllegalArgumentException("Parameter \"parallelReplays\" should be in range 1-100."); } } else { - client.setWorkersNum(clArgs.length); - client.setDispatcher(new HttpSourceNameAwareClientWorkerDispatcher()); + flowExecutor.setWorkersNum(clArgs.length); + flowExecutor.setDispatcher(new SourceNameAwareFlowWorkerDispatcher()); } emitter.start(); @@ -205,7 +192,7 @@ } writerListener.write(Arrays.asList(args).toString()); writerListener.write("\n"); - client.addListener(writerListener); + flowExecutorListeners.add(writerListener); } SummaryHttpClientListener summaryListener = null; @@ -216,14 +203,14 @@ dumper.setDecodeContent(true); File directory = dumper.getDirectory(); if (directory.isDirectory() || directory.mkdirs()) { - client.addListener(dumper); + flowExecutorListeners.add(dumper); summaryListener = new SummaryHttpClientListener(new File(directory, "summary.txt")); File file = new File(directory, "cmd." + new File(clArgs[0]).getName() + ".txt"); String cmd = String.join(" ", args); try (FileOutputStream fos = new FileOutputStream(file)) { IOUtils.write(cmd, fos); } - client.addListener(summaryListener); + flowExecutorListeners.add(summaryListener); } else { throw new Exception("Cannot create directory: " + directory.getAbsolutePath()); } @@ -244,7 +231,7 @@ if (reporterDestination != null) { reporterDestination.start(); Registry.getInstance().add(ReporterDestination.SERVICE_NAME, reporterDestination); - client.addListener(reporterDestination); + flowExecutorListeners.add(reporterDestination); collector.addHandler(reporterDestination); } @@ -252,12 +239,12 @@ cliHelper.readLookupsToContext(cl, context); - List<HttpFilter> httpFilters = cliHelper.readHttpClientFilters(cl, context); + List<FlowFilter> httpFilters = cliHelper.readHttpClientFilters(cl, context); if (httpFilters != null) { - httpFilters.forEach(client::addFilter); + httpFilters.forEach(flowExecutor::addFilter); } - client.start(); + flowExecutor.start(); PcapSessionEventSource[] eventSrcs = new PcapSessionEventSource[clArgs.length]; @@ -306,7 +293,7 @@ } collector.register(emitter); - collector.register(client); + collector.register(flowExecutor); collector.start(); if (cl.hasOption("ca")) { @@ -316,7 +303,7 @@ sourcesName.add(eventSrc.getName()); } - MemoryEventsCache cache = new MemoryEventsCache(client, sourcesName); + MemoryEventsCache cache = new MemoryEventsCache(flowExecutor, sourcesName); for (int i = 0; i < clArgs.length; i++) { PcapSessionEventSource eventSrc = eventSrcs[i]; eventSrc.setHandler(cache); @@ -328,7 +315,7 @@ } else { for (int i = 0; i < clArgs.length; i++) { PcapSessionEventSource eventSrc = eventSrcs[i]; - eventSrc.setHandler(client); + eventSrc.setHandler(flowExecutor); eventSrc.setLoops(loops); eventSrc.start(); } @@ -337,7 +324,8 @@ ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); executor.scheduleAtFixedRate(this::printMetrics, 5, 5, TimeUnit.SECONDS); - client.join(); + flowExecutor.setListener(new MultipleClientListener(flowExecutorListeners)); + flowExecutor.join(); long endTime = System.currentTimeMillis(); System.out.println("Broadcast finished. Duration " + PeriodFormatter.INSTANCE.reverseTransform(endTime - startTime) + "."); @@ -349,7 +337,7 @@ eventSrcs[i].stop(); } - client.stop(); + flowExecutor.stop(); emitter.stop(); if (reporterDestination != null) {
--- a/stress-tester/src/main/java/com/passus/st/client/AbstractFlow.java Thu May 30 14:55:34 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -package com.passus.st.client; - -import com.passus.commons.Assert; -import com.passus.st.emitter.Emitter; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public abstract class AbstractFlow implements Flow { - - protected final Logger logger = LogManager.getLogger(getClass()); - - private static final boolean DEFAULT_COLLECT_METRICS = false; - - protected Emitter emitter; - - private final List<ClientListener> listeners = new ArrayList<>(); - - private FlowFilterChain filterChain = new FlowFilterChain(); - - private boolean collectMetrics = DEFAULT_COLLECT_METRICS; - - protected ClientX client; - - @Override - public ClientX getClient() { - return client; - } - - @Override - public void setClient(ClientX client) { - this.client = client; - } - - @Override - public Emitter getEmitter() { - return emitter; - } - - @Override - public void setEmitter(Emitter emitter) { - this.emitter = emitter; - } - - @Override - public void setListeners(Collection<ClientListener> listeners) { - Assert.notContainsNull(listeners, "listeners"); - this.listeners.addAll(listeners); - } - - @Override - public void addListener(ClientListener listener) { - Assert.notNull(listener, "listener"); - listeners.add(listener); - } - - @Override - public void removeListener(ClientListener listener) { - Assert.notNull(listener, "listener"); - listeners.remove(listener); - } - - @Override - public List<ClientListener> getListeners() { - return Collections.unmodifiableList(listeners); - } - - @Override - public List<FlowFilter> getFilters() { - return filterChain.getFilters(); - } - - @Override - public void addFilter(FlowFilter filter) { - Assert.notNull(filter, "filter"); - filterChain.addFilter(filter); - } - - @Override - public void setFilters(Collection<FlowFilter> filters) { - Assert.notContainsNull(filters, "filters"); - filterChain.clear(); - filters.forEach((filter) -> filterChain.addFilter(filter)); - } - - @Override - public boolean isCollectMetrics() { - return collectMetrics; - } - - @Override - public void setCollectMetrics(boolean collectMetrics) { - this.collectMetrics = collectMetrics; - } -}
--- a/stress-tester/src/main/java/com/passus/st/client/FlowBased.java Thu May 30 14:55:34 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -package com.passus.st.client; - -public abstract class FlowBased extends AbstractFlow { -}
--- a/stress-tester/src/main/java/com/passus/st/client/FlowExecutor.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/FlowExecutor.java Fri May 31 09:12:08 2019 +0200 @@ -329,7 +329,7 @@ } - public static class HttpClientNodeDefCreator implements NodeDefinitionCreator { + public static class FlowExecutorNodeDefCreator implements NodeDefinitionCreator { private static final Set<String> DISPATCHERS = new HashSet<>(Arrays.asList( "source", "parallel"
--- a/stress-tester/src/main/java/com/passus/st/client/http/DumperHttpClientListener.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/DumperHttpClientListener.java Fri May 31 09:12:08 2019 +0200 @@ -28,7 +28,7 @@ * @author mikolaj.podbielski */ @NodeDefinitionCreate(DumperHttpClientListener.DumperHttpClientListenerNodeDefCreator.class) -@Plugin(name = DumperHttpClientListener.TYPE, category = PluginConstants.CATEGORY_HTTP_CLIENT_LISTENER) +@Plugin(name = DumperHttpClientListener.TYPE, category = PluginConstants.CATEGORY_CLIENT_LISTENER) public class DumperHttpClientListener implements HttpClientListener, Configurable { public static final String TYPE = "dumper";
--- a/stress-tester/src/main/java/com/passus/st/client/http/StdoutHttpClientListener.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/StdoutHttpClientListener.java Fri May 31 09:12:08 2019 +0200 @@ -9,7 +9,7 @@ /** * @author Mirosław Hawrot */ -@Plugin(name = StdoutHttpClientListener.TYPE, category = PluginConstants.CATEGORY_HTTP_CLIENT_LISTENER) +@Plugin(name = StdoutHttpClientListener.TYPE, category = PluginConstants.CATEGORY_CLIENT_LISTENER) public class StdoutHttpClientListener extends WriterHttpClientListener { public static final String TYPE = "stdout";
--- a/stress-tester/src/main/java/com/passus/st/client/http/SummaryHttpClientListener.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/SummaryHttpClientListener.java Fri May 31 09:12:08 2019 +0200 @@ -18,12 +18,12 @@ import java.io.*; import static com.passus.config.schema.ConfigurationSchemaBuilder.*; -import static com.passus.st.plugin.PluginConstants.CATEGORY_HTTP_CLIENT_LISTENER; +import static com.passus.st.plugin.PluginConstants.CATEGORY_CLIENT_LISTENER; /** * @author mikolaj.podbielski */ -@Plugin(name = SummaryHttpClientListener.TYPE, category = CATEGORY_HTTP_CLIENT_LISTENER) +@Plugin(name = SummaryHttpClientListener.TYPE, category = CATEGORY_CLIENT_LISTENER) public final class SummaryHttpClientListener implements HttpClientListener, Closeable, Configurable { private static final Logger LOGGER = LogManager.getLogger(SummaryHttpClientListener.class);
--- a/stress-tester/src/main/java/com/passus/st/job/JobExecutor.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/job/JobExecutor.java Fri May 31 09:12:08 2019 +0200 @@ -3,8 +3,8 @@ import com.passus.commons.Assert; import com.passus.commons.metric.MetricsCollection; import com.passus.commons.utils.StringUtils; +import com.passus.st.client.FlowExecutor; import com.passus.st.client.MemoryEventsCache; -import com.passus.st.client.http.HttpClient; import com.passus.st.emitter.nio.NioEmitter; import com.passus.st.metric.ScheduledMetricsCollector; import com.passus.st.project.Project; @@ -166,7 +166,7 @@ private Set<PcapSessionEventSource> eventSrcs; - private HttpClient httpClient; + private FlowExecutor flowExecutor; private NioEmitter emitter; @@ -182,7 +182,7 @@ context.setStatus(JobStatus.WAITING); } - private void configureFilters(Project project, HttpClient client) { + private void configureFilters(Project project, FlowExecutor flowExecutor) { /*List<FilterSettings> filtersSettings = project.getHttpFiltersSettings(); if (filtersSettings.isEmpty()) { return; @@ -238,27 +238,27 @@ emitter.setSessionMapper(mapper); emitter.setCollectMetrics(true); - httpClient = new HttpClient(emitter); - httpClient.setCollectMetrics(true); - httpClient.setConnectPartialSession(project.isAllowPartialSessions()); - httpClient.setWokerType(project.getWorkerType().toString()); - configureFilters(project, httpClient); + flowExecutor = new HttpClient(emitter); + flowExecutor.setCollectMetrics(true); + flowExecutor.setConnectPartialSession(project.isAllowPartialSessions()); + flowExecutor.setWokerType(project.getWorkerType().toString()); + configureFilters(project, flowExecutor); if (project.getParallelReplays() != null) { if (pcapFiles.size() != 1) { throw new IllegalArgumentException("Parameter \"parallelReplays\" works only for one pcap file."); } - httpClient.setWorkersNum(project.getParallelReplays()); + flowExecutor.setWorkersNum(project.getParallelReplays()); } else { - httpClient.setWorkersNum(pcapFiles.size()); - httpClient.setDispatcher(new HttpSourceNameAwareClientWorkerDispatcher()); + flowExecutor.setWorkersNum(pcapFiles.size()); + flowExecutor.setDispatcher(new HttpSourceNameAwareClientWorkerDispatcher()); } if (project.getReplaySpeed() > 0) { float speed = project.getReplaySpeed(); if (speed > .1f && speed < 100f) { - httpClient.setSleepFactor(1f / speed); + flowExecutor.setSleepFactor(1f / speed); } } eventSrcs = new HashSet<>(); @@ -279,7 +279,7 @@ sourcesName.add(eventSrc.getName()); }); - cache = new MemoryEventsCache(httpClient, sourcesName); + cache = new MemoryEventsCache(flowExecutor, sourcesName); eventSrcs.forEach((eventSrc) -> { eventSrc.setHandler(cache); }); @@ -288,7 +288,7 @@ } else { eventSrcs.forEach((eventSrc) -> { - eventSrc.setHandler(httpClient); + eventSrc.setHandler(flowExecutor); eventSrc.setLoops(project.getLoops()); }); } @@ -298,7 +298,7 @@ }); metricsCollector.register(emitter); - metricsCollector.register(httpClient); + metricsCollector.register(flowExecutor); metricsCollector.addHandler((mc) -> { fireJobMetrics(context, mc); }); @@ -309,7 +309,7 @@ ReporterFileDestination reporterDestination = new ReporterFileDestination(projectDataDir); Registry.getInstance().add(ReporterDestination.SERVICE_NAME, reporterDestination); - httpClient.addListener(reporterDestination); + flowExecutor.addListener(reporterDestination); metricsCollector.addHandler(reporterDestination); if (project.isSnmpEnabled() && project.getSnmpHost() != null) { @@ -363,7 +363,7 @@ } try { - httpClient.stop(); + flowExecutor.stop(); } catch (Exception e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); @@ -410,7 +410,7 @@ try { metricsCollector.start(); emitter.start(); - httpClient.start(); + flowExecutor.start(); eventSrcs.forEach(PcapSessionEventSource::start); changeStatus(JobStatus.RUNNING); @@ -429,7 +429,7 @@ } try { - httpClient.join(); + flowExecutor.join(); } catch (Exception ignore) { }
--- a/stress-tester/src/main/java/com/passus/st/job/TestJob.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/job/TestJob.java Fri May 31 09:12:08 2019 +0200 @@ -4,8 +4,9 @@ import com.passus.config.ConfigurationContext; import com.passus.filter.ValueExtractor; import com.passus.st.client.Client; +import com.passus.st.client.ClientListener; +import com.passus.st.client.FlowExecutor; import com.passus.st.client.http.HttpClient; -import com.passus.st.client.http.HttpClientListener; import com.passus.st.client.http.HttpSourceNameAwareClientWorkerDispatcher; import com.passus.st.client.http.ReporterDestination; import com.passus.st.client.http.filter.HttpFilter; @@ -36,6 +37,8 @@ private List<EventSource> eventSources = new ArrayList<>(); + private FlowExecutor flowExecutor = new FlowExecutor(); + private List<Client> clients = new ArrayList<>(); private List<Emitter> emitters = new ArrayList<>(); @@ -44,7 +47,7 @@ private Emitter defaultEmitter; - private List<HttpClientListener> httpClientListener; + private List<ClientListener> clientListener; private MetricsCollector metricsCollector; @@ -93,14 +96,14 @@ metricsCollector.start(); } emitters.forEach(Emitter::start); - clients.forEach(Client::start); + flowExecutor.start(); eventSources.forEach(EventSource::start); } @Override public void stop() { eventSources.forEach(EventSource::stop); - clients.forEach(Client::stop); + flowExecutor.stop(); emitters.forEach(Emitter::stop); reporterDestinations.forEach(ReporterDestination::stop); @@ -111,9 +114,7 @@ } public void join() throws InterruptedException { - for (Client client : clients) { - client.join(); - } + flowExecutor.join(); } private static <T> void populateIfNotNull(Collection<T> srcCollection, Collection<T> dstCollection) { @@ -169,10 +170,10 @@ client.setEmitter(defaultEmitter); } - if (httpClientListener != null - && !httpClientListener.isEmpty() + if (clientListener != null + && !clientListener.isEmpty() && client instanceof HttpClient) { - httpClientListener.forEach(((HttpClient) client)::addListener); + clientListener.forEach(((HttpClient) client)::addListener); } if (metricsCollector != null) {
--- a/stress-tester/src/main/java/com/passus/st/job/TestJobBuilder.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/main/java/com/passus/st/job/TestJobBuilder.java Fri May 31 09:12:08 2019 +0200 @@ -5,6 +5,7 @@ import com.passus.config.validation.Errors; import com.passus.st.Builder; import com.passus.st.client.Client; +import com.passus.st.client.FlowExecutor; import com.passus.st.client.http.HttpClient; import com.passus.st.client.http.HttpClientListener; import com.passus.st.client.http.ReporterDestination; @@ -123,17 +124,17 @@ return eventSource; } - public static HttpClient createHttpClient() { - return createHttpClient(null, null); + public static FlowExecutor createFlowExecutor() { + return createFlowExecutor(null, null); } - public static HttpClient createHttpClient(Configuration config, ConfigurationContext context) { - HttpClient client = new HttpClient(); - if (client != null) { - client.configure(config, context); + public static FlowExecutor createFlowExecutor(Configuration config, ConfigurationContext context) { + FlowExecutor flowExecutor = new FlowExecutor(); + if (flowExecutor != null) { + flowExecutor.configure(config, context); } - return client; + return flowExecutor; } public MetricsCollector metricsCollector() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/test/java/com/passus/st/client/FlowExecutorTest.java Fri May 31 09:12:08 2019 +0200 @@ -0,0 +1,150 @@ +package com.passus.st.client; + +import com.passus.commons.service.ServiceUtils; +import com.passus.st.AbstractWireMockTest; +import com.passus.st.emitter.RuleBasedSessionMapper; +import com.passus.st.emitter.nio.NioEmitter; +import com.passus.st.utils.EventUtils; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertTrue; + +public class FlowExecutorTest extends AbstractWireMockTest { + + + private NioEmitter prepareEmitter(String mapperRule) throws Exception { + RuleBasedSessionMapper sessionMapper = new RuleBasedSessionMapper(); + sessionMapper.addRule(mapperRule); + + NioEmitter emitter = new NioEmitter(); + emitter.setSessionMapper(sessionMapper); + return emitter; + } + + @BeforeMethod + public void beforeMethod() { + String content = "test"; + stubFor(post(urlEqualTo("/bskonl/transfers/anytransfer/newtransfer.html")) + .willReturn(aResponse() + .withHeader("Content-Type", "text/plain") + .withHeader("Content-Length", "" + content.length()) + .withBody(content))); + } + + @Test + public void testHandle_HTTP() throws Exception { + Properties props = new Properties(); + props.put("allowPartialSession", "true"); + props.put("ports", "4214"); + List<Event> events = EventUtils.readEvents("pcap/http/http_req_resp.pcap", props); + assertEquals(4, events.size()); + + NioEmitter emitter = prepareEmitter("10.87.110.40:4214 -> " + HOST + ":" + port()); + emitter.start(); + TestHttpClientListener listener = new TestHttpClientListener(); + + FlowExecutor flowExecutor = new FlowExecutor(); + flowExecutor.setEmitter(emitter); + try { + flowExecutor.setListener(listener); + flowExecutor.start(); + + SessionEvent sessionEvent = (SessionEvent) events.get(0); + flowExecutor.handle(new SessionStatusEvent(sessionEvent.getSessionInfo(), SessionStatusEvent.STATUS_ESTABLISHED)); + events.forEach(flowExecutor::handle); + + flowExecutor.join(); + assertTrue(listener.size() > 0); + assertTrue(listener.get(0) instanceof TestHttpClientListener.ResponseReceivedEvent); + TestHttpClientListener.ResponseReceivedEvent event = (TestHttpClientListener.ResponseReceivedEvent) listener.get(0); + String responseStr = event.getResponse().toString(); + assertTrue(responseStr.startsWith("HTTP/1.1 200 OK")); + assertTrue(responseStr.endsWith("test")); + } finally { + ServiceUtils.stopQuietly(flowExecutor); + ServiceUtils.stopQuietly(emitter); + } + } + + @Test + public void testHandle_HTTP_ConnectPartialSession() throws Exception { + Properties props = new Properties(); + props.put("allowPartialSession", "true"); + props.put("ports", "4214"); + List<Event> events = EventUtils.readEvents("pcap/http/http_req_resp.pcap", props); + + NioEmitter emitter = prepareEmitter("10.87.110.40:4214 -> " + HOST + ":" + port()); + emitter.start(); + + FlowExecutor flowExecutor = new FlowExecutor(); + flowExecutor.setEmitter(emitter); + try { + TestHttpClientListener listener = new TestHttpClientListener(); + flowExecutor.setConnectPartialSession(true); + flowExecutor.setListener(listener); + flowExecutor.start(); + + events.forEach(flowExecutor::handle); + + flowExecutor.join(); + + assertTrue(listener.size() > 0); + assertTrue(listener.get(0) instanceof TestHttpClientListener.ResponseReceivedEvent); + } finally { + ServiceUtils.stopQuietly(flowExecutor); + ServiceUtils.stopQuietly(emitter); + } + } + + @Test + public void testHandle_HTTP_ThreeLoops() throws Exception { + Properties props = new Properties(); + props.put("allowPartialSession", "true"); + props.put("ports", "4214"); + LinkedList<Event> events = new LinkedList<>(EventUtils.readEvents("pcap/http/http_req_resp.pcap", props)); + assertEquals(4, events.size()); + Event dataEnd = events.removeLast(); //Usuwamy DataEnd + + SessionEvent sessionEvent = (SessionEvent) events.get(0); + events.addFirst(new SessionStatusEvent(sessionEvent.getSessionInfo(), SessionStatusEvent.STATUS_ESTABLISHED)); + + NioEmitter emitter = prepareEmitter("10.87.110.40:4214 -> " + HOST + ":" + port()); + emitter.start(); + TestHttpClientListener listener = new TestHttpClientListener(); + + FlowExecutor flowExecutor = new FlowExecutor(); + flowExecutor.setEmitter(emitter); + try { + flowExecutor.setListener(listener); + flowExecutor.start(); + + for (int i = 0; i < 3; i++) { + events.forEach(flowExecutor::handle); + } + flowExecutor.handle(dataEnd); + flowExecutor.join(); + + assertEquals(3, listener.size()); + + for (int i = 0; i < 3; i++) { + assertTrue(listener.get(i) instanceof TestHttpClientListener.ResponseReceivedEvent); + TestHttpClientListener.ResponseReceivedEvent event = (TestHttpClientListener.ResponseReceivedEvent) listener.get(i); + String responseStr = event.getResponse().toString(); + assertTrue(responseStr.startsWith("HTTP/1.1 200 OK")); + assertTrue(responseStr.endsWith("test")); + //assertEquals(i, event.getFlowParameters().getLoop()); + } + } finally { + ServiceUtils.stopQuietly(flowExecutor); + ServiceUtils.stopQuietly(emitter); + } + } + +} \ No newline at end of file
--- a/stress-tester/src/test/java/com/passus/st/client/http/HttpClientTest.java Thu May 30 14:55:34 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,154 +0,0 @@ -package com.passus.st.client.http; - -import com.passus.commons.service.ServiceUtils; -import com.passus.st.AbstractWireMockTest; -import com.passus.st.client.Event; -import com.passus.st.client.SessionEvent; -import com.passus.st.client.SessionStatusEvent; -import com.passus.st.client.TestHttpClientListener; -import com.passus.st.client.TestHttpClientListener.ResponseReceivedEvent; -import com.passus.st.emitter.RuleBasedSessionMapper; -import com.passus.st.emitter.nio.NioEmitter; -import com.passus.st.utils.EventUtils; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.LinkedList; -import java.util.List; -import java.util.Properties; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertTrue; - -/** - * - * @author Mirosław Hawrot - */ -public class HttpClientTest extends AbstractWireMockTest { - - private NioEmitter prepareEmitter(String mapperRule) throws Exception { - RuleBasedSessionMapper sessionMapper = new RuleBasedSessionMapper(); - sessionMapper.addRule(mapperRule); - - NioEmitter emitter = new NioEmitter(); - emitter.setSessionMapper(sessionMapper); - return emitter; - } - - @BeforeMethod - public void beforeMethod() { - String content = "test"; - stubFor(post(urlEqualTo("/bskonl/transfers/anytransfer/newtransfer.html")) - .willReturn(aResponse() - .withHeader("Content-Type", "text/plain") - .withHeader("Content-Length", "" + content.length()) - .withBody(content))); - } - - @Test(enabled = false) - public void testHandle() throws Exception { - Properties props = new Properties(); - props.put("allowPartialSession", "true"); - props.put("ports", "4214"); - List<Event> events = EventUtils.readEvents("pcap/http/http_req_resp.pcap", props); - assertEquals(4, events.size()); - - NioEmitter emitter = prepareEmitter("10.87.110.40:4214 -> " + HOST + ":" + port()); - emitter.start(); - TestHttpClientListener listner = new TestHttpClientListener(); - - HttpClient client = new HttpClient(emitter); - try { - client.addListener(listner); - client.start(); - - SessionEvent sessionEvent = (SessionEvent) events.get(0); - client.handle(new SessionStatusEvent(sessionEvent.getSessionInfo(), SessionStatusEvent.STATUS_ESTABLISHED)); - events.forEach(client::handle); - - client.join(); - assertTrue(listner.size() > 0); - assertTrue(listner.get(0) instanceof ResponseReceivedEvent); - ResponseReceivedEvent event = (ResponseReceivedEvent) listner.get(0); - String responseStr = event.getResponse().toString(); - assertTrue(responseStr.startsWith("HTTP/1.1 200 OK")); - assertTrue(responseStr.endsWith("test")); - } finally { - ServiceUtils.stopQuietly(client); - ServiceUtils.stopQuietly(emitter); - } - } - - @Test(enabled = false) - public void testHandle_ConnectPartialSession() throws Exception { - Properties props = new Properties(); - props.put("allowPartialSession", "true"); - props.put("ports", "4214"); - List<Event> events = EventUtils.readEvents("pcap/http/http_req_resp.pcap", props); - - NioEmitter emitter = prepareEmitter("10.87.110.40:4214 -> " + HOST + ":" + port()); - emitter.start(); - - HttpClient client = new HttpClient(emitter); - try { - TestHttpClientListener listner = new TestHttpClientListener(); - client.setConnectPartialSession(true); - client.addListener(listner); - client.start(); - - events.forEach(client::handle); - - client.join(); - - assertTrue(listner.size() > 0); - assertTrue(listner.get(0) instanceof ResponseReceivedEvent); - } finally { - ServiceUtils.stopQuietly(client); - ServiceUtils.stopQuietly(emitter); - } - } - - @Test(enabled = false) - public void testHandle_ThreeLoops() throws Exception { - Properties props = new Properties(); - props.put("allowPartialSession", "true"); - props.put("ports", "4214"); - LinkedList<Event> events = new LinkedList<>(EventUtils.readEvents("pcap/http/http_req_resp.pcap", props)); - assertEquals(4, events.size()); - Event dataEnd = events.removeLast(); //Usuwamy DataEnd - - SessionEvent sessionEvent = (SessionEvent) events.get(0); - events.addFirst(new SessionStatusEvent(sessionEvent.getSessionInfo(), SessionStatusEvent.STATUS_ESTABLISHED)); - - NioEmitter emitter = prepareEmitter("10.87.110.40:4214 -> " + HOST + ":" + port()); - emitter.start(); - TestHttpClientListener listener = new TestHttpClientListener(); - - HttpClient client = new HttpClient(emitter); - try { - client.addListener(listener); - client.start(); - - for (int i = 0; i < 3; i++) { - events.forEach(client::handle); - } - client.handle(dataEnd); - client.join(); - - assertEquals(3, listener.size()); - - for (int i = 0; i < 3; i++) { - assertTrue(listener.get(i) instanceof ResponseReceivedEvent); - ResponseReceivedEvent event = (ResponseReceivedEvent) listener.get(i); - String responseStr = event.getResponse().toString(); - assertTrue(responseStr.startsWith("HTTP/1.1 200 OK")); - assertTrue(responseStr.endsWith("test")); - assertEquals(i, event.getFlowParameters().getLoop()); - } - } finally { - ServiceUtils.stopQuietly(client); - ServiceUtils.stopQuietly(emitter); - } - } -}
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpBasicAuthLoginFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpBasicAuthLoginFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -11,6 +11,7 @@ import com.passus.net.http.HttpResponseBuilder; import com.passus.st.AppUtils; import com.passus.st.client.FlowContext; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import com.passus.st.client.credentials.Credentials; import com.passus.st.client.credentials.CredentialsProvider; @@ -122,7 +123,7 @@ @Test public void testConfigureAndFilterOutbound() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: basicLogin\n" + " applyIf:\n" + " \"@req.uri\": {$contains: \"index2\"}\n" @@ -138,7 +139,7 @@ filterConfig = String.format(filterConfig, file.getAbsolutePath()); Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, ConfigurationContext.create()); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, ConfigurationContext.create()); HttpFilterTestUtils.printErrors(errors); assertEquals(errors.getErrorCount(), 0);
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpCounterFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpCounterFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -13,6 +13,7 @@ import java.util.List; import static org.testng.AssertJUnit.*; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import org.testng.annotations.Test; @@ -44,14 +45,14 @@ @Test public void testConfigure() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: counter\n" + " name: 'filter x'\n" + " limit: 3\n" + " applyIf: {'@resp.status.code': 404}\n"; Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); HttpFilterTestUtils.printErrors(errors); assertEquals(0, errors.getErrorCount());
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpCsrfFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpCsrfFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -8,6 +8,7 @@ import com.passus.net.http.HttpResponseBuilder; import com.passus.st.ParametersBag; import com.passus.st.client.FlowContext; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import com.passus.st.client.http.HttpScopes; import com.passus.st.client.http.filter.HttpCsrfFilter.*; @@ -136,7 +137,7 @@ @Test public void testConfigure() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: csrf\n" + " extract:\n" + " header: \"csrf-header\"\n" @@ -147,7 +148,7 @@ + " store: single\n"; Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); assertEquals(0, errors.getErrorCount()); assertEquals(1, filters.size());
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpCsrfFormFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpCsrfFormFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -19,6 +19,7 @@ import static org.mockito.Mockito.when; import static org.testng.AssertJUnit.*; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import org.testng.annotations.Test; @@ -68,13 +69,13 @@ @Test public void testConfigure() throws IOException, NodeException { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: csrfForm\n" + " inputName: '_token'\n" + " contentTypesToScan: ['text/html', 'application/xhtml+xml', 'application/xml']\n"; Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); assertEquals(0, errors.getErrorCount()); assertEquals(1, filters.size());
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFiltersConfiguratorTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFiltersConfiguratorTest.java Fri May 31 09:12:08 2019 +0200 @@ -3,6 +3,7 @@ import com.passus.commons.utils.ResourceUtils; import com.passus.config.ConfigurationContext; import com.passus.config.validation.Errors; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import com.passus.st.client.credentials.MultiCredentialsProvider; import com.passus.st.client.credentials.UsernamePasswordCredentialsProvider; @@ -22,7 +23,7 @@ File file = ResourceUtils.getFile("com/passus/st/client/http/filter/http_message_modify_filter.yml"); Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(file, errors, ConfigurationContext.create()); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(file, errors, ConfigurationContext.create()); assertEquals(0, errors.getErrorCount()); assertTrue(filters.get(0) instanceof HttpMessageModificationFilter);
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFiltersNodeDefinitionCreatorTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFiltersNodeDefinitionCreatorTest.java Fri May 31 09:12:08 2019 +0200 @@ -32,7 +32,7 @@ NodeDefinition def = creator.create(); Errors errors = new Errors(); - def.validate(config.subConfiguration("httpFilters").getRootNode(), errors, null); + def.validate(config.subConfiguration("filters").getRootNode(), errors, null); errors.getAllErrors().forEach(System.out::println); assertEquals(0, errors.getErrorCount()); }
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpHostRewriterFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpHostRewriterFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -8,6 +8,7 @@ import static com.passus.net.http.HttpHeaders.*; import com.passus.net.http.HttpRequest; import com.passus.net.http.HttpRequestBuilder; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import com.passus.st.client.http.filter.HttpHostRewriterFilter.HostPort; import java.util.List; @@ -83,14 +84,14 @@ @Test public void testConfigure() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: host\n" + " hostMap:\n" + " \"example.com\": \"example.org:8088\"\n" + " \"example.com:8080\": \"example.org\"\n"; Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); assertEquals(0, errors.getErrorCount()); assertEquals(1, filters.size());
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpLogoutFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpLogoutFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -7,6 +7,7 @@ import com.passus.net.http.HttpResponseBuilder; import com.passus.st.AppUtils; import com.passus.st.client.FlowContext; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import com.passus.st.client.http.HttpScopes; import org.testng.annotations.AfterClass; @@ -80,13 +81,13 @@ @Test public void testConfigure() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: logout\n" + " invalidateSession: false\n" + " applyIf: {\"@req.uri\": \"/logout\"}\n"; Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); assertEquals(0, errors.getErrorCount()); assertEquals(1, filters.size());
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMarkFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMarkFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -6,6 +6,7 @@ import com.passus.st.AppUtils; import static com.passus.st.client.http.HttpConsts.TAG_MARKER; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import com.passus.st.client.http.filter.HttpMarkFilter.Marker; import com.passus.st.client.http.filter.HttpMarkFilter.MarkerRule; @@ -50,7 +51,7 @@ @Test public void testConfigure() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: marker\n" + " rules:\n" + " - category: category1\n" @@ -58,7 +59,7 @@ + " applyIf: {req.url: {$contains: test}}\n"; Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); assertEquals(0, errors.getErrorCount()); assertEquals(1, filters.size());
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMatchFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMatchFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -14,6 +14,7 @@ import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertTrue; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -95,14 +96,14 @@ @Test public void testConfigureAndFilterOutbound() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: matcher\n" + " matches:\n" + " '@req.uri': {$contains: 'test'}\n" + " '@resp.status.code': 200\n"; Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); assertEquals(0, errors.getErrorCount()); assertEquals(1, filters.size());
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -7,6 +7,7 @@ import com.passus.net.http.*; import com.passus.st.AppUtils; import com.passus.st.client.FlowContext; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import com.passus.st.extractor.ContentExtractorUtils; import com.passus.st.client.http.filter.HttpMessageModificationOperations.*; @@ -171,7 +172,7 @@ @Test(enabled = true) public void testConfigureAndFilterOutbound() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: modifyMessage\n" + " operations:\n" + " removeHeader: Header1\n" @@ -192,7 +193,7 @@ Errors errors = new Errors(); ConfigurationContextImpl emptyContext = new ConfigurationContextImpl(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, emptyContext); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, emptyContext); assertEquals(0, errors.getErrorCount()); assertEquals(1, filters.size()); assertTrue(filters.get(0) instanceof HttpMessageModificationFilter); @@ -224,7 +225,7 @@ @Test public void testConfigureAndFilterOutbound_firstLineOps() throws Exception { String filterConfig - = "httpFilters:\n" + = "filters:\n" + " - type: modifyMessage\n" + " operations:\n" + " setMethod: HEAD\n" @@ -242,14 +243,14 @@ Errors errors = new Errors(); ConfigurationContextImpl emptyContext = new ConfigurationContextImpl(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, emptyContext); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, emptyContext); HttpFilterTestUtils.printErrors(errors); assertEquals(0, errors.getErrorCount()); assertEquals(2, filters.size()); assertTrue(filters.get(0) instanceof HttpMessageModificationFilter); assertTrue(filters.get(1) instanceof HttpMessageModificationFilter); - HttpFilter f0 = filters.get(0); + FlowFilter f0 = filters.get(0); HttpRequest req0 = HttpRequestBuilder.get("http://example.com?q=1#a1").build(); f0.filterOutbound(req0, null, null); assertEquals(HttpMethod.HEAD, req0.getMethod()); @@ -257,7 +258,7 @@ assertEquals("/aaa/bbb/ccc?q1x=v1x", req0.getUri().toString()); assertEquals("example.com/aaa/bbb/ccc?q1x=v1x", req0.getUrl().toString()); - HttpFilter f1 = filters.get(1); + FlowFilter f1 = filters.get(1); HttpRequest req1 = HttpRequestBuilder.get("http://example.com?q=1#a1").build(); f1.filterOutbound(req1, null, null); assertEquals("example.com/xxx/new/GET?qqq=vvv#anchor", req1.getUrl().toString()); @@ -270,7 +271,7 @@ e("var1", val("value1")) ); - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: modifyMessage\n" + " operations:\n" + " setHeader: \n" @@ -283,7 +284,7 @@ Errors errors = new Errors(); ConfigurationContextImpl context = new ConfigurationContextImpl(); context.add(ConfigurationContextConsts.APP_VARS, appVars); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, context); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, context); assertEquals(0, errors.getErrorCount()); assertEquals(1, filters.size()); assertTrue(filters.get(0) instanceof HttpMessageModificationFilter); @@ -301,7 +302,7 @@ @Test(enabled = true) public void testComplexExpression() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: modifyMessage\n" + " operations:\n" + " setQueryParam: \n" @@ -315,7 +316,7 @@ Errors errors = new Errors(); ConfigurationContextImpl emptyContext = new ConfigurationContextImpl(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, emptyContext); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, emptyContext); HttpFilterTestUtils.printErrors(errors); HttpMessageModificationFilter filter = (HttpMessageModificationFilter) filters.get(0); @@ -331,7 +332,7 @@ .header("Header1", "Header1Value1") .build(); - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: modifyMessage\n" + " applyIf:\n" + " \"@req.uri\": /path/test\n" @@ -342,7 +343,7 @@ Errors errors = new Errors(); ConfigurationContextImpl emptyContext = new ConfigurationContextImpl(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, emptyContext); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, emptyContext); HttpFilterTestUtils.printErrors(errors); assertEquals(0, errors.getErrorCount());
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMvelFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMvelFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -8,6 +8,7 @@ import java.io.File; import java.util.List; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import org.mvel2.MVEL; import org.mvel2.compiler.ExecutableStatement; @@ -40,13 +41,13 @@ public void testConfigure() throws Exception { File file = ResourceUtils.getFile("mvel/return1.mvel"); - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: mvel\n" + " dir: out\n" + " script: return -1\n"; Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); HttpFilterTestUtils.printErrors(errors); assertEquals(0, errors.getErrorCount());
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpScopeModificationFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -8,6 +8,7 @@ import com.passus.net.http.HttpRequestBuilder; import com.passus.st.AppUtils; import com.passus.st.client.FlowContext; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import com.passus.st.client.http.HttpConsts; import com.passus.st.client.http.HttpScopes; @@ -194,7 +195,7 @@ private HttpScopeModificationFilter processConfig(String cfg) throws Exception { Errors errors = new Errors(); ConfigurationContextImpl emptyContext = new ConfigurationContextImpl(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(cfg, errors, emptyContext); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(cfg, errors, emptyContext); assertEquals(errors.toString(), 0, errors.getErrorCount()); assertEquals(1, filters.size()); @@ -205,7 +206,7 @@ @Test public void testSetGlobalParamOperation_Extractors() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: modifyScope\n" + " operations:\n" + " setGlobalParam: \n" @@ -270,7 +271,7 @@ @Test public void testConfiguration() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: modifyScope\n" + " dir: both\n" + " operations:\n" @@ -295,7 +296,7 @@ @Test public void testConfiguration_expressions() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: modifyScope\n" + " dir: both\n" + " operations:\n"
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSequenceFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSequenceFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -16,6 +16,7 @@ import com.passus.net.http.HttpResponse; import com.passus.net.http.HttpResponseBuilder; import com.passus.st.AppUtils; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import com.passus.st.client.http.filter.HttpSequenceFilter.SequenceItem; import com.passus.st.filter.Transformers; @@ -113,7 +114,7 @@ String filterConfig = new String(Files.readAllBytes(Paths.get(file.toURI()))); Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); HttpFilterTestUtils.printErrors(errors); assertEquals(0, errors.getErrorCount());
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -20,6 +20,7 @@ import static org.mockito.Mockito.when; import static org.testng.Assert.*; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import org.testng.annotations.Test; @@ -256,13 +257,13 @@ @Test public void testConfigure() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: session\n" + " sessionCookieNames: [aaa, bbb]\n" + " removeInvalidSessionId: true\n"; Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); HttpFilterTestUtils.printErrors(errors); assertEquals(0, errors.getErrorCount());
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpZoneFilterTest.java Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpZoneFilterTest.java Fri May 31 09:12:08 2019 +0200 @@ -8,6 +8,7 @@ import com.passus.st.AppUtils; import static com.passus.st.client.http.HttpConsts.TAG_ZONE; +import com.passus.st.client.FlowFilter; import com.passus.st.client.FlowFiltersConfigurator; import com.passus.st.client.http.filter.HttpZoneFilter.Rule; import java.util.List; @@ -52,13 +53,13 @@ @Test public void testConfigure() throws Exception { - String filterConfig = "httpFilters:\n" + String filterConfig = "filters:\n" + " - type: zone\n" + " zones:\n" + " \"zone1\": {req.url: {$contains: \"test\"}}\n"; Errors errors = new Errors(); - List<HttpFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); + List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, null); assertEquals(0, errors.getErrorCount()); assertEquals(1, filters.size());
--- a/stress-tester/src/test/resources/com/passus/st/client/http/filter/http_message_modify_filter.yml Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/resources/com/passus/st/client/http/filter/http_message_modify_filter.yml Fri May 31 09:12:08 2019 +0200 @@ -1,4 +1,4 @@ -httpFilters: +filters: - type: modifyMessage operations: removeHeader: Test
--- a/stress-tester/src/test/resources/com/passus/st/client/http/filter/sequence.yml Thu May 30 14:55:34 2019 +0200 +++ b/stress-tester/src/test/resources/com/passus/st/client/http/filter/sequence.yml Fri May 31 09:12:08 2019 +0200 @@ -1,4 +1,4 @@ -httpFilters: +filters: - type: sequence sequence: - match: {"@req.uri": "/res1", "@resp.getCookie('id')": {$neq: "123"}}