Mercurial > stress-tester
changeset 893:f1ae7ba51a29
bugfixes
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java Tue Mar 27 15:19:12 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java Fri Mar 30 11:47:16 2018 +0200 @@ -1,5 +1,6 @@ package com.passus.st; +import com.passus.commons.metric.Metric; import com.passus.config.Configuration; import com.passus.config.YamlConfigurationReader; import com.passus.config.validation.Errors; @@ -9,6 +10,7 @@ import org.apache.commons.cli.*; import java.io.File; +import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -18,6 +20,7 @@ public class GlobalConfigMain { private final CliHelper cliHelper = new CliHelper(); + private final SummaryMetricsCollectionHandler summMetricsHandler = new SummaryMetricsCollectionHandler(); private Options createOptions() { CliOptions options = cliHelper.options(); @@ -30,7 +33,11 @@ formatter.printHelp("[options] <config file>", "description", options, ""); } - private void start(String[] args) { + List<Metric> getMetrics() { + return summMetricsHandler.getMetrics(); + } + + void start(String... args) { AppUtils.registerAll(); Options options = createOptions(); @@ -61,33 +68,32 @@ final long startTime = System.currentTimeMillis(); MetricsCollector metricsCollector = testJob.getMetricsCollector(); - SummaryMetricsCollectionHandler summMetricsHandler; + ScheduledExecutorService executor; if (metricsCollector != null) { - summMetricsHandler = new SummaryMetricsCollectionHandler(); metricsCollector.addHandler(summMetricsHandler); executor = Executors.newSingleThreadScheduledExecutor(); - executor.scheduleAtFixedRate(() -> Main.printMetrics(summMetricsHandler.getMetrics(), startTime), 5, 5, TimeUnit.SECONDS); + executor.scheduleAtFixedRate(() -> Main.printMetrics(getMetrics(), startTime), 5, 5, TimeUnit.SECONDS); } else { - summMetricsHandler = null; executor = null; } final Logger logger = LogManager.getLogger("GlobalConfigMain"); - + testJob.start(); logger.debug("TestJob started"); testJob.join(); logger.debug("TestJob finished"); - testJob.stop(); - logger.debug("TestJob stopped"); - if (metricsCollector != null && summMetricsHandler != null && executor != null) { + if (metricsCollector != null && executor != null) { executor.shutdownNow(); metricsCollector.collect(); metricsCollector.flush(true); - Main.printMetrics(summMetricsHandler.getMetrics(), startTime); + Main.printMetrics(getMetrics(), startTime); } + + testJob.stop(); + logger.debug("TestJob stopped"); } catch (ParseException e) { System.out.println(e.getMessage()); printHelp(options);
--- a/stress-tester/src/main/java/com/passus/st/client/credentials/UsernamePasswordCredentialsProvider.java Tue Mar 27 15:19:12 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/credentials/UsernamePasswordCredentialsProvider.java Fri Mar 30 11:47:16 2018 +0200 @@ -59,8 +59,8 @@ @Override public void configure(Configuration config, ConfigurationContext context) { - username = (String) config.get("username"); - password = (String) config.get("password", ""); + username = config.getString("username"); + password = config.getString("password", ""); } public static class UsernamePasswordCredentialsProviderNodeDefinitionCreator implements NodeDefinitionCreator {
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpHostRewriterFilter.java Tue Mar 27 15:19:12 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpHostRewriterFilter.java Fri Mar 30 11:47:16 2018 +0200 @@ -52,7 +52,7 @@ @SuppressWarnings("unchecked") @Override public void configure(Configuration config, ConfigurationContext context) { - Map map = (Map) config.get("hostMap", Collections.EMPTY_MAP); + Map map = config.getMap("hostMap", Collections.EMPTY_MAP); setHostMap(map); }
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMatchFilter.java Tue Mar 27 15:19:12 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMatchFilter.java Fri Mar 30 11:47:16 2018 +0200 @@ -46,7 +46,7 @@ @Override public void configure(Configuration config, ConfigurationContext context) { predicate = (HttpMessagePredicate) config.get("matches"); - acceptOnMatch = (boolean) config.get("acceptOnMatch", true); + acceptOnMatch = config.getBoolean("acceptOnMatch", true); } @Override
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java Tue Mar 27 15:19:12 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java Fri Mar 30 11:47:16 2018 +0200 @@ -108,7 +108,7 @@ public void configure(Configuration config, ConfigurationContext context) { cookieNames.clear(); cookieNames.addAll((Collection) config.get("sessionCookieNames", DEFAULT_COOKIE_NAMES)); - removeInvalidSessionId = (Boolean) config.get("removeInvalidSessionId", false); + removeInvalidSessionId = config.getBoolean("removeInvalidSessionId", false); } @Override
--- a/stress-tester/src/main/java/com/passus/st/config/TestJobConfigurator.java Tue Mar 27 15:19:12 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/config/TestJobConfigurator.java Fri Mar 30 11:47:16 2018 +0200 @@ -4,7 +4,6 @@ import com.passus.commons.plugin.PluginFactory; import com.passus.config.*; import com.passus.config.validation.Errors; -import com.passus.st.job.TestJob; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger;
--- a/stress-tester/src/main/java/com/passus/st/emitter/EmitterConfigurator.java Tue Mar 27 15:19:12 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/emitter/EmitterConfigurator.java Fri Mar 30 11:47:16 2018 +0200 @@ -45,7 +45,7 @@ CCompositeNode rootNode = config.getRootNode(); nodeDefinition.transform(rootNode, errors, context); if (errors.getErrorCount() == 0) { - SessionMapper defaultSessionMapper = (SessionMapper) config.get("sessionMapper", Emitter.DEFAULT_SESSION_MAPPER); + SessionMapper defaultSessionMapper = config.get("sessionMapper", Emitter.DEFAULT_SESSION_MAPPER); List<Emitter> emitters = (List<Emitter>) config.get("emitters"); if (emitters == null) { emitters = new ArrayList<>(4);
--- a/stress-tester/src/main/java/com/passus/st/job/TestJob.java Tue Mar 27 15:19:12 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/job/TestJob.java Fri Mar 30 11:47:16 2018 +0200 @@ -13,6 +13,7 @@ import com.passus.st.emitter.Emitter; import com.passus.st.emitter.PassThroughSessionMapper; import com.passus.st.emitter.nio.NioEmitter; +import com.passus.st.metric.MetricSource; import com.passus.st.metric.MetricsCollector; import com.passus.st.source.EventSource; import org.apache.logging.log4j.LogManager; @@ -196,6 +197,12 @@ Client firstClient = clients.get(0); eventSources.forEach(src -> { src.setHandler(firstClient); + if (src instanceof MetricSource) { + MetricSource es = (MetricSource) src; + if (es.isCollectMetrics()) { + metricsCollector.register(es); + } + } }); // TODO: quickfix
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Tue Mar 27 15:19:12 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Fri Mar 30 11:47:16 2018 +0200 @@ -41,6 +41,7 @@ import org.apache.logging.log4j.Logger; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ArrayBlockingQueue; @@ -196,6 +197,13 @@ pcapFile = config.getString("fileName"); loops = config.getInteger("loops", EventSource.DEFAULT_LOOPS); loopDelay = config.getLong("loopDelay", 0L); + + setCollectMetrics(config.getBoolean("collectMetrics", Boolean.FALSE)); + + Map<String, Map> sessionProc = config.getMap("sessionProc", Collections.EMPTY_MAP); + Map<String, Object> tcp = sessionProc.getOrDefault("tcp", Collections.EMPTY_MAP); + Boolean ps = (Boolean) tcp.getOrDefault("allowPartialSession", Boolean.FALSE); + setAllowPartialSession(ps); } @Override