Mercurial > stress-tester
changeset 1111:7da8b2a6bb2e
TimeoutsNodeDefCreator improvements
author | Devel 2 |
---|---|
date | Wed, 20 May 2020 13:50:13 +0200 |
parents | e488f699f8c2 |
children | 35118d7d6acf |
files | stress-tester/src/main/java/com/passus/st/config/CommonNodeDefs.java stress-tester/src/main/java/com/passus/st/config/TimeoutsNodeDefCreator.java stress-tester/src/main/java/com/passus/st/config/TimeoutsRuleNodeTransformer.java stress-tester/src/test/java/com/passus/st/emitter/EmitterConfiguratorTest.java |
diffstat | 4 files changed, 33 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/config/CommonNodeDefs.java Wed May 20 11:27:49 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/config/CommonNodeDefs.java Wed May 20 13:50:13 2020 +0200 @@ -3,6 +3,7 @@ import com.passus.config.schema.NodeDefinition; import com.passus.config.validation.LongValidator; import com.passus.st.filter.MessagePredicateNodeDefinition; +import com.passus.st.utils.PeriodValueTransformer; import com.passus.st.validation.PortValidator; import static com.passus.config.schema.ConfigurationSchemaBuilder.*; @@ -29,6 +30,8 @@ public static NodeDefinition MSG_PREDICATE_DEF = new MessagePredicateNodeDefinition(); + public static NodeDefinition PERIOD_DEF = valueDef().setTransformer(PeriodValueTransformer.INSTANCE); + private CommonNodeDefs() { } }
--- a/stress-tester/src/main/java/com/passus/st/config/TimeoutsNodeDefCreator.java Wed May 20 11:27:49 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/config/TimeoutsNodeDefCreator.java Wed May 20 13:50:13 2020 +0200 @@ -6,7 +6,7 @@ import static com.passus.config.schema.ConfigurationSchemaBuilder.mapDef; import static com.passus.config.schema.ConfigurationSchemaBuilder.tupleDef; -import static com.passus.st.config.CommonNodeDefs.LONG_GREATER_THAN_ZERO_DEF; +import static com.passus.st.config.CommonNodeDefs.PERIOD_DEF; public class TimeoutsNodeDefCreator implements NodeDefinitionCreator { @@ -23,9 +23,9 @@ @Override public NodeDefinition create() { return mapDef( - tupleDef("connect", LONG_GREATER_THAN_ZERO_DEF).setRequired(false), - tupleDef("read", LONG_GREATER_THAN_ZERO_DEF).setRequired(false), - tupleDef("disconnect", LONG_GREATER_THAN_ZERO_DEF).setRequired(false) + tupleDef("connect", PERIOD_DEF).setRequired(false), + tupleDef("read", PERIOD_DEF).setRequired(false), + tupleDef("disconnect", PERIOD_DEF).setRequired(false) ).setTransformer(new TimeoutsRuleNodeTransformer(defaultTimeouts)); }
--- a/stress-tester/src/main/java/com/passus/st/config/TimeoutsRuleNodeTransformer.java Wed May 20 11:27:49 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/config/TimeoutsRuleNodeTransformer.java Wed May 20 13:50:13 2020 +0200 @@ -4,10 +4,11 @@ import com.passus.config.schema.NodeTransformer; import com.passus.config.validation.Errors; import com.passus.st.client.Timeouts; +import com.passus.st.utils.PeriodValueTransformer; import java.util.List; -import static com.passus.config.ConfigurationUtils.extractLong; +import static com.passus.config.ConfigurationUtils.extractString; public class TimeoutsRuleNodeTransformer implements NodeTransformer<CNode> { @@ -28,19 +29,32 @@ Timeouts timeouts = defaultTimeouts == null ? new Timeouts() : new Timeouts(defaultTimeouts); List<CTupleNode> tuples = mapNode.getChildren(); if (!tuples.isEmpty()) { + PeriodValueTransformer transformer = PeriodValueTransformer.INSTANCE; for (CTupleNode tuple : tuples) { String opName = tuple.getName(); try { switch (opName.toLowerCase()) { - case "connect": - timeouts.setConnectionTimeout(extractLong(tuple)); + case "connect": { + Long value = (Long) transformer.transform(extractString(tuple), errors, context); + if (!errors.hasError()) { + timeouts.setConnectionTimeout(value); + } break; - case "read": - timeouts.setReadTimeout(extractLong(tuple)); + } + case "read": { + Long value = (Long) transformer.transform(extractString(tuple), errors, context); + if (!errors.hasError()) { + timeouts.setReadTimeout(value); + } break; - case "disconnect": - timeouts.setDisconnectTimeout(extractLong(tuple)); + } + case "disconnect": { + Long value = (Long) transformer.transform(extractString(tuple), errors, context); + if (!errors.hasError()) { + timeouts.setDisconnectTimeout(value); + } break; + } default: throw new IllegalArgumentException("Unknown parameter '" + opName + "'."); }
--- a/stress-tester/src/test/java/com/passus/st/emitter/EmitterConfiguratorTest.java Wed May 20 11:27:49 2020 +0200 +++ b/stress-tester/src/test/java/com/passus/st/emitter/EmitterConfiguratorTest.java Wed May 20 13:50:13 2020 +0200 @@ -44,9 +44,9 @@ " collectMetrics: true\n" + " sessionMapper: '2.2.2.2:80->2.2.2.2:90'\n" + " timeouts: \n" + - " connect: 1\n" + - " read: 2\n" + - " disconnect: 3\n"; + " connect: 1s\n" + + " read: 2m\n" + + " disconnect: 3ms\n"; ConfigurationContext context = new ConfigurationContextImpl(); processConfig(configStr, context); @@ -60,8 +60,8 @@ assertSame(defaultEmitters, emitter); Timeouts timeouts = emitter.getTimeouts(); - assertEquals(1L, timeouts.getConnectionTimeout()); - assertEquals(2L, timeouts.getReadTimeout()); + assertEquals(1000L, timeouts.getConnectionTimeout()); + assertEquals(120000L, timeouts.getReadTimeout()); assertEquals(3L, timeouts.getDisconnectTimeout()); }