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
5 changes: 0 additions & 5 deletions hbase-balancer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,35 @@
*/
package org.apache.hadoop.hbase.favored;

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

import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
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;

@Category({ MiscTests.class, SmallTests.class })
@Tag(MiscTests.TAG)
@Tag(SmallTests.TAG)
public class TestStartcodeAgnosticServerName {

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

@Test
public void testStartCodeServerName() {
ServerName sn = ServerName.valueOf("www.example.org", 1234, 5678);
StartcodeAgnosticServerName snStartCode =
new StartcodeAgnosticServerName("www.example.org", 1234, 5678);

assertTrue(ServerName.isSameAddress(sn, snStartCode));
assertTrue(snStartCode.equals(sn));
assertTrue(sn.equals(snStartCode));
assertEquals(snStartCode, sn);
assertEquals(sn, snStartCode);
assertEquals(0, snStartCode.compareTo(sn));

StartcodeAgnosticServerName snStartCodeFNPort =
new StartcodeAgnosticServerName("www.example.org", 1234, ServerName.NON_STARTCODE);
assertTrue(ServerName.isSameAddress(snStartCodeFNPort, snStartCode));
assertTrue(snStartCode.equals(snStartCodeFNPort));
assertTrue(snStartCodeFNPort.equals(snStartCode));
assertEquals(snStartCode, snStartCodeFNPort);
assertEquals(snStartCodeFNPort, snStartCode);
assertEquals(0, snStartCode.compareTo(snStartCodeFNPort));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,37 @@
*/
package org.apache.hadoop.hbase.master;

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

import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

@Category({ MasterTests.class, SmallTests.class })
@Tag(MasterTests.TAG)
@Tag(SmallTests.TAG)
public class TestRegionPlan {

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

private final ServerName SRC = ServerName.valueOf("source", 1234, 2345);
private final ServerName DEST = ServerName.valueOf("dest", 1234, 2345);
@Rule
public TestName name = new TestName();

private String methodName;

@BeforeEach
public void setUp(TestInfo testInfo) {
methodName = testInfo.getTestMethod().get().getName();
}

@Test
public void testCompareTo() {
RegionInfo hri = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
RegionInfo hri = RegionInfoBuilder.newBuilder(TableName.valueOf(methodName)).build();
RegionPlan a = new RegionPlan(hri, null, null);
RegionPlan b = new RegionPlan(hri, null, null);
assertEquals(0, a.compareTo(b));
Expand All @@ -72,24 +70,24 @@ public void testCompareTo() {

@Test
public void testEqualsWithNulls() {
RegionInfo hri = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
RegionInfo hri = RegionInfoBuilder.newBuilder(TableName.valueOf(methodName)).build();
RegionPlan a = new RegionPlan(hri, null, null);
RegionPlan b = new RegionPlan(hri, null, null);
assertTrue(a.equals(b));
assertEquals(a, b);
a = new RegionPlan(hri, SRC, null);
b = new RegionPlan(hri, null, null);
assertFalse(a.equals(b));
assertNotEquals(a, b);
a = new RegionPlan(hri, SRC, null);
b = new RegionPlan(hri, SRC, null);
assertTrue(a.equals(b));
assertEquals(a, b);
a = new RegionPlan(hri, SRC, null);
b = new RegionPlan(hri, SRC, DEST);
assertFalse(a.equals(b));
assertNotEquals(a, b);
}

@Test
public void testEquals() {
RegionInfo hri = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
RegionInfo hri = RegionInfoBuilder.newBuilder(TableName.valueOf(methodName)).build();

// Identity equality
RegionPlan plan = new RegionPlan(hri, SRC, DEST);
Expand All @@ -98,7 +96,7 @@ public void testEquals() {

// HRI is used for equality
RegionInfo other =
RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName() + "other")).build();
RegionInfoBuilder.newBuilder(TableName.valueOf(methodName + "other")).build();
assertNotEquals(plan.hashCode(), new RegionPlan(other, SRC, DEST).hashCode());
assertNotEquals(plan, new RegionPlan(other, SRC, DEST));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
*/
package org.apache.hadoop.hbase.master.balancer;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.ArrayDeque;
import java.util.ArrayList;
Expand Down Expand Up @@ -45,7 +46,6 @@
import org.apache.hadoop.hbase.master.RegionPlan;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.net.DNSToSwitchMapping;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -171,11 +171,11 @@ public void assertClusterAsBalanced(List<ServerAndLoad> servers) {
int max = numRegions % numServers == 0 ? min : min + 1;

for (ServerAndLoad server : servers) {
assertTrue("All servers should have a positive load. " + server, server.getLoad() >= 0);
assertTrue("All servers should have load no more than " + max + ". " + server,
server.getLoad() <= max);
assertTrue("All servers should have load no less than " + min + ". " + server,
server.getLoad() >= min);
assertTrue(server.getLoad() >= 0, "All servers should have a positive load. " + server);
assertTrue(server.getLoad() <= max,
"All servers should have load no more than " + max + ". " + server);
assertTrue(server.getLoad() >= min,
"All servers should have load no less than " + min + ". " + server);
}
}

Expand Down Expand Up @@ -237,7 +237,7 @@ public void assertRegionReplicaPlacement(Map<ServerName, List<RegionInfo>> serve
for (RegionInfo info : entry.getValue()) {
RegionInfo primaryInfo = RegionReplicaUtil.getRegionInfoForDefaultReplica(info);
if (!infos.add(primaryInfo)) {
Assert.fail("Two or more region replicas are hosted on the same host after balance");
fail("Two or more region replicas are hosted on the same host after balance");
}
}
}
Expand All @@ -257,7 +257,7 @@ public void assertRegionReplicaPlacement(Map<ServerName, List<RegionInfo>> serve
for (RegionInfo info : entry.getValue()) {
RegionInfo primaryInfo = RegionReplicaUtil.getRegionInfoForDefaultReplica(info);
if (!infos.add(primaryInfo)) {
Assert.fail("Two or more region replicas are hosted on the same rack after balance");
fail("Two or more region replicas are hosted on the same rack after balance");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.master.balancer;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.time.Duration;
import java.util.List;
Expand All @@ -30,7 +30,7 @@
import org.apache.hadoop.hbase.master.RackManager;
import org.apache.hadoop.hbase.master.RegionPlan;
import org.apache.hadoop.net.DNSToSwitchMapping;
import org.junit.BeforeClass;
import org.junit.jupiter.api.BeforeAll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -44,7 +44,7 @@ public class StochasticBalancerTestBase extends BalancerTestBase {
protected static DummyMetricsStochasticBalancer dummyMetricsStochasticBalancer =
new DummyMetricsStochasticBalancer();

@BeforeClass
@BeforeAll
public static void beforeAllTests() throws Exception {
conf = HBaseConfiguration.create();
conf.setClass("hbase.util.ip.to.rack.determiner", MockMapping.class, DNSToSwitchMapping.class);
Expand Down Expand Up @@ -84,7 +84,7 @@ protected void increaseMaxRunTimeOrFail() {
protected void testWithClusterWithIteration(Map<ServerName, List<RegionInfo>> serverMap,
RackManager rackManager, boolean assertFullyBalanced, boolean assertFullyBalancedForReplicas) {
List<ServerAndLoad> list = convertToList(serverMap);
LOG.info("Mock Cluster : " + printMock(list) + " " + printStats(list));
LOG.info("Mock Cluster : {} {}", printMock(list), printStats(list));

loadBalancer.setRackManager(rackManager);
// Run the balancer.
Expand All @@ -106,7 +106,7 @@ protected void testWithClusterWithIteration(Map<ServerName, List<RegionInfo>> se
balancedCluster = reconcile(list, plans, serverMap);

// Print out the cluster loads to make debugging easier.
LOG.info("Mock after balance: " + printMock(balancedCluster));
LOG.info("Mock after balance: {}", printMock(balancedCluster));

LoadOfAllTable = (Map) mockClusterServersWithTables(serverMap);
plans = loadBalancer.balanceCluster(LoadOfAllTable);
Expand All @@ -116,8 +116,8 @@ protected void testWithClusterWithIteration(Map<ServerName, List<RegionInfo>> se
LOG.info("Mock Final balance: " + printMock(balancedCluster));

if (assertFullyBalanced) {
assertNull("Given a requirement to be fully balanced, second attempt at plans should "
+ "produce none.", plans);
assertNull(plans, "Given a requirement to be fully balanced, second attempt at plans should "
+ "produce none.");
}
if (assertFullyBalancedForReplicas) {
assertRegionReplicaPlacement(serverMap, rackManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/
package org.apache.hadoop.hbase.master.balancer;

import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

public class StochasticBalancerTestBase2 extends StochasticBalancerTestBase {

@Before
@BeforeEach
public void before() {
conf.setLong(StochasticLoadBalancer.MAX_STEPS_KEY, 2000000L);
conf.setFloat("hbase.master.balancer.stochastic.localityCost", 0);
Expand All @@ -31,7 +31,7 @@ public void before() {
loadBalancer.onConfigurationChange(conf);
}

@After
@AfterEach
public void after() {
// reset config to make sure balancer run
loadBalancer.onConfigurationChange(conf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,24 @@
*/
package org.apache.hadoop.hbase.master.balancer;

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

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category({ SmallTests.class, MasterTests.class })
@Tag(MasterTests.TAG)
@Tag(SmallTests.TAG)
public class TestBalancerConditionals extends BalancerTestBase {

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

private BalancerConditionals balancerConditionals;
private BalancerClusterState mockCluster;

@Before
@BeforeEach
public void setUp() {
balancerConditionals = BalancerConditionals.create();
mockCluster = mockCluster(new int[] { 0, 1, 2 });
Expand All @@ -51,8 +46,8 @@ public void testDefaultConfiguration() {
balancerConditionals.setConf(conf);
balancerConditionals.loadClusterState(mockCluster);

assertEquals("No conditionals should be loaded by default", 0,
balancerConditionals.getConditionalClasses().size());
assertEquals(0, balancerConditionals.getConditionalClasses().size(),
"No conditionals should be loaded by default");
}

@Test
Expand All @@ -64,8 +59,8 @@ public void testCustomConditionalsViaConfiguration() {
balancerConditionals.setConf(conf);
balancerConditionals.loadClusterState(mockCluster);

assertTrue("Custom conditionals should be loaded",
balancerConditionals.isConditionalBalancingEnabled());
assertTrue(balancerConditionals.isConditionalBalancingEnabled(),
"Custom conditionals should be loaded");
}

@Test
Expand All @@ -76,8 +71,8 @@ public void testInvalidCustomConditionalClass() {
balancerConditionals.setConf(conf);
balancerConditionals.loadClusterState(mockCluster);

assertEquals("Invalid classes should not be loaded as conditionals", 0,
balancerConditionals.getConditionalClasses().size());
assertEquals(0, balancerConditionals.getConditionalClasses().size(),
"Invalid classes should not be loaded as conditionals");
}

@Test
Expand All @@ -88,8 +83,7 @@ public void testMetaTableIsolationConditionalEnabled() {
balancerConditionals.setConf(conf);
balancerConditionals.loadClusterState(mockCluster);

assertTrue("MetaTableIsolationConditional should be active",
balancerConditionals.isTableIsolationEnabled());
assertTrue(balancerConditionals.isTableIsolationEnabled(),
"MetaTableIsolationConditional should be active");
}

}
Loading