Mercurial > stress-tester
changeset 1176:8208e6d5ce24
File - relative path processing
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java Tue Jun 16 16:39:25 2020 +0200 @@ -64,6 +64,7 @@ File configFile = new File(clArgs[0]); Configuration config = YamlConfigurationReader.readFromFile(configFile); + ConfigurationContext context = ConfigurationContext.create(); TestJobConfigurator testJobConfigurator = new TestJobConfigurator(); testJobConfigurator.configure(config, errors, context);
--- a/stress-tester/src/main/java/com/passus/st/client/credentials/CsvUsernamePasswordCredentialsProvider.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/credentials/CsvUsernamePasswordCredentialsProvider.java Tue Jun 16 16:39:25 2020 +0200 @@ -10,6 +10,7 @@ import static com.passus.config.schema.ConfigurationSchemaBuilder.mapDef; import static com.passus.config.schema.ConfigurationSchemaBuilder.tupleDef; import static com.passus.config.schema.ConfigurationSchemaBuilder.valueDef; +import static com.passus.st.config.CommonNodeDefs.FILE_STR_DEF; import static com.passus.st.config.CommonNodeDefs.STRING_DEF; import com.passus.config.schema.NodeDefinition; @@ -173,7 +174,7 @@ @Override public NodeDefinition create() { return mapDef( - tupleDef("fileName", STRING_DEF), + tupleDef("fileName", FILE_STR_DEF), tupleDef("readMode", valueDef().setTransformer(TRANSFORMER)).setRequired(false), tupleDef("separator", STRING_DEF).setRequired(false) );
--- a/stress-tester/src/main/java/com/passus/st/client/http/SummaryHttpClientListener.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/SummaryHttpClientListener.java Tue Jun 16 16:39:25 2020 +0200 @@ -12,6 +12,7 @@ import com.passus.net.http.HttpRequest; import com.passus.net.http.HttpResponse; import com.passus.st.client.FlowContext; +import com.passus.st.config.FileTransformer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -105,7 +106,7 @@ @Override public NodeDefinition create() { return mapDef( - tupleDef("fileName", STRING_DEF) + tupleDef("fileName", valueDef().setTransformer(new FileTransformer(true))) ); } }
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpTrafficDumperFilter.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpTrafficDumperFilter.java Tue Jun 16 16:39:25 2020 +0200 @@ -15,6 +15,7 @@ import com.passus.st.ParametersBag; import com.passus.st.client.FlowContext; import com.passus.st.client.http.HttpFlowContext; +import com.passus.st.config.FileTransformer; import com.passus.st.emitter.ChannelContext; import com.passus.st.filter.FlowFilter; import com.passus.st.plugin.PluginConstants; @@ -24,8 +25,7 @@ import java.io.*; -import static com.passus.config.schema.ConfigurationSchemaBuilder.mapDef; -import static com.passus.config.schema.ConfigurationSchemaBuilder.tupleDef; +import static com.passus.config.schema.ConfigurationSchemaBuilder.*; import static com.passus.net.http.HttpUtils.intToVersionString; import static com.passus.st.client.http.HttpConsts.*; import static com.passus.st.client.http.filter.HttpFlowUtils.extractHttpContext; @@ -250,7 +250,7 @@ @Override public NodeDefinition create() { return mapDef( - tupleDef("fileName", STRING_DEF), + tupleDef("fileName", valueDef().setTransformer(new FileTransformer(true))), tupleDef("append", BOOLEAN_DEF).setRequired(false) ); }
--- a/stress-tester/src/main/java/com/passus/st/config/CommonNodeDefs.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/config/CommonNodeDefs.java Tue Jun 16 16:39:25 2020 +0200 @@ -4,6 +4,7 @@ import com.passus.config.validation.LongValidator; import com.passus.st.filter.MessagePredicateNodeDefinition; import com.passus.st.utils.PeriodValueTransformer; +import com.passus.st.validation.FileValidator; import com.passus.st.validation.PortValidator; import static com.passus.config.schema.ConfigurationSchemaBuilder.*; @@ -32,6 +33,9 @@ public static NodeDefinition PERIOD_DEF = valueDef().setTransformer(PeriodValueTransformer.INSTANCE); + public static NodeDefinition FILE_STR_DEF = valueDef().addValidator(new FileValidator()) + .setTransformer(new FileTransformer(true)); + private CommonNodeDefs() { } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/config/FileTransformer.java Tue Jun 16 16:39:25 2020 +0200 @@ -0,0 +1,47 @@ +package com.passus.st.config; + +import com.passus.config.ConfigurationContext; +import com.passus.config.ValueTransformer; +import com.passus.config.validation.Errors; + +import java.io.File; + +public class FileTransformer implements ValueTransformer { + + private final boolean returnAsString; + + public FileTransformer() { + this(false); + } + + public FileTransformer(boolean returnAsString) { + this.returnAsString = returnAsString; + } + + @Override + public Object transform(Object obj, Errors errors, ConfigurationContext context) { + if (obj == null) { + return null; + } + + if (obj instanceof String) { + String s = (String) obj; + File file = new File(s); + if (!file.isAbsolute()) { + file = new File(context.getRootDir(), s); + } + + + return returnAsString ? file.getAbsolutePath() : file; + } + + errors.reject("Invalid type."); + return null; + } + + @Override + public Object reverseTransform(Object obj, Errors errors, ConfigurationContext context) { + throw new UnsupportedOperationException("Not supported yet."); + } + +} \ No newline at end of file
--- a/stress-tester/src/main/java/com/passus/st/metric/FileMetricsCollectionAppender.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/metric/FileMetricsCollectionAppender.java Tue Jun 16 16:39:25 2020 +0200 @@ -9,8 +9,10 @@ import com.passus.config.annotations.NodeDefinitionCreate; import com.passus.config.schema.NodeDefinition; import com.passus.config.schema.NodeDefinitionCreator; +import com.passus.st.config.FileTransformer; import com.passus.st.plugin.PluginConstants; import com.passus.st.utils.SizeValueTransformer; +import com.passus.st.validation.FileValidator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -289,7 +291,7 @@ public NodeDefinition create() { return mapDef( tupleDef("active", BOOLEAN_DEF).setRequired(false), - tupleDef("fileName", STRING_DEF), + tupleDef("fileName", valueDef().setTransformer(new FileTransformer(true))), tupleDef("maxFileSize", valueDef().setTransformer(SizeValueTransformer.INSTANCE) ).setRequired(false),
--- a/stress-tester/src/main/java/com/passus/st/source/NcEventSource.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/NcEventSource.java Tue Jun 16 16:39:25 2020 +0200 @@ -20,6 +20,7 @@ import com.passus.st.client.EventHandler; import com.passus.st.client.SessionPayloadEvent; import com.passus.st.client.SessionStatusEvent; +import com.passus.st.config.FileTransformer; import com.passus.st.emitter.SessionInfo; import com.passus.st.plugin.PluginConstants; import com.passus.st.reader.nc.*; @@ -29,8 +30,7 @@ import java.io.File; import java.io.IOException; -import static com.passus.config.schema.ConfigurationSchemaBuilder.mapDef; -import static com.passus.config.schema.ConfigurationSchemaBuilder.tupleDef; +import static com.passus.config.schema.ConfigurationSchemaBuilder.*; import static com.passus.st.Protocols.*; import static com.passus.st.config.CommonNodeDefs.INT_GREATER_EQUAL_ZERO_DEF; import static com.passus.st.config.CommonNodeDefs.STRING_DEF; @@ -341,7 +341,7 @@ @Override public NodeDefinition create() { return mapDef( - tupleDef("fileName", STRING_DEF), + tupleDef("fileName", valueDef().setTransformer(new FileTransformer(true))), tupleDef("loops", INT_GREATER_EQUAL_ZERO_DEF).setRequired(false) ); }
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Tue Jun 16 16:39:25 2020 +0200 @@ -540,7 +540,7 @@ ); return mapDef( - tupleDef("fileName", valueDef().addValidator(new FileValidator())), + tupleDef("fileName", FILE_STR_DEF), tupleDef("loops", INT_GREATER_EQUAL_ZERO_DEF).setRequired(false), tupleDef("loopDelay", LONG_GREATER_EQUAL_ZERO_DEF).setRequired(false), tupleDef("sessionProc", sessionProcDef).setRequired(false),
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSourceNodeDefCreator.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSourceNodeDefCreator.java Tue Jun 16 16:39:25 2020 +0200 @@ -1,11 +1,12 @@ package com.passus.st.source; -import static com.passus.config.schema.ConfigurationSchemaBuilder.*; import com.passus.config.schema.NodeDefinition; import com.passus.config.schema.NodeDefinitionCreator; +import static com.passus.config.schema.ConfigurationSchemaBuilder.*; +import static com.passus.st.config.CommonNodeDefs.FILE_STR_DEF; + /** - * * @author Mirosław Hawrot */ public class PcapSessionEventSourceNodeDefCreator implements NodeDefinitionCreator { @@ -13,10 +14,10 @@ @Override public NodeDefinition create() { return mapDef( - tupleDef("fileName", valueDef()), + tupleDef("fileName", FILE_STR_DEF), tupleDef("loops", valueDefInteger().setDefaultValue(1)).setRequired(false), tupleDef("loopDelay", valueDefInteger().setDefaultValue(200)).setRequired(false) ); } - + }
--- a/stress-tester/src/main/java/com/passus/st/validation/FileValidator.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/validation/FileValidator.java Tue Jun 16 16:39:25 2020 +0200 @@ -75,8 +75,8 @@ return; } - if(!file.isAbsolute()) { - + if (!file.isAbsolute()) { + file = new File(context.getRootDir(), file.getPath()); } if (exists && !file.exists()) {
--- a/stress-tester/src/test/java/com/passus/st/config/MetricsConfiguratorTest.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/test/java/com/passus/st/config/MetricsConfiguratorTest.java Tue Jun 16 16:39:25 2020 +0200 @@ -7,6 +7,8 @@ import com.passus.config.validation.Errors; import com.passus.st.metric.FileMetricsCollectionAppender; import com.passus.st.metric.MetricsCollectionAppender; + +import java.io.File; import java.util.List; import static com.passus.st.utils.ConfigurationContextConsts.METRICS_COLLECTION_APPENDERS; @@ -63,7 +65,7 @@ assertTrue(appenders.get(0) instanceof FileMetricsCollectionAppender); FileMetricsCollectionAppender appender = (FileMetricsCollectionAppender) appenders.get(0); - assertEquals("/file", appender.getFileName()); + assertEquals(new File(context.getRootDir(), "/file").toString(), appender.getFileName()); assertEquals(10 * 1024, appender.getMaxFileSize()); } }
--- a/stress-tester/src/test/java/com/passus/st/config/TestJobConfiguratorTest.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/test/java/com/passus/st/config/TestJobConfiguratorTest.java Tue Jun 16 16:39:25 2020 +0200 @@ -49,7 +49,7 @@ Configuration config = YamlConfigurationReader.readFromFile(configFile); TestJobConfigurator configurator = new TestJobConfigurator(); - ConfigurationContext context = new ConfigurationContextImpl(); + ConfigurationContext context = new ConfigurationContextImpl(configFile.getParentFile()); configurator.configure(config, errors, context); assertFalse(errors.hasError()); return context;
--- a/stress-tester/src/test/java/com/passus/st/project/ProjectConfiguratorTest.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/test/java/com/passus/st/project/ProjectConfiguratorTest.java Tue Jun 16 16:39:25 2020 +0200 @@ -28,7 +28,7 @@ Configuration config = YamlConfigurationReader.readFromFile(configFile); ProjectConfigurator configurator = new ProjectConfigurator(); - ConfigurationContext context = new ConfigurationContextImpl(); + ConfigurationContext context = new ConfigurationContextImpl(configFile.getParentFile()); configurator.configure(config, errors, context); assertFalse(errors.hasError());
--- a/stress-tester/src/test/java/com/passus/st/source/EventSourceConfiguratorTest.java Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/test/java/com/passus/st/source/EventSourceConfiguratorTest.java Tue Jun 16 16:39:25 2020 +0200 @@ -9,10 +9,10 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; +import java.io.File; import java.util.List; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.*; public class EventSourceConfiguratorTest { @@ -54,16 +54,16 @@ configurator.configure(config, errors, context); assertFalse(errors.hasError()); - List<EventSource> sources = (List<EventSource>) context.get(ConfigurationContextConsts.EVENT_SOURCE_SOURCES); + List<EventSource> sources = context.get(ConfigurationContextConsts.EVENT_SOURCE_SOURCES); assertEquals(2, sources.size()); PcapSessionEventSource pcapEventSource = (PcapSessionEventSource) sources.get(0); - assertEquals("/test.pcap", pcapEventSource.getPcapFile()); + assertEquals(new File(context.getRootDir(), "/test.pcap").toString(), pcapEventSource.getPcapFile()); assertEquals(2, pcapEventSource.getLoops()); assertEquals(3, pcapEventSource.getLoopDelay()); NcEventSource ncEventSource = (NcEventSource) sources.get(1); - assertEquals("/test.nc", ncEventSource.getNcFile()); + assertEquals(new File(context.getRootDir(), "/test.nc").toString(), ncEventSource.getNcFile()); assertEquals(4, ncEventSource.getLoops()); } } \ No newline at end of file
--- a/stress-tester/src/test/resources/com/passus/st/project/test_project_config.yml Tue Jun 16 16:22:44 2020 +0200 +++ b/stress-tester/src/test/resources/com/passus/st/project/test_project_config.yml Tue Jun 16 16:39:25 2020 +0200 @@ -24,11 +24,11 @@ eventSource: sources: - type: pcap - fileName: /test.pcap + fileName: ./test.pcap loops: 1 - type: nc - fileName: /test.nc + fileName: ./test.nc loops: 1 client: