From dff294ed75f2499bf51196b242cc9715d5ca7713 Mon Sep 17 00:00:00 2001 From: Zheng Wang <18031031@qq.com> Date: Tue, 18 Aug 2020 16:41:12 +0800 Subject: [PATCH 1/5] HBASE-24894 [Flakey Test] TestStochasticLoadBalancer.testMoveCostMultiplier --- .../hbase/master/balancer/TestStochasticLoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java index 4cb92a2b3187..5967dfa60f9a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java @@ -297,7 +297,7 @@ public void testMoveCostMultiplier() throws Exception { //In offpeak hours, the multiplier of move cost should be lower conf.setInt("hbase.offpeak.start.hour",0); - conf.setInt("hbase.offpeak.end.hour",23); + conf.setInt("hbase.offpeak.end.hour",24); costFunction = new StochasticLoadBalancer.MoveCostFunction(conf); costFunction.init(cluster); costFunction.cost(); From cabf7f14ca10aba7bc983f6acdf4e3fe44b017c1 Mon Sep 17 00:00:00 2001 From: Zheng Wang <18031031@qq.com> Date: Wed, 19 Aug 2020 15:39:46 +0800 Subject: [PATCH 2/5] use EnvironmentEdge to fix it --- .../hbase/master/balancer/TestStochasticLoadBalancer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java index 5967dfa60f9a..dd526dd5a795 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java @@ -52,6 +52,7 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -297,7 +298,9 @@ public void testMoveCostMultiplier() throws Exception { //In offpeak hours, the multiplier of move cost should be lower conf.setInt("hbase.offpeak.start.hour",0); - conf.setInt("hbase.offpeak.end.hour",24); + conf.setInt("hbase.offpeak.end.hour",23); + //Set a fixed time which hour is 14, so it will always in offpeak + EnvironmentEdgeManager.injectEdge(() -> 1597820400000l); costFunction = new StochasticLoadBalancer.MoveCostFunction(conf); costFunction.init(cluster); costFunction.cost(); From c09ce1d0b00fad6bc22bae8c42110ac86497d3fd Mon Sep 17 00:00:00 2001 From: Zheng Wang <18031031@qq.com> Date: Wed, 19 Aug 2020 16:30:23 +0800 Subject: [PATCH 3/5] fix checkstyle issue --- .../hbase/master/balancer/TestStochasticLoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java index dd526dd5a795..a6e83fef114d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java @@ -300,7 +300,7 @@ public void testMoveCostMultiplier() throws Exception { conf.setInt("hbase.offpeak.start.hour",0); conf.setInt("hbase.offpeak.end.hour",23); //Set a fixed time which hour is 14, so it will always in offpeak - EnvironmentEdgeManager.injectEdge(() -> 1597820400000l); + EnvironmentEdgeManager.injectEdge(() -> 1597820400000L); costFunction = new StochasticLoadBalancer.MoveCostFunction(conf); costFunction.init(cluster); costFunction.cost(); From cc011261bff868f46dc25722aa11f82443b0472d Mon Sep 17 00:00:00 2001 From: Zheng Wang <18031031@qq.com> Date: Thu, 20 Aug 2020 15:15:45 +0800 Subject: [PATCH 4/5] a bit comment correct --- .../hbase/master/balancer/TestStochasticLoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java index a6e83fef114d..620a7f1f3b24 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java @@ -299,7 +299,7 @@ public void testMoveCostMultiplier() throws Exception { //In offpeak hours, the multiplier of move cost should be lower conf.setInt("hbase.offpeak.start.hour",0); conf.setInt("hbase.offpeak.end.hour",23); - //Set a fixed time which hour is 14, so it will always in offpeak + //Set a fixed time which hour is 15, so it will always in offpeak EnvironmentEdgeManager.injectEdge(() -> 1597820400000L); costFunction = new StochasticLoadBalancer.MoveCostFunction(conf); costFunction.init(cluster); From 92a493586bdd3d34795d31f2961f10f9cb261262 Mon Sep 17 00:00:00 2001 From: Zheng Wang <18031031@qq.com> Date: Sat, 22 Aug 2020 13:29:52 +0800 Subject: [PATCH 5/5] get special hour by a new way that use special time with delta --- .../master/balancer/TestStochasticLoadBalancer.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java index 620a7f1f3b24..cec988520c33 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancer.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Queue; import java.util.Set; +import java.util.TimeZone; import java.util.TreeMap; import org.apache.hadoop.conf.Configuration; @@ -296,11 +297,14 @@ public void testMoveCostMultiplier() throws Exception { assertEquals(StochasticLoadBalancer.MoveCostFunction.DEFAULT_MOVE_COST, costFunction.getMultiplier(), 0.01); - //In offpeak hours, the multiplier of move cost should be lower + // In offpeak hours, the multiplier of move cost should be lower conf.setInt("hbase.offpeak.start.hour",0); conf.setInt("hbase.offpeak.end.hour",23); - //Set a fixed time which hour is 15, so it will always in offpeak - EnvironmentEdgeManager.injectEdge(() -> 1597820400000L); + // Set a fixed time which hour is 15, so it will always in offpeak + // See HBASE-24898 for more info of the calculation here + long deltaFor15 = TimeZone.getDefault().getRawOffset() - 28800000; + long timeFor15 = 1597907081000L - deltaFor15; + EnvironmentEdgeManager.injectEdge(() -> timeFor15); costFunction = new StochasticLoadBalancer.MoveCostFunction(conf); costFunction.init(cluster); costFunction.cost();