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,9 +17,12 @@
*/
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 static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -122,8 +125,8 @@ protected void assertImmediateAssignment(List<RegionInfo> regions, List<ServerNa
String groupName = getMockedGroupInfoManager().getRSGroupOfTable(tableName);
assertTrue(StringUtils.isNotEmpty(groupName));
RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName);
assertTrue("Region is not correctly assigned to group servers.",
gInfo.containsServer(server.getAddress()));
assertTrue(gInfo.containsServer(server.getAddress()),
"Region is not correctly assigned to group servers.");
}
}

Expand All @@ -144,8 +147,8 @@ protected void assertRetainedAssignment(Map<RegionInfo, ServerName> existing,
Set<ServerName> onlineServerSet = new TreeSet<>(servers);
Set<RegionInfo> assignedRegions = new TreeSet<>(RegionInfo.COMPARATOR);
for (Map.Entry<ServerName, List<RegionInfo>> a : assignment.entrySet()) {
assertTrue("Region assigned to server that was not listed as online",
onlineServerSet.contains(a.getKey()));
assertTrue(onlineServerSet.contains(a.getKey()),
"Region assigned to server that was not listed as online");
for (RegionInfo r : a.getValue()) {
assignedRegions.add(r);
}
Expand All @@ -166,8 +169,8 @@ protected void assertRetainedAssignment(Map<RegionInfo, ServerName> existing,
String groupName = getMockedGroupInfoManager().getRSGroupOfTable(tableName);
assertTrue(StringUtils.isNotEmpty(groupName));
RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName);
assertTrue("Region is not correctly assigned to group servers.",
gInfo.containsServer(currentServer.getAddress()));
assertTrue(gInfo.containsServer(currentServer.getAddress()),
"Region is not correctly assigned to group servers.");
if (
oldAssignedServer != null && onlineHostNames.contains(oldAssignedServer.getHostname())
) {
Expand Down Expand Up @@ -225,7 +228,7 @@ protected String printStats(ArrayListMultimap<String, ServerAndLoad> groupBasedL
}
}
List<RegionInfo> regions = serversMap.get(actual);
assertTrue("No load for " + actual, regions != null);
assertTrue(regions != null, "No load for " + actual);
loadMap.put(gInfo.getName(), new ServerAndLoad(actual, regions.size()));
}
}
Expand Down Expand Up @@ -397,12 +400,9 @@ protected static MasterServices getMockedMaster() throws IOException {
}

