changeset 1120:7f40755547ad

TestJob - metrics appender configuration bugfix
author Devel 2
date Wed, 03 Jun 2020 09:09:42 +0200
parents 9bae1220fef2
children b45826b35c6e
files stress-tester/src/main/java/com/passus/st/job/TestJob.java stress-tester/src/test/java/com/passus/st/config/MetricsConfiguratorTest.java
diffstat 2 files changed, 28 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/job/TestJob.java	Tue Jun 02 11:46:12 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/job/TestJob.java	Wed Jun 03 09:09:42 2020 +0200
@@ -1,16 +1,22 @@
 package com.passus.st.job;
 
 import com.passus.commons.Assert;
+import com.passus.commons.service.Service;
 import com.passus.config.ConfigurationContext;
 import com.passus.filter.ValueExtractor;
-import com.passus.st.client.*;
-import com.passus.st.filter.FlowFilter;
+import com.passus.st.client.ClientListener;
+import com.passus.st.client.FlowExecutor;
+import com.passus.st.client.MultipleClientListener;
+import com.passus.st.client.SourceNameAwareFlowWorkerDispatcher;
 import com.passus.st.client.http.ReporterDestination;
 import com.passus.st.client.http.filter.HttpVarsFilter;
 import com.passus.st.emitter.Emitter;
 import com.passus.st.emitter.PassThroughSessionMapper;
 import com.passus.st.emitter.nio.NioEmitter;
+import com.passus.st.filter.FlowFilter;
 import com.passus.st.metric.MetricSource;
+import com.passus.st.metric.MetricsCollectionAppender;
+import com.passus.st.metric.MetricsCollectionHandler;
 import com.passus.st.metric.MetricsCollector;
 import com.passus.st.source.EventSource;
 import com.passus.st.utils.ConfigurationContextConsts;
@@ -104,6 +110,15 @@
 
         if (metricsCollector != null) {
             metricsCollector.flush(true);
+
+            List<MetricsCollectionHandler> handlers = metricsCollector.getHandlers();
+            if (handlers != null) {
+                for (MetricsCollectionHandler handler : handlers) {
+                    if (handler instanceof Service) {
+                        ((Service) handler).stop();
+                    }
+                }
+            }
         }
     }
 
@@ -175,6 +190,16 @@
             if (flowExecutor.isCollectMetrics()) {
                 metricsCollector.register(flowExecutor);
             }
+
+            List<MetricsCollectionAppender> appenders = context.get(METRICS_COLLECTION_APPENDERS);
+            if (appenders != null) {
+                appenders.forEach((a) -> {
+                    if (!a.isStarted()) {
+                        a.start();
+                    }
+                    metricsCollector.addHandler(a);
+                });
+            }
         }
 
         eventSources.forEach(src -> {
--- a/stress-tester/src/test/java/com/passus/st/config/MetricsConfiguratorTest.java	Tue Jun 02 11:46:12 2020 +0200
+++ b/stress-tester/src/test/java/com/passus/st/config/MetricsConfiguratorTest.java	Wed Jun 03 09:09:42 2020 +0200
@@ -58,7 +58,7 @@
         configurator.configure(config, errors, context);
         assertEquals(0, errors.getErrorCount());
 
-        List<MetricsCollectionAppender> appenders = (List<MetricsCollectionAppender>) context.get(METRICS_COLLECTION_APPENDERS);
+        List<MetricsCollectionAppender> appenders = context.get(METRICS_COLLECTION_APPENDERS);
         assertEquals(1, appenders.size());
 
         assertTrue(appenders.get(0) instanceof FileMetricsCollectionAppender);