kaisun2000 commented on a change in pull request #1227:
URL: https://github.com/apache/helix/pull/1227#discussion_r467313142



##########
File path: helix-core/src/test/java/org/apache/helix/TestHelper.java
##########
@@ -847,4 +850,161 @@ public static void printZkListeners(HelixZkClient client) 
throws Exception {
     }
     System.out.println("}");
   }
+
+  // Thread dump related utility function
+  private static ThreadGroup getRootThreadGroup() {
+    ThreadGroup candidate = Thread.currentThread().getThreadGroup();
+    while (candidate.getParent() != null) {
+      candidate = candidate.getParent();
+    }
+    return candidate;
+  }
+
+  public static List<Thread> getAllThreads() {
+    ThreadGroup rootThreadGroup = getRootThreadGroup();
+    Thread[] threads = new Thread[32];
+    int count = rootThreadGroup.enumerate(threads);
+    while (count == threads.length) {
+      threads = new Thread[threads.length * 2];
+      count = rootThreadGroup.enumerate(threads);
+    }
+    return Arrays.asList(Arrays.copyOf(threads, count));
+  }
+
+  static public enum ThreadCategory {
+    ZkServer("zookeeper server threads", 4, 100,
+        new String[]{"SessionTracker", "NIOServerCxn", "SyncThread:", 
"ProcessThread"}),
+    ZkSession("zkclient/zooKeeper session threads", 12, 12,
+        new String[] {"ZkClient-EventThread", "ZkClient-AsyncCallback", 
"-EventThread", "-SendThread"}),
+    ForkJoin( "fork join pool threads", 2, 10, new String[]{"ForkJoinPool"}),
+    Timer( "timer threads", 0, 2, new String[]{"time"}),
+    TaskStateModel("TaskStateModel threads", 0, 0, new 
String[]{"TaskStateModel"}),
+    Other("Other threads", 0, 3, new String[]{""});
+
+    private String _description;
+    private List<String> _pattern;
+    private int _warningLimit;
+    private int _limit;
+
+    public String getDescription() {
+      return _description;
+    }
+
+    public Predicate<String> getMatchPred() {
+      if (this.name() != ThreadCategory.Other.name()) {
+        Predicate<String> pred = target -> {
+          for (String p : _pattern) {
+            if (target.toLowerCase().contains(p.toLowerCase())) {
+              return true;
+            }
+          }
+          return false;
+        };
+        return pred;
+      }
+
+      List<Predicate<String>> predicateList = new ArrayList<>();
+      for (ThreadCategory threadCategory : ThreadCategory.values()) {
+        if (threadCategory == ThreadCategory.Other) {
+          continue;
+        }
+        predicateList.add(threadCategory.getMatchPred());
+      }
+      Predicate<String> pred = target -> {
+        for (Predicate<String> p : predicateList) {
+          if (p.test(target)) {
+            return false;
+          }
+        }
+        return true;
+      };
+
+      return pred;
+    }
+
+    public int getWarningLimit() {
+      return _warningLimit;
+    }
+
+    public int getLimit() {
+      return _limit;
+    }
+
+    private ThreadCategory(String description, int warningLimit,  int limit, 
String[] patterns ) {
+      _description = description;
+      _pattern = Arrays.asList(patterns);
+      _warningLimit = warningLimit;
+      _limit = limit;
+    }
+  }
+
+  public static boolean afterClassCheck(String classname) {
+    // step 1: get all active threads
+    List<Thread> threads = TestHelper.getAllThreads();
+    System.out.println(classname + " has active threads cnt:" + 
threads.size());
+
+
+    // step 2: caegorize threads

Review comment:
       fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to