Mercurial > stress-tester
changeset 840:69f9920bc532
TestJobConfiguratorTest + Configurators minors
author | Devel 2 |
---|---|
date | Mon, 22 Jan 2018 14:13:41 +0100 |
parents | 6b4a56251b57 |
children | 6ea37bd18996 |
files | stress-tester/src/main/java/com/passus/st/client/http/ReporterConfigurator.java stress-tester/src/main/java/com/passus/st/emitter/EmitterConfigurator.java stress-tester/src/main/java/com/passus/st/source/EventSourceConfigurator.java stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java stress-tester/src/test/java/com/passus/st/config/TestJobConfiguratorTest.java stress-tester/src/test/resources/com/passus/st/config/test_job_config.yml |
diffstat | 6 files changed, 95 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/ReporterConfigurator.java Mon Jan 22 12:46:19 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/client/http/ReporterConfigurator.java Mon Jan 22 14:13:41 2018 +0100 @@ -1,12 +1,15 @@ package com.passus.st.client.http; +import com.passus.commons.annotations.Plugin; import com.passus.config.CCompositeNode; import com.passus.config.Configuration; import com.passus.config.ConfigurationContext; import com.passus.config.DomainConfigurator; import com.passus.config.schema.NodeDefinition; import com.passus.config.validation.Errors; +import com.passus.st.plugin.PluginConstants; +@Plugin(name = ReporterConfigurator.DOMAIN, category = PluginConstants.CATEGORY_DOMAIN_CONFIGURATOR) public class ReporterConfigurator implements DomainConfigurator { public static final String DOMAIN = "reporter";
--- a/stress-tester/src/main/java/com/passus/st/emitter/EmitterConfigurator.java Mon Jan 22 12:46:19 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/emitter/EmitterConfigurator.java Mon Jan 22 14:13:41 2018 +0100 @@ -1,5 +1,6 @@ package com.passus.st.emitter; +import com.passus.commons.annotations.Plugin; import com.passus.config.CCompositeNode; import com.passus.config.Configuration; import com.passus.config.ConfigurationContext; @@ -7,17 +8,17 @@ import com.passus.config.schema.NodeDefinition; import com.passus.config.validation.Errors; import com.passus.st.emitter.nio.NioEmitter; +import com.passus.st.plugin.PluginConstants; import java.util.ArrayList; import java.util.List; -import static com.passus.st.utils.ConfigurationContextConsts.EMITTER_DEFAULT_EMITTER; -import static com.passus.st.utils.ConfigurationContextConsts.EMITTER_EMITTERS; -import static com.passus.st.utils.ConfigurationContextConsts.EMITTER_SESSION_MAPPER; +import static com.passus.st.utils.ConfigurationContextConsts.*; /** * @author Mirosław Hawrot */ +@Plugin(name = EmitterConfigurator.DOMAIN, category = PluginConstants.CATEGORY_DOMAIN_CONFIGURATOR) public class EmitterConfigurator implements DomainConfigurator { public static final String DOMAIN = "emitter";
--- a/stress-tester/src/main/java/com/passus/st/source/EventSourceConfigurator.java Mon Jan 22 12:46:19 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/source/EventSourceConfigurator.java Mon Jan 22 14:13:41 2018 +0100 @@ -1,11 +1,13 @@ package com.passus.st.source; +import com.passus.commons.annotations.Plugin; import com.passus.config.CCompositeNode; import com.passus.config.Configuration; import com.passus.config.ConfigurationContext; import com.passus.config.DomainConfigurator; import com.passus.config.schema.NodeDefinition; import com.passus.config.validation.Errors; +import com.passus.st.plugin.PluginConstants; import com.passus.st.utils.ConfigurationContextConsts; import java.util.List; @@ -13,6 +15,7 @@ /** * @author Mirosław Hawrot */ +@Plugin(name = EventSourceConfigurator.DOMAIN, category = PluginConstants.CATEGORY_DOMAIN_CONFIGURATOR) public class EventSourceConfigurator implements DomainConfigurator { public static final String DOMAIN = "eventSource";
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Mon Jan 22 12:46:19 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Mon Jan 22 14:13:41 2018 +0100 @@ -69,7 +69,7 @@ private String pcapFile; - private int loops = 1; + private int loops = EventSource.DEFAULT_LOOPS; private long loopDelay = 0; @@ -193,7 +193,7 @@ @Override public void configure(Configuration config) { pcapFile = config.getString("fileName"); - loops = config.getInteger("loops", 1); + loops = config.getInteger("loops", EventSource.DEFAULT_LOOPS); loopDelay = config.getLong("loopDelay", 0L); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/test/java/com/passus/st/config/TestJobConfiguratorTest.java Mon Jan 22 14:13:41 2018 +0100 @@ -0,0 +1,45 @@ +package com.passus.st.config; + +import com.passus.commons.utils.ResourceUtils; +import com.passus.config.Configuration; +import com.passus.config.ConfigurationContext; +import com.passus.config.ConfigurationContextImpl; +import com.passus.config.YamlConfigurationReader; +import com.passus.config.validation.Errors; +import com.passus.st.client.Client; +import com.passus.st.client.http.HttpClient; +import com.passus.st.source.EventSource; +import com.passus.st.source.NcEventSource; +import com.passus.st.source.PcapSessionEventSource; +import com.passus.st.utils.ConfigurationContextConsts; +import org.testng.annotations.Test; + +import java.io.File; +import java.util.List; + +import static org.testng.AssertJUnit.*; + +public class TestJobConfiguratorTest { + + private Errors errors = new Errors(); + + @Test + public void testConfigure() throws Exception { + File configFile = ResourceUtils.getFile("com/passus/st/config/test_job_config.yml"); + Configuration config = YamlConfigurationReader.readFromFile(configFile); + + TestJobConfigurator configurator = new TestJobConfigurator(); + ConfigurationContext context = new ConfigurationContextImpl(); + configurator.configure(config, errors, context); + assertFalse(errors.hasError()); + + List<Client> clients = (List<Client>) context.get(ConfigurationContextConsts.CLIENT_CLIENTS); + assertEquals(1, clients.size()); + assertTrue(clients.get(0) instanceof HttpClient); + + List<EventSource> sources = (List<EventSource>) context.get(ConfigurationContextConsts.EVENT_SOURCE_SOURCES); + assertEquals(2, sources.size()); + assertTrue(sources.get(0) instanceof PcapSessionEventSource); + assertTrue(sources.get(1) instanceof NcEventSource); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/test/resources/com/passus/st/config/test_job_config.yml Mon Jan 22 14:13:41 2018 +0100 @@ -0,0 +1,38 @@ +reporter: + active: true + address: 2.2.2.2 + port: 222222 + + +metrics: + active: true + destinations: + - type: file + fileName: /file + active: true + +emitter: + sessionMapper: "1.1.1.1:80->2.2.2.2:90" + emitters: + - type: nio + connectionTimeout: 5s + connectionAttempts: 3 + threads: 4 + collectMetrics: true + +eventSource: + sources: + - type: pcap + fileName: /test.pcap + loops: 1 + + - type: nc + fileName: /test.nc + loops: 1 + +client: + clients: + - type: http + connectPartialSession: false + collectMetrics: true + workers: 4