You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by ra...@apache.org on 2026/06/28 14:19:05 UTC

(storm) branch isolation-scheduler-visible-for-testing created (now f6ce363a9)

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

reiabreu pushed a change to branch isolation-scheduler-visible-for-testing
in repository https://gitbox.apache.org/repos/asf/storm.git


      at f6ce363a9 scheduler: replace reflection with @VisibleForTesting in IsolationSchedulerTest

This branch includes the following new commits:

     new f6ce363a9 scheduler: replace reflection with @VisibleForTesting in IsolationSchedulerTest

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(storm) 01/01: scheduler: replace reflection with @VisibleForTesting in IsolationSchedulerTest

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

reiabreu pushed a commit to branch isolation-scheduler-visible-for-testing
in repository https://gitbox.apache.org/repos/asf/storm.git

commit f6ce363a9230bd8eb395214579edfd772d746b7c
Author: Rui Abreu <ru...@gmail.com>
AuthorDate: Sun Jun 28 15:18:54 2026 +0100

    scheduler: replace reflection with @VisibleForTesting in IsolationSchedulerTest
    
    Make IsolationScheduler#hostAssignableSlots package-private and annotate
    it with @VisibleForTesting so the test can call it directly instead of
    using reflection, which is fragile under refactoring.
    
    Co-Authored-By: Claude Sonnet 4.6 <no...@anthropic.com>
---
 .../org/apache/storm/scheduler/IsolationScheduler.java  |  4 +++-
 .../apache/storm/scheduler/IsolationSchedulerTest.java  | 17 ++++-------------
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/storm-server/src/main/java/org/apache/storm/scheduler/IsolationScheduler.java b/storm-server/src/main/java/org/apache/storm/scheduler/IsolationScheduler.java
index 4ec48b554..0e2c283a6 100644
--- a/storm-server/src/main/java/org/apache/storm/scheduler/IsolationScheduler.java
+++ b/storm-server/src/main/java/org/apache/storm/scheduler/IsolationScheduler.java
@@ -26,6 +26,7 @@ import java.util.TreeMap;
 import org.apache.commons.lang3.Validate;
 import org.apache.storm.DaemonConfig;
 import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.shade.com.google.common.annotations.VisibleForTesting;
 import org.apache.storm.utils.Utils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -309,7 +310,8 @@ public class IsolationScheduler implements IScheduler {
     //                                                         need fewer evictions
     //   3. (tertiary)  host name,                 ascending  — deterministic order
     //                                                         for testability
-    private LinkedList<HostAssignableSlots> hostAssignableSlots(Cluster cluster) {
+    @VisibleForTesting
+    LinkedList<HostAssignableSlots> hostAssignableSlots(Cluster cluster) {
         List<WorkerSlot> assignableSlots = cluster.getAssignableSlots();
         Map<String, List<WorkerSlot>> hostAssignableSlots = new HashMap<String, List<WorkerSlot>>();
         Map<String, Integer> hostFreeSlotCounts = new HashMap<String, Integer>();
diff --git a/storm-server/src/test/java/org/apache/storm/scheduler/IsolationSchedulerTest.java b/storm-server/src/test/java/org/apache/storm/scheduler/IsolationSchedulerTest.java
index 3fbc43e15..6c8cd2464 100644
--- a/storm-server/src/test/java/org/apache/storm/scheduler/IsolationSchedulerTest.java
+++ b/storm-server/src/test/java/org/apache/storm/scheduler/IsolationSchedulerTest.java
@@ -12,7 +12,6 @@
 
 package org.apache.storm.scheduler;
 
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -50,14 +49,6 @@ public class IsolationSchedulerTest {
                            topologies, new HashMap<String, Object>());
     }
 
-    @SuppressWarnings("unchecked")
-    private static LinkedList<IsolationScheduler.HostAssignableSlots> hostAssignableSlots(
-        IsolationScheduler scheduler, Cluster cluster) throws Exception {
-        Method method = IsolationScheduler.class.getDeclaredMethod("hostAssignableSlots", Cluster.class);
-        method.setAccessible(true);
-        return (LinkedList<IsolationScheduler.HostAssignableSlots>) method.invoke(scheduler, cluster);
-    }
-
     private static List<String> hostOrder(LinkedList<IsolationScheduler.HostAssignableSlots> slots) {
         List<String> hosts = new ArrayList<>();
         for (IsolationScheduler.HostAssignableSlots slot : slots) {
@@ -67,7 +58,7 @@ public class IsolationSchedulerTest {
     }
 
     @Test
-    public void hostAssignableSlots_prefersHostWithMoreFreeSlots() throws Exception {
+    public void hostAssignableSlots_prefersHostWithMoreFreeSlots() {
         Map<String, SupervisorDetails> supervisors = new HashMap<>();
         supervisors.put("sup-busy", mkSupervisor("sup-busy", "host-busy", 2));
         supervisors.put("sup-free", mkSupervisor("sup-free", "host-free", 2));
@@ -83,7 +74,7 @@ public class IsolationSchedulerTest {
                        Collections.singletonList(filler.getExecutors().iterator().next()));
 
         LinkedList<IsolationScheduler.HostAssignableSlots> ranked =
-            hostAssignableSlots(new IsolationScheduler(), cluster);
+            new IsolationScheduler().hostAssignableSlots(cluster);
 
         assertEquals(2, ranked.size());
         assertEquals("host-free", ranked.get(0).getHostName());
@@ -94,7 +85,7 @@ public class IsolationSchedulerTest {
     }
 
     @Test
-    public void hostAssignableSlots_breaksTiesByHostName() throws Exception {
+    public void hostAssignableSlots_breaksTiesByHostName() {
         Map<String, SupervisorDetails> supervisors = new HashMap<>();
         supervisors.put("sup-a", mkSupervisor("sup-a", "host-aaa", 2));
         supervisors.put("sup-b", mkSupervisor("sup-b", "host-bbb", 2));
@@ -102,7 +93,7 @@ public class IsolationSchedulerTest {
         Cluster cluster = mkCluster(supervisors, new Topologies());
 
         LinkedList<IsolationScheduler.HostAssignableSlots> ranked =
-            hostAssignableSlots(new IsolationScheduler(), cluster);
+            new IsolationScheduler().hostAssignableSlots(cluster);
 
         assertEquals(2, ranked.size());
         assertEquals(2, ranked.get(0).getWorkerSlots().size());