From 3a1d467f1d9382f188650e27d04bcc1609b6a3b9 Mon Sep 17 00:00:00 2001 From: Yang Chen <583334298@qq.com> Date: Thu, 19 Aug 2021 11:38:08 +0800 Subject: [PATCH] Clean shared state pollution to avoid flaky tests. --- .../java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java | 5 +++++ .../org/apache/hadoop/hbase/monitoring/TestTaskMonitor.java | 1 + 2 files changed, 6 insertions(+) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java index d2edaa8b1d8..33d00a5c289 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java @@ -243,6 +243,11 @@ public class TaskMonitor { } } + public synchronized void purgeAllTasks() { + tasks.clear(); + rpcTasks.clear(); + } + /** * This class encapsulates an object as well as a weak reference to a proxy * that passes through calls to that object. In art form: diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestTaskMonitor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestTaskMonitor.java index c9a9fc98069..a7711d8a763 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestTaskMonitor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestTaskMonitor.java @@ -142,6 +142,7 @@ public class TestTaskMonitor { } assertEquals("RPC Tasks have been purged!", RPCTaskNums, remainRPCTask); tm.shutdown(); + tm.purgeAllTasks(); } @Test