changeset 891:75051c952983

HttpClient - dispatcher - config, validator, transformer
author Devel 1
date Tue, 27 Mar 2018 14:24:26 +0200
parents 688a28cd5792
children c8b4ff11d1c0
files stress-tester/src/main/java/com/passus/st/client/http/HttpClient.java stress-tester/src/main/java/com/passus/st/config/TestJobConfigurator.java
diffstat 2 files changed, 51 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpClient.java	Mon Mar 26 16:02:15 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpClient.java	Tue Mar 27 14:24:26 2018 +0200
@@ -1,14 +1,18 @@
 package com.passus.st.client.http;
 
 import com.passus.commons.Assert;
+import com.passus.commons.ConversionException;
 import com.passus.commons.annotations.Plugin;
 import com.passus.commons.service.ServiceException;
 import com.passus.config.Configuration;
 import com.passus.config.ConfigurationContext;
+import com.passus.config.ValueTransformer;
 import com.passus.config.annotations.NodeDefinitionCreate;
+import static com.passus.config.schema.ConfigurationSchemaBuilder.*;
 import com.passus.config.schema.DynaKeyValueVaryListNodeDefinition;
 import com.passus.config.schema.NodeDefinition;
 import com.passus.config.schema.NodeDefinitionCreator;
+import com.passus.config.validation.EnumValidator;
 import com.passus.config.validation.LongValidator;
 import com.passus.st.client.Client;
 import com.passus.st.client.Event;
@@ -23,11 +27,13 @@
 import org.apache.logging.log4j.Logger;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
-import static com.passus.config.schema.ConfigurationSchemaBuilder.*;
 
 /**
  * @author Mirosław Hawrot
@@ -224,6 +230,7 @@
         setWorkersNum(config.getInteger("workers", DEFAULT_WORKERS_NUM));
         connectPartialSession = config.getBoolean("connectPartialSession", DEFAULT_CONNECT_PARTIAL_SESSION);
         collectMetrics = config.getBoolean("collectMetrics", DEFAULT_COLLECT_METRICS);
+        dispatcher = (HttpClientWorkerDispatcher) config.get("dispatcher", null);
     }
 
     @Override
@@ -341,8 +348,42 @@
 
     }
 
+    private static class DispatcherTransformer implements ValueTransformer {
+
+        private static final DispatcherTransformer INSTANCE = new DispatcherTransformer();
+
+        @Override
+        public HttpClientWorkerDispatcher transform(Object obj) throws ConversionException {
+            if (obj == null) {
+                return null;
+            }
+            if (obj instanceof String) {
+                String s = (String) obj;
+                switch (s) {
+                    case "source":
+                        return new HttpSourceNameAwareClientWorkerDispatcher();
+                    case "parallel":
+                        return null;
+                    default:
+                        throw new ConversionException("Unknown dispatcher type: " + s);
+                }
+            }
+            throw new ConversionException("Invalid type.");
+        }
+
+        @Override
+        public Object reverseTransform(Object obj) throws ConversionException {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+    }
+
     public static class HttpClientNodeDefCreator implements NodeDefinitionCreator {
 
+        private static final Set<String> DISPATCHERS = new HashSet<>(Arrays.asList(
+                "source", "parallel"
+        ));
+
         @Override
         public NodeDefinition create() {
             return mapDef(
@@ -351,6 +392,10 @@
                     tupleDef("workers", valueDefInteger()
                             .addValueValidator(LongValidator.GREATER_ZERO)
                     ).setRequired(false),
+                    tupleDef("dispatcher", valueDef()
+                            .addValueValidator(new EnumValidator(DISPATCHERS, false))
+                            .setTransformer(DispatcherTransformer.INSTANCE)
+                    ).setRequired(false),
                     tupleDef("filters",
                             HttpFiltersNodeDefinitionCreator.createFiltersList(true)
                     ).setRequired(false),
--- a/stress-tester/src/main/java/com/passus/st/config/TestJobConfigurator.java	Mon Mar 26 16:02:15 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/config/TestJobConfigurator.java	Tue Mar 27 14:24:26 2018 +0200
@@ -109,6 +109,11 @@
 
                 Configuration subConfig = config.subConfiguration(keyName);
                 DomainConfigurator configurator = entry.getValue();
+                // TODO: enable validation
+//                configurator.validate(config, errors, context);
+//                if (errors.hasError()) {
+//                    break;
+//                }
                 configurator.configure(subConfig, errors, context);
                 if (errors.hasError()) {
                     break;