protected static RSGroupInfoManager getMockedGroupInfoManager() throws IOException {
RSGroupInfoManager gm = Mockito.mock(RSGroupInfoManager.class);
Mockito.when(gm.getRSGroup(Mockito.any())).thenAnswer(new Answer<RSGroupInfo>() {
@Override
public RSGroupInfo answer(InvocationOnMock invocation) throws Throwable {
return groupMap.get(invocation.getArgument(0));
}
RSGroupInfoManager gm = mock(RSGroupInfoManager.class);
when(gm.getRSGroup(any())).thenAnswer(invocation -> {
return groupMap.get(invocation.getArgument(0));
});
Mockito.when(gm.listRSGroups()).thenReturn(Lists.newLinkedList(groupMap.values()));
Mockito.when(gm.isOnline()).thenReturn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
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.ArrayList;
import java.util.Collections;
Expand All @@ -30,7 +30,6 @@
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
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 @@ -42,10 +41,9 @@
import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.net.DNSToSwitchMapping;
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.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -54,15 +52,12 @@
/**
* Test RSGroupBasedLoadBalancer with SimpleLoadBalancer as internal balancer
*/
@Category(LargeTests.class)
@Tag(LargeTests.TAG)
public class TestRSGroupBasedLoadBalancer extends RSGroupableBalancerTestBase {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRSGroupBasedLoadBalancer.class);
private static final Logger LOG = LoggerFactory.getLogger(TestRSGroupBasedLoadBalancer.class);
private static RSGroupBasedLoadBalancer loadBalancer;

@BeforeClass
@BeforeAll
public static void beforeAllTests() throws Exception {
servers = generateServers(7);
groupMap = constructGroupInfo(servers, groups);
Expand Down Expand Up @@ -121,8 +116,8 @@ public void testBulkAssignment() throws Exception {
String groupName = getMockedGroupInfoManager().getRSGroupOfTable(tableName);
assertTrue(StringUtils.isNotEmpty(groupName));
RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName);
assertTrue("Region is not correctly assigned to group servers.",
gInfo.containsServer(sn.getAddress()));
assertTrue(gInfo.containsServer(sn.getAddress()),
"Region is not correctly assigned to group servers.");
}
}
ArrayListMultimap<String, ServerAndLoad> loadMap = convertToGroupBasedMap(assignments);
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.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -30,7 +30,6 @@
import java.util.Set;
import java.util.TreeMap;
import org.apache.hadoop.hbase.ClusterMetrics;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.RegionMetrics;
import org.apache.hadoop.hbase.ServerMetrics;
import org.apache.hadoop.hbase.ServerName;
Expand All @@ -43,23 +42,16 @@
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.net.DNSToSwitchMapping;
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.Tag;
import org.junit.jupiter.api.Test;

/**
* Test RSGroupBasedLoadBalancer with StochasticLoadBalancer as internal balancer
*/
@Category(LargeTests.class)
@Tag(LargeTests.TAG)
public class TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal
extends RSGroupableBalancerTestBase {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule
.forClass(TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal.class);
private static RSGroupBasedLoadBalancer loadBalancer;

@BeforeClass
@BeforeAll
public static void beforeAllTests() throws Exception {
groups = new String[] { RSGroupInfo.DEFAULT_GROUP };
servers = generateServers(3);
Expand Down
5 changes: 0 additions & 5 deletions hbase-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,6 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

public abstract class MasterStateStoreTestBase {

Expand All @@ -63,7 +63,7 @@ public abstract class MasterStateStoreTestBase {
TableDescriptorBuilder.newBuilder(TableName.valueOf("test:local"))
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(MasterRegionFactory.STATE_FAMILY)).build();

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() throws Exception {
Configuration conf = UTIL.getConfiguration();
conf.setBoolean(MemStoreLAB.USEMSLAB_KEY, false);
Expand Down Expand Up @@ -94,7 +94,7 @@ public static void setUpBeforeClass() throws Exception {
UTIL.startMiniZKCluster();
}

@AfterClass
@AfterAll
public static void tearDownAfterClass() throws IOException {
REGION.close(true);
HFILE_CLEANER_POOL.shutdownNow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,27 @@
*/
package org.apache.hadoop.hbase.master;

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 org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.client.MasterSwitchType;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
import org.junit.After;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterEach;
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.ZooKeeperProtos;

@Category({ MasterTests.class, MediumTests.class })
@Tag(MasterTests.TAG)
@Tag(MediumTests.TAG)
public class TestSplitOrMergeStateStore extends MasterStateStoreTestBase {

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

@After
@AfterEach
public void tearDown() throws Exception {
cleanup();
ZKUtil.deleteNodeRecursively(UTIL.getZooKeeperWatcher(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
*/
package org.apache.hadoop.hbase.master.balancer;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -53,8 +54,7 @@
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.junit.BeforeClass;
import org.junit.jupiter.api.BeforeAll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -71,7 +71,7 @@ public class 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 @@ -196,11 +196,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 @@ -262,7 +262,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 @@ -282,7 +282,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 Expand Up @@ -586,7 +586,7 @@ protected void testWithCluster(Map<ServerName, List<RegionInfo>> serverMap,
Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable =
(Map) mockClusterServersWithTables(serverMap);
List<RegionPlan> plans = loadBalancer.balanceCluster(LoadOfAllTable);
assertNotNull("Initial cluster balance should produce plans.", plans);
assertNotNull(plans, "Initial cluster balance should produce plans.");

// Check to see that this actually got to a stable place.
if (assertFullyBalanced || assertFullyBalancedForReplicas) {
Expand All @@ -600,8 +600,8 @@ protected void testWithCluster(Map<ServerName, List<RegionInfo>> serverMap,
assertClusterAsBalanced(balancedCluster);
LoadOfAllTable = (Map) mockClusterServersWithTables(serverMap);
List<RegionPlan> secondPlans = loadBalancer.balanceCluster(LoadOfAllTable);
assertNull("Given a requirement to be fully balanced, second attempt at plans should "
+ "produce none.", secondPlans);
assertNull(secondPlans, "Given a requirement to be fully balanced, second attempt at plans "
+ "should produce none.");
}

if (assertFullyBalancedForReplicas) {
Expand All @@ -620,7 +620,7 @@ protected void testWithClusterWithIteration(Map<ServerName, List<RegionInfo>> se
Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable =
(Map) mockClusterServersWithTables(serverMap);
List<RegionPlan> plans = loadBalancer.balanceCluster(LoadOfAllTable);
assertNotNull("Initial cluster balance should produce plans.", plans);
assertNotNull(plans, "Initial cluster balance should produce plans.");

List<ServerAndLoad> balancedCluster = null;
// Run through iteration until done. Otherwise will be killed as test time out
Expand All @@ -639,8 +639,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
Loading