Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*/
package org.apache.hadoop.hbase.master.balancer;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
Expand All @@ -36,10 +36,8 @@
import org.apache.hadoop.hbase.namequeues.response.NamedQueueGetResponse;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos;
Expand All @@ -48,13 +46,10 @@
/**
* Test BalancerDecision ring buffer using namedQueue interface
*/
@Category({ MasterTests.class, MediumTests.class })
@Tag(MasterTests.TAG)
@Tag(MediumTests.TAG)
public class TestBalancerDecision extends StochasticBalancerTestBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBalancerDecision.class);

@Test
public void testBalancerDecisions() {
conf.setBoolean("hbase.master.balancer.decision.buffer.enabled", true);
Expand All @@ -79,7 +74,7 @@ public void testBalancerDecisions() {
(Map) mockClusterServersWithTables(servers);
List<RegionPlan> plans = loadBalancer.balanceCluster(LoadOfAllTable);
boolean emptyPlans = plans == null || plans.isEmpty();
Assert.assertTrue(emptyPlans || needsBalanceIdleRegion(mockCluster));
assertTrue(emptyPlans || needsBalanceIdleRegion(mockCluster));
}
}
final NamedQueueGetRequest namedQueueGetRequest = new NamedQueueGetRequest();
Expand All @@ -93,7 +88,7 @@ public void testBalancerDecisions() {
MasterProtos.BalancerDecisionsResponse response = MasterProtos.BalancerDecisionsResponse
.newBuilder().addAllBalancerDecision(balancerDecisions).build();
List<LogEntry> balancerDecisionRecords = ProtobufUtil.getBalancerDecisionEntries(response);
Assert.assertTrue(balancerDecisionRecords.size() > 160);
assertTrue(balancerDecisionRecords.size() > 160);
} finally {
// reset config
conf.unset(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
*/
package org.apache.hadoop.hbase.master.balancer;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.List;
import java.util.Map;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.LogEntry;
Expand All @@ -34,10 +36,8 @@
import org.apache.hadoop.hbase.namequeues.response.NamedQueueGetResponse;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos;
Expand All @@ -46,13 +46,10 @@
/**
* Test BalancerRejection ring buffer using namedQueue interface
*/
@Category({ MasterTests.class, MediumTests.class })
@Tag(MasterTests.TAG)
@Tag(MediumTests.TAG)
public class TestBalancerRejection extends StochasticBalancerTestBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBalancerRejection.class);

static class MockCostFunction extends CostFunction {
public static double mockCost;

Expand Down Expand Up @@ -90,13 +87,13 @@ public void testBalancerRejections() throws Exception {
// Reject case 1: Total cost < 0
MockCostFunction.mockCost = -Double.MAX_VALUE;
// Since the Balancer was rejected, there should not be any plans
Assert.assertNull(loadBalancer.balanceCluster(LoadOfAllTable));
assertNull(loadBalancer.balanceCluster(LoadOfAllTable));

// Reject case 2: Cost < minCostNeedBalance
MockCostFunction.mockCost = 1;
conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", Float.MAX_VALUE);
loadBalancer.onConfigurationChange(conf);
Assert.assertNull(loadBalancer.balanceCluster(LoadOfAllTable));
assertNull(loadBalancer.balanceCluster(LoadOfAllTable));

// NamedQueue is an async Producer-consumer Pattern, waiting here until it completed
int maxWaitingCount = 10;
Expand All @@ -105,9 +102,9 @@ public void testBalancerRejections() throws Exception {
}
// There are two cases, should be 2 logEntries
List<LogEntry> logEntries = getBalancerRejectionLogEntries(provider);
Assert.assertEquals(2, logEntries.size());
Assert.assertTrue(logEntries.get(0).toJsonPrettyPrint().contains("minCostNeedBalance"));
Assert.assertTrue(logEntries.get(1).toJsonPrettyPrint().contains("cost1*multiplier1"));
assertEquals(2, logEntries.size());
assertTrue(logEntries.get(0).toJsonPrettyPrint().contains("minCostNeedBalance"));
assertTrue(logEntries.get(1).toJsonPrettyPrint().contains("cost1*multiplier1"));
} finally {
conf.unset(StochasticLoadBalancer.COST_FUNCTIONS_COST_FUNCTIONS_KEY);
conf.unset(BaseLoadBalancer.BALANCER_REJECTION_BUFFER_ENABLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,28 @@
*/
package org.apache.hadoop.hbase.master.balancer;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Pair;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category({ MasterTests.class, MediumTests.class })
@Tag(MasterTests.TAG)
@Tag(MediumTests.TAG)
public class TestCacheAwareLoadBalancerCostFunctions extends StochasticBalancerTestBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestCacheAwareLoadBalancerCostFunctions.class);

// Mapping of test -> expected cache cost
private final float[] expectedCacheCost = { 0.0f, 0.0f, 0.5f, 1.0f, 0.0f, 0.572f, 0.0f, 0.075f };

Expand Down Expand Up @@ -185,12 +180,12 @@ public class TestCacheAwareLoadBalancerCostFunctions extends StochasticBalancerT

private CacheAwareLoadBalancer loadBalancer = new CacheAwareLoadBalancer();

@BeforeClass
@BeforeAll
public static void saveInitialConfiguration() {
storedConfiguration = new Configuration(conf);
}

@Before
@BeforeEach
public void beforeEachTest() {
conf = new Configuration(storedConfiguration);
loadBalancer.loadConf(conf);
Expand Down
Loading