changeset 910:82931aa4de74

refactoring
author Devel 1
date Thu, 19 Apr 2018 10:29:42 +0200
parents 57bec9c38e0d
children 7f83606b0a27
files stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java stress-tester/src/main/java/com/passus/st/config/TestJobConfigurator.java stress-tester/src/main/java/com/passus/st/job/TestJob.java
diffstat 3 files changed, 23 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java	Thu Apr 19 09:43:06 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java	Thu Apr 19 10:29:42 2018 +0200
@@ -2,8 +2,10 @@
 
 import com.passus.commons.metric.Metric;
 import com.passus.config.Configuration;
+import com.passus.config.ConfigurationContext;
 import com.passus.config.YamlConfigurationReader;
 import com.passus.config.validation.Errors;
+import com.passus.st.config.TestJobConfigurator;
 import com.passus.st.job.TestJob;
 import com.passus.st.metric.MetricsCollector;
 import com.passus.st.metric.SummaryMetricsCollectionHandler;
@@ -55,7 +57,9 @@
             File configFile = new File(clArgs[0]);
             Configuration config = YamlConfigurationReader.readFromFile(configFile);
 
-            TestJob testJob = TestJob.create(config, errors);
+            ConfigurationContext context = ConfigurationContext.create();
+            TestJobConfigurator testJobConfigurator = new TestJobConfigurator();
+            testJobConfigurator.configure(config, errors, context);
             if (errors.hasError()) {
                 StringBuilder sb = new StringBuilder();
 
@@ -65,6 +69,7 @@
 
                 cliHelper.printError(sb.toString());
             }
+            TestJob testJob = TestJob.create(context);
 
             final long startTime = System.currentTimeMillis();
             MetricsCollector metricsCollector = testJob.getMetricsCollector();
--- a/stress-tester/src/main/java/com/passus/st/config/TestJobConfigurator.java	Thu Apr 19 09:43:06 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/config/TestJobConfigurator.java	Thu Apr 19 10:29:42 2018 +0200
@@ -18,7 +18,7 @@
 /**
  * @author Mirosław Hawrot
  */
-public class TestJobConfigurator implements Configurator {
+public class TestJobConfigurator {
 
     private static final Logger LOGGER = LogManager.getLogger(TestJobConfigurator.class);
 
@@ -30,7 +30,7 @@
         this(null);
     }
 
-    public TestJobConfigurator(BiPredicate<String, DomainConfigurator> filter) {
+    protected TestJobConfigurator(BiPredicate<String, DomainConfigurator> filter) {
         this.filter = filter;
     }
 
@@ -79,7 +79,6 @@
         return domainsConfigurator;
     }
 
-    @Override
     public void validate(Configuration config, Errors errors, ConfigurationContext context) {
         Map<String, DomainConfigurator> configurators = getDomainsConfigurator(config, errors);
         if (!errors.hasError()) {
@@ -99,7 +98,6 @@
         }
     }
 
-    @Override
     public void configure(Configuration config, Errors errors, ConfigurationContext context) {
         Map<String, DomainConfigurator> configurators = getDomainsConfigurator(config, errors);
         if (!errors.hasError()) {
@@ -123,4 +121,19 @@
         }
     }
 
+    public void destroy(Configuration config, Errors errors, ConfigurationContext context) {
+        Map<String, DomainConfigurator> configurators = getDomainsConfigurator(config, errors);
+        if (!errors.hasError()) {
+            for (Entry<String, DomainConfigurator> entry : configurators.entrySet()) {
+                String keyName = entry.getKey();
+                if (filter != null && filter.test(keyName, entry.getValue())) {
+                    continue;
+                }
+
+                Configuration subConfig = config.subConfiguration(keyName);
+                DomainConfigurator configurator = entry.getValue();
+                configurator.destroy(subConfig, context);
+            }
+        }
+    }
 }
--- a/stress-tester/src/main/java/com/passus/st/job/TestJob.java	Thu Apr 19 09:43:06 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/job/TestJob.java	Thu Apr 19 10:29:42 2018 +0200
@@ -125,19 +125,6 @@
         }
     }
 
-    @SuppressWarnings("unchecked")
-    public static TestJob create(Configuration config, Errors errors) {
-        Assert.notNull(config, "config");
-        TestJobConfigurator configurator = new TestJobConfigurator();
-        ConfigurationContext context = ConfigurationContext.create();
-        configurator.configure(config, errors, context);
-        if (errors.hasError()) {
-            return null;
-        }
-
-        return create(context);
-    }
-
     public static TestJob create(ConfigurationContext context) {
         Assert.notNull(context, "context");
         TestJob testJob = new TestJob();