changeset 890:688a28cd5792

TestJob - bugfixes
author Devel 1
date Mon, 26 Mar 2018 16:02:15 +0200
parents 05a158902216
children 75051c952983
files stress-tester/src/main/java/com/passus/st/job/TestJob.java
diffstat 1 files changed, 52 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/job/TestJob.java	Mon Mar 26 14:41:30 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/job/TestJob.java	Mon Mar 26 16:02:15 2018 +0200
@@ -12,9 +12,7 @@
 import com.passus.st.emitter.Emitter;
 import com.passus.st.emitter.PassThroughSessionMapper;
 import com.passus.st.emitter.nio.NioEmitter;
-import com.passus.st.metric.MetricSource;
 import com.passus.st.metric.MetricsCollector;
-import com.passus.st.metric.ScheduledMetricsCollector;
 import com.passus.st.source.EventSource;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -85,57 +83,19 @@
         this.metricsCollector = metricsCollector;
     }
 
-    private void prepare() {
-        LOGGER.debug("Preparing job...");
-        if (defaultEmitter == null) {
-            if (emitters.isEmpty()) {
-                defaultEmitter = new NioEmitter();
-                defaultEmitter.setSessionMapper(new PassThroughSessionMapper());
-                emitters.add(defaultEmitter);
-            } else {
-                defaultEmitter = emitters.get(0);
-            }
-        }
-
-        if (metricsCollector != null) {
-            emitters.forEach(emitter -> {
-                if (emitter.isCollectMetrics()) {
-                    metricsCollector.register(emitter);
-                }
-            });
-        }
-
-        clients.forEach(client -> {
-            if (client.getEmitter() == null) {
-                client.setEmitter(defaultEmitter);
-            }
-
-            if (httpClientListener != null
-                    && !httpClientListener.isEmpty()
-                    && client instanceof HttpClient) {
-                httpClientListener.forEach(((HttpClient) client)::addListener);
-            }
-
-            if (client.isCollectMetrics()) {
-                if (metricsCollector != null) {
-                    metricsCollector.register(client);
-                }
-            }
-        });
-    }
-
     @Override
     public void start() {
-        prepare();
         if (metricsCollector != null) {
             metricsCollector.start();
         }
         emitters.forEach(Emitter::start);
         clients.forEach(Client::start);
+        eventSources.forEach(EventSource::start);
     }
 
     @Override
     public void stop() {
+        eventSources.forEach(EventSource::stop);
         clients.forEach(Client::stop);
         emitters.forEach(Emitter::stop);
 
@@ -174,6 +134,7 @@
     public static TestJob create(ConfigurationContext context) {
         Assert.notNull(context, "context");
         TestJob testJob = new TestJob();
+
         List<EventSource> cfgEventSources = (List<EventSource>) context.get(EVENT_SOURCE_SOURCES);
         populateIfNotNull(cfgEventSources, testJob.eventSources);
 
@@ -182,10 +143,59 @@
 
         List<Emitter> cfgEmitters = (List<Emitter>) context.get(EMITTER_EMITTERS);
         populateIfNotNull(cfgEmitters, testJob.emitters);
+
         testJob.defaultEmitter = (Emitter) context.get(EMITTER_DEFAULT_EMITTER);
 
         testJob.metricsCollector = context.get(METRICS_COLLECTOR, MetricsCollector.class);
 
+        testJob.prepare(context);
+
         return testJob;
     }
+
+    public void prepare(ConfigurationContext context) {
+        LOGGER.debug("Preparing job...");
+        if (defaultEmitter == null) {
+            if (emitters.isEmpty()) {
+                defaultEmitter = new NioEmitter();
+                defaultEmitter.setSessionMapper(new PassThroughSessionMapper());
+                emitters.add(defaultEmitter);
+            } else {
+                defaultEmitter = emitters.get(0);
+            }
+        }
+
+        emitters.forEach(emitter -> {
+            if (metricsCollector != null) {
+                if (emitter.isCollectMetrics()) {
+                    metricsCollector.register(emitter);
+                }
+            }
+        });
+
+        clients.forEach(client -> {
+            if (client.getEmitter() == null) {
+                client.setEmitter(defaultEmitter);
+            }
+
+            if (httpClientListener != null
+                    && !httpClientListener.isEmpty()
+                    && client instanceof HttpClient) {
+                httpClientListener.forEach(((HttpClient) client)::addListener);
+            }
+
+            if (metricsCollector != null) {
+                if (client.isCollectMetrics()) {
+                    metricsCollector.register(client);
+                }
+            }
+        });
+
+        // TODO: co z wieloma klientami??
+        Client firstClient = clients.get(0);
+        eventSources.forEach(src -> {
+            src.setHandler(firstClient);
+        });
+    }
+
 }