You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by ka...@apache.org on 2019/03/15 18:45:56 UTC

[storm] 02/04: STORM-3344 clean up test code

This is an automated email from the ASF dual-hosted git repository.

kabhwan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/storm.git

commit 8a332e382e404d1341b09f7b77c74c5bbec43610
Author: Aaron Gresch <ag...@yahoo-inc.com>
AuthorDate: Fri Mar 15 10:33:30 2019 -0500

    STORM-3344 clean up test code
---
 .../scheduler/blacklist/BlacklistScheduler.java    |  2 +-
 .../scheduler/blacklist/FaultGenerateUtils.java    |  2 +-
 .../blacklist/TestBlacklistScheduler.java          | 22 ++++++++++++--------
 .../blacklist/TestUtilsForBlacklistScheduler.java  | 24 ++++++++++++++++------
 4 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/storm-server/src/main/java/org/apache/storm/scheduler/blacklist/BlacklistScheduler.java b/storm-server/src/main/java/org/apache/storm/scheduler/blacklist/BlacklistScheduler.java
index 1061a3f..54c10f9 100644
--- a/storm-server/src/main/java/org/apache/storm/scheduler/blacklist/BlacklistScheduler.java
+++ b/storm-server/src/main/java/org/apache/storm/scheduler/blacklist/BlacklistScheduler.java
@@ -155,7 +155,7 @@ public class BlacklistScheduler implements IScheduler {
 
         Set<Integer> newPorts = Sets.difference(supervisorPorts, cachedSupervisorPorts);
         if (newPorts.size() > 0) {
-            //add new ports to cached supervisor.  We need a modifiable set to allow removing ports later.
+            // add new ports to cached supervisor.  We need a modifiable set to allow removing ports later.
             Set<Integer> allPorts = new HashSet<>(newPorts);
             allPorts.addAll(cachedSupervisorPorts);
             cachedSupervisors.put(supervisorKey, allPorts);
diff --git a/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/FaultGenerateUtils.java b/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/FaultGenerateUtils.java
index c962039..9a34080 100644
--- a/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/FaultGenerateUtils.java
+++ b/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/FaultGenerateUtils.java
@@ -43,7 +43,7 @@ public class FaultGenerateUtils {
                     supervisors = TestUtilsForBlacklistScheduler.removeSupervisorFromSupervisors(supervisors, "sup-" + supervisor);
                 } else {
                     for (int slot : slots) {
-                        supervisors = TestUtilsForBlacklistScheduler.modifyPortFromSupervisors(supervisors, "sup-" + supervisor, slot, false);
+                        supervisors = TestUtilsForBlacklistScheduler.removePortFromSupervisors(supervisors, "sup-" + supervisor, slot);
                     }
                 }
             }
diff --git a/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/TestBlacklistScheduler.java b/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/TestBlacklistScheduler.java
index f55cbb1..96006b4 100644
--- a/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/TestBlacklistScheduler.java
+++ b/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/TestBlacklistScheduler.java
@@ -120,9 +120,11 @@ public class TestBlacklistScheduler {
         scheduler.prepare(config);
         scheduler.schedule(topologies, cluster);
 
-        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.modifyPortFromSupervisors(supMap, "sup-0", 0, false), TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
+        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removePortFromSupervisors(supMap,
+                "sup-0", 0), TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
         scheduler.schedule(topologies, cluster);
-        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.modifyPortFromSupervisors(supMap, "sup-0", 0, false), TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
+        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removePortFromSupervisors(supMap, "sup-0", 0),
+                TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
         scheduler.schedule(topologies, cluster);
         cluster = new Cluster(iNimbus, resourceMetrics, supMap, new HashMap<String, SchedulerAssignmentImpl>(), topologies, config);
         scheduler.schedule(topologies, cluster);
@@ -319,7 +321,8 @@ public class TestBlacklistScheduler {
         scheduler = bs;
         bs.prepare(config);
         bs.schedule(topologies,cluster);
-        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removeSupervisorFromSupervisors(supMap,"sup-0"),TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
+        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removeSupervisorFromSupervisors(supMap,"sup-0"),
+                TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
         for (int i = 0 ; i < 20 ; i++){
             bs.schedule(topologies,cluster);
         }
@@ -329,7 +332,8 @@ public class TestBlacklistScheduler {
         Assert.assertEquals(cached, bs.cachedSupervisors.keySet());
         cluster = new Cluster(iNimbus, resourceMetrics, supMap, new HashMap<String, SchedulerAssignmentImpl>(), topologies, config);
         bs.schedule(topologies,cluster);
-        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.modifyPortFromSupervisors(supMap,"sup-0",0, false),TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
+        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removePortFromSupervisors(supMap, "sup-0", 0),
+                TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
         for (int i = 0 ;i < 20 ; i++){
             bs.schedule(topologies, cluster);
         }
@@ -351,7 +355,7 @@ public class TestBlacklistScheduler {
 
         Map<String, TopologyDetails> topoMap = new HashMap<>();
         TopologyDetails topo1 = TestUtilsForBlacklistScheduler.getTopology("topo-1", config, 5,
-                15, 1, 1, currentTime - 2,true);
+                15, 1, 1, currentTime - 2, true);
         topoMap.put(topo1.getId(), topo1);
         Topologies topologies = new Topologies(topoMap);
 
@@ -363,15 +367,15 @@ public class TestBlacklistScheduler {
 
         // allow blacklist scheduler to cache the supervisor
         scheduler.schedule(topologies, cluster);
-        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.modifyPortFromSupervisors(supMap,
-                "sup-0",4, true),TestUtilsForBlacklistScheduler.assignmentMapToImpl(
+        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.addPortToSupervisors(supMap,
+                "sup-0", 4),TestUtilsForBlacklistScheduler.assignmentMapToImpl(
                         cluster.getAssignments()), topologies, config);
         // allow blacklist scheduler to cache the supervisor with an added port
         scheduler.schedule(topologies, cluster);
         // remove the port from the supervisor and make sure the blacklist scheduler can remove the port without
         // throwing an exception
-        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.modifyPortFromSupervisors(supMap,
-                "sup-0",4, false),TestUtilsForBlacklistScheduler.assignmentMapToImpl(
+        cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removePortFromSupervisors(supMap,
+                "sup-0", 4),TestUtilsForBlacklistScheduler.assignmentMapToImpl(
                         cluster.getAssignments()), topologies, config);
         scheduler.schedule(topologies, cluster);
     }
diff --git a/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/TestUtilsForBlacklistScheduler.java b/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/TestUtilsForBlacklistScheduler.java
index ded11d2..e226097 100644
--- a/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/TestUtilsForBlacklistScheduler.java
+++ b/storm-server/src/test/java/org/apache/storm/scheduler/blacklist/TestUtilsForBlacklistScheduler.java
@@ -67,7 +67,7 @@ public class TestUtilsForBlacklistScheduler {
         return retList;
     }
 
-    public static Map<String, SupervisorDetails> modifyPortFromSupervisors(Map<String, SupervisorDetails> supervisorDetailsMap, String supervisor, int port, boolean add) {
+    public static Map<String, SupervisorDetails> removePortFromSupervisors(Map<String, SupervisorDetails> supervisorDetailsMap, String supervisor, int port) {
         Map<String, SupervisorDetails> retList = new HashMap<String, SupervisorDetails>();
         for (Map.Entry<String, SupervisorDetails> supervisorDetailsEntry : supervisorDetailsMap.entrySet()) {
             String supervisorKey = supervisorDetailsEntry.getKey();
@@ -75,11 +75,23 @@ public class TestUtilsForBlacklistScheduler {
             Set<Integer> ports = new HashSet<>();
             ports.addAll(supervisorDetails.getAllPorts());
             if (supervisorKey.equals(supervisor)) {
-                if (add) {
-                    ports.add(port);
-                } else {
-                    ports.remove(port);
-                }
+                ports.remove(port);
+            }
+            SupervisorDetails sup = new SupervisorDetails(supervisorDetails.getId(), supervisorDetails.getHost(), null, (HashSet) ports, null);
+            retList.put(sup.getId(), sup);
+        }
+        return retList;
+    }
+
+    public static Map<String, SupervisorDetails> addPortToSupervisors(Map<String, SupervisorDetails> supervisorDetailsMap, String supervisor, int port) {
+        Map<String, SupervisorDetails> retList = new HashMap<String, SupervisorDetails>();
+        for (Map.Entry<String, SupervisorDetails> supervisorDetailsEntry : supervisorDetailsMap.entrySet()) {
+            String supervisorKey = supervisorDetailsEntry.getKey();
+            SupervisorDetails supervisorDetails = supervisorDetailsEntry.getValue();
+            Set<Integer> ports = new HashSet<>();
+            ports.addAll(supervisorDetails.getAllPorts());
+            if (supervisorKey.equals(supervisor)) {
+                ports.add(port);
             }
             SupervisorDetails sup = new SupervisorDetails(supervisorDetails.getId(), supervisorDetails.getHost(), null, (HashSet) ports, null);
             retList.put(sup.getId(), sup);