Skip to content
Open
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
2 changes: 1 addition & 1 deletion hbase-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,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 @@ -62,7 +62,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 @@ -93,7 +93,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,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.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import java.io.IOException;
import java.util.HashSet;
Expand Down Expand Up @@ -130,16 +130,15 @@ static void validateReplicaDistribution(Connection connection, TableName tableNa
Set<byte[]> startKeys = new HashSet<>();
for (RegionInfo regionInfo : regionInfos) {
// each region should have a distinct start key
assertFalse(
assertFalse(startKeys.contains(regionInfo.getStartKey()),
"Each region should have its own start key, "
+ "demonstrating it is not a replica of any others on this host",
startKeys.contains(regionInfo.getStartKey()));
+ "demonstrating it is not a replica of any others on this host");
startKeys.add(regionInfo.getStartKey());
}
}
} else {
// Ensure all replicas are on the same server
assertEquals("All regions should share one server", 1, serverToRegions.size());
assertEquals(1, serverToRegions.size(), "All regions should share one server");
}
}

Expand All @@ -153,19 +152,19 @@ static void validateRegionLocations(Map<TableName, Set<ServerName>> tableToServe

if (shouldBeBalanced) {
for (ServerName server : productServers) {
assertNotEquals("Meta table and product table should not share servers", server,
metaServer);
assertNotEquals("Quota table and product table should not share servers", server,
quotaServer);
assertNotEquals(server, metaServer,
"Meta table and product table should not share servers");
assertNotEquals(server, quotaServer,
"Quota table and product table should not share servers");
}
assertNotEquals("The meta server and quotas server should be different", metaServer,
quotaServer);
assertNotEquals(metaServer, quotaServer,
"The meta server and quotas server should be different");
} else {
for (ServerName server : productServers) {
assertEquals("Meta table and product table must share servers", server, metaServer);
assertEquals("Quota table and product table must share servers", server, quotaServer);
assertEquals(server, metaServer, "Meta table and product table must share servers");
assertEquals(server, quotaServer, "Quota table and product table must share servers");
}
assertEquals("The meta server and quotas server must be the same", metaServer, quotaServer);
assertEquals(metaServer, quotaServer, "The meta server and quotas server must be the same");
}
}

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.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;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import static org.mockito.Mockito.any; is not the correct matcher import (matchers live under org.mockito.ArgumentMatchers). This will not compile and also makes the intent less clear. Switch the static import to org.mockito.ArgumentMatchers.any (or use anyString/any(Class) as appropriate).

Suggested change
import static org.mockito.Mockito.any;
import static org.mockito.ArgumentMatchers.any;

Copilot uses AI. Check for mistakes.
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -56,9 +57,6 @@
import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
import org.apache.hadoop.hbase.rsgroup.RSGroupInfoManager;
import org.apache.hadoop.hbase.util.Bytes;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import org.apache.hbase.thirdparty.com.google.common.collect.ArrayListMultimap;
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
Expand Down Expand Up @@ -128,8 +126,8 @@ protected void assertImmediateAssignment(List<RegionInfo> regions, List<ServerNa
tableDescs.get(tableName).getRegionServerGroup().orElse(RSGroupInfo.DEFAULT_GROUP);
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 @@ -150,8 +148,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 @@ -173,8 +171,8 @@ protected void assertRetainedAssignment(Map<RegionInfo, ServerName> existing,
tableDescs.get(tableName).getRegionServerGroup().orElse(RSGroupInfo.DEFAULT_GROUP);
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 @@ -232,7 +230,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 @@ -389,31 +387,28 @@ protected static Map<TableName, TableDescriptor> constructTableDesc(boolean hasB
}

protected static MasterServices getMockedMaster() throws IOException {
TableDescriptors tds = Mockito.mock(TableDescriptors.class);
Mockito.when(tds.get(tables[0])).thenReturn(tableDescs.get(tables[0]));
Mockito.when(tds.get(tables[1])).thenReturn(tableDescs.get(tables[1]));
Mockito.when(tds.get(tables[2])).thenReturn(tableDescs.get(tables[2]));
Mockito.when(tds.get(tables[3])).thenReturn(tableDescs.get(tables[3]));
MasterServices services = Mockito.mock(HMaster.class);
Mockito.when(services.getTableDescriptors()).thenReturn(tds);
AssignmentManager am = Mockito.mock(AssignmentManager.class);
Mockito.when(services.getAssignmentManager()).thenReturn(am);
Mockito.when(services.getConfiguration()).thenReturn(conf);
TableDescriptors tds = mock(TableDescriptors.class);
when(tds.get(tables[0])).thenReturn(tableDescs.get(tables[0]));
when(tds.get(tables[1])).thenReturn(tableDescs.get(tables[1]));
when(tds.get(tables[2])).thenReturn(tableDescs.get(tables[2]));
when(tds.get(tables[3])).thenReturn(tableDescs.get(tables[3]));
MasterServices services = mock(HMaster.class);
when(services.getTableDescriptors()).thenReturn(tds);
AssignmentManager am = mock(AssignmentManager.class);
when(services.getAssignmentManager()).thenReturn(am);
when(services.getConfiguration()).thenReturn(conf);
RSGroupInfoManager manager = getMockedGroupInfoManager();
Mockito.when(services.getRSGroupInfoManager()).thenReturn(manager);
when(services.getRSGroupInfoManager()).thenReturn(manager);
return services;
}

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);
when(gm.listRSGroups()).thenReturn(Lists.newLinkedList(groupMap.values()));
when(gm.isOnline()).thenReturn(true);
return gm;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,30 @@
*/
package org.apache.hadoop.hbase.master.balancer;

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

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.metrics2.MetricsSource;
import org.apache.hadoop.metrics2.MetricsTag;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterAll;
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;

@Category({ MediumTests.class })
@Tag(MiscTests.TAG)
@Tag(MediumTests.TAG)
public class TestBalancerStatusTagInJMXMetrics extends BalancerTestBase {

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

private static final Logger LOG =
LoggerFactory.getLogger(TestBalancerStatusTagInJMXMetrics.class);
private static HBaseTestingUtil UTIL = new HBaseTestingUtil();
Expand All @@ -56,7 +52,7 @@ public class TestBalancerStatusTagInJMXMetrics extends BalancerTestBase {
/**
* Setup the environment for the test.
*/
@BeforeClass
@BeforeAll
public static void setupBeforeClass() throws Exception {
conf = UTIL.getConfiguration();
Random rand = ThreadLocalRandom.current();
Expand Down Expand Up @@ -85,7 +81,7 @@ public static void setupBeforeClass() throws Exception {
}
}

@AfterClass
@AfterAll
public static void tearDownAfterClass() throws Exception {
UTIL.shutdownMiniCluster();
}
Expand All @@ -96,9 +92,9 @@ public static void tearDownAfterClass() throws Exception {
@Test
public void testJmxMetrics() throws Exception {

assertEquals(getStatus(), "true");
assertEquals("true", getStatus());
master.getLoadBalancer().updateBalancerStatus(false);
assertEquals(getStatus(), "false");
assertEquals("false", getStatus());

}

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.fail;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -31,7 +31,6 @@
import java.util.concurrent.ThreadLocalRandom;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ClusterMetrics;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.RegionMetrics;
Expand All @@ -45,20 +44,16 @@
import org.apache.hadoop.hbase.master.RegionPlan;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
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;

import org.apache.hbase.thirdparty.com.google.common.collect.Lists;

@Category({ LargeTests.class })
@Tag(LargeTests.TAG)
public class TestCacheAwareLoadBalancer extends BalancerTestBase {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestCacheAwareLoadBalancer.class);

private static final Logger LOG = LoggerFactory.getLogger(TestCacheAwareLoadBalancer.class);

Expand Down Expand Up @@ -115,7 +110,7 @@ private ServerMetrics mockServerMetricsWithRegionCacheInfo(ServerName server,
return serverMetrics;
}

@BeforeClass
@BeforeAll
public static void beforeAllTests() throws Exception {
servers = generateServers(3);
tableDescs = constructTableDesc(false);
Expand Down
Loading
Loading