HBASE-24894 [Flakey Test] TestStochasticLoadBalancer.testMoveCostMultiplier

Closes #2270

Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Zheng Wang 2020-08-30 20:08:28 +05:30 committed by Viraj Jasani
parent 31e47af665
commit 041debde02
No known key found for this signature in database
GPG Key ID: B3D6C0B41C8ADFD5
1 changed files with 14 additions and 1 deletions

View File

@ -32,6 +32,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Queue; import java.util.Queue;
import java.util.TimeZone;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -53,7 +54,9 @@ import org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer.ServerLoca
import org.apache.hadoop.hbase.testclassification.FlakeyTests; import org.apache.hadoop.hbase.testclassification.FlakeyTests;
import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdge;
import org.junit.Ignore; import org.junit.Ignore;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@ -237,9 +240,19 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
assertEquals(StochasticLoadBalancer.MoveCostFunction.DEFAULT_MOVE_COST, assertEquals(StochasticLoadBalancer.MoveCostFunction.DEFAULT_MOVE_COST,
costFunction.getMultiplier(), 0.01); 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.start.hour",0);
conf.setInt("hbase.offpeak.end.hour",23); conf.setInt("hbase.offpeak.end.hour",23);
// 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;
final long timeFor15 = 1597907081000L - deltaFor15;
EnvironmentEdgeManager.injectEdge(new EnvironmentEdge() {
@Override
public long currentTime() {
return timeFor15;
}
});
costFunction = new StochasticLoadBalancer.MoveCostFunction(conf); costFunction = new StochasticLoadBalancer.MoveCostFunction(conf);
costFunction.init(cluster); costFunction.init(cluster);
costFunction.cost(); costFunction.cost();