Mercurial > stress-tester
changeset 846:c6bd0e721da3
reverseTransform in progress
author | Devel 1 |
---|---|
date | Tue, 23 Jan 2018 13:30:36 +0100 |
parents | 80b23882a893 |
children | eac857745b29 |
files | stress-tester/src/main/java/com/passus/st/client/credentials/CsvUsernamePasswordCredentialsProvider.java stress-tester/src/main/java/com/passus/st/client/credentials/MultiCredentialsProviderTransformer.java stress-tester/src/main/java/com/passus/st/utils/PeriodValueTransformer.java stress-tester/src/main/java/com/passus/st/utils/SizeValueTransformer.java stress-tester/src/test/java/com/passus/st/client/credentials/MultiCredentialsProviderTransformerTest.java stress-tester/src/test/java/com/passus/st/client/http/ReporterConfiguratorTest.java |
diffstat | 6 files changed, 30 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/credentials/CsvUsernamePasswordCredentialsProvider.java Tue Jan 23 12:50:05 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/client/credentials/CsvUsernamePasswordCredentialsProvider.java Tue Jan 23 13:30:36 2018 +0100 @@ -165,7 +165,7 @@ public static class NodeDefCreator implements NodeDefinitionCreator { - private static ReadModeTransformer TRANSFORMER = new ReadModeTransformer(); + private static final ReadModeTransformer TRANSFORMER = new ReadModeTransformer(); @Override public NodeDefinition create() {
--- a/stress-tester/src/main/java/com/passus/st/client/credentials/MultiCredentialsProviderTransformer.java Tue Jan 23 12:50:05 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/client/credentials/MultiCredentialsProviderTransformer.java Tue Jan 23 13:30:36 2018 +0100 @@ -8,10 +8,8 @@ import com.passus.config.ConfigurationContext; import com.passus.config.ConfigurationImpl; import com.passus.config.NodeType; -import com.passus.config.schema.ConfigurationSchemaUtils; import static com.passus.config.schema.ConfigurationSchemaUtils.getDefinitionCreatorFactory; import com.passus.config.schema.NodeDefinition; -import com.passus.config.schema.NodeDefinitionCreator; import com.passus.config.schema.NodeTransformer; import com.passus.config.validation.Errors; import static com.passus.st.validation.NodeValidationUtils.validateType;
--- a/stress-tester/src/main/java/com/passus/st/utils/PeriodValueTransformer.java Tue Jan 23 12:50:05 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/utils/PeriodValueTransformer.java Tue Jan 23 13:30:36 2018 +0100 @@ -22,7 +22,14 @@ @Override public Object reverseTransform(Object obj) throws ConversionException { - throw new UnsupportedOperationException("Not supported yet."); + if (obj == null) { + return null; + } else if (!(obj instanceof Long)) { + throw new ConversionException(); + } + + Long l = (Long) obj; + return PeriodFormatter.INSTANCE.reverseTransform(l); } }
--- a/stress-tester/src/main/java/com/passus/st/utils/SizeValueTransformer.java Tue Jan 23 12:50:05 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/utils/SizeValueTransformer.java Tue Jan 23 13:30:36 2018 +0100 @@ -24,7 +24,14 @@ @Override public Object reverseTransform(Object obj) throws ConversionException { - throw new UnsupportedOperationException("Not supported yet."); + if (obj == null) { + return null; + } else if (!(obj instanceof Long)) { + throw new ConversionException(); + } + + Long l = (Long) obj; + return SizeFormatter.INSTANCE.reverseTransform(l); } }
--- a/stress-tester/src/test/java/com/passus/st/client/credentials/MultiCredentialsProviderTransformerTest.java Tue Jan 23 12:50:05 2018 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/credentials/MultiCredentialsProviderTransformerTest.java Tue Jan 23 13:30:36 2018 +0100 @@ -10,8 +10,7 @@ import com.passus.config.ConfigurationContext; import com.passus.config.NodeException; import com.passus.config.YamlConfigurationReader; -import com.passus.config.schema.NodeDefinitionCreatorFactory; -import com.passus.config.schema.NodeDefinitionCreatorFactoryImpl; +import com.passus.config.schema.NodeTransformer; import com.passus.st.client.credentials.CsvUsernamePasswordCredentialsProvider.ReadMode; import java.io.File; import java.io.IOException; @@ -94,15 +93,20 @@ } private static MultiCredentialsProvider readAndTransform(String content) throws IOException, NodeException, ConversionException { + return readAndTransform(new MultiCredentialsProviderTransformer(), content); + } + + static <T extends NodeTransformer<CValueNode>, P extends CredentialsProvider> P + readAndTransform(T transformer, String content) + throws IOException, NodeException, ConversionException { + ConfigurationContext context = ConfigurationContext.create(); Configuration cfg = YamlConfigurationReader.readFromString(content); CCompositeNode rootNode = cfg.getRootNode(); CTupleNode providerNode = (CTupleNode) rootNode.getFirstChild(); CNode node = providerNode.getNode(); - MultiCredentialsProviderTransformer transformer = new MultiCredentialsProviderTransformer(); CValueNode valueNode = transformer.transform(node, context); - return (MultiCredentialsProvider) valueNode.getValue(); + return (P) valueNode.getValue(); } - }
--- a/stress-tester/src/test/java/com/passus/st/client/http/ReporterConfiguratorTest.java Tue Jan 23 12:50:05 2018 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/ReporterConfiguratorTest.java Tue Jan 23 13:30:36 2018 +0100 @@ -61,6 +61,7 @@ + " - type: remote\n" + " host: 1.1.1.1\n" + " port: 11111\n" + + " threads: 3\n" + " - type: file\n" + " directory: 'c:\\reporter'"; validate(cfgString); @@ -94,7 +95,8 @@ + " - type: remote\n" + " - type: remote\n" + " host: 1.1.1.2\n" - + " port: 1112\n" + + " port: 1112" + + " threads: 3\n" + ""; ConfigurationContext context = new ConfigurationContextImpl(); @@ -112,7 +114,7 @@ checkRemote((ReporterRemoteDestination) destinations.get(1), SocketReporterClient.DEFAULT_HOST, SocketReporterClient.DEFAULT_PORT, SocketReporterClient.DEFAULT_THREADS); - checkRemote((ReporterRemoteDestination) destinations.get(2), "1.1.1.2", 1112, SocketReporterClient.DEFAULT_THREADS); + checkRemote((ReporterRemoteDestination) destinations.get(2), "1.1.1.2", 1112, 3); } }