HBASE-20092 Fix TestRegionMetrics#testRegionMetrics

Signed-off-by: Michael Stack <stack@apache.org>
Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
Chia-Ping Tsai 2018-02-27 16:48:17 +08:00
parent f06a89b531
commit dbd8013057
2 changed files with 34 additions and 10 deletions

View File

@ -27,6 +27,7 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.hadoop.hbase.ClusterMetrics.Option;
import org.apache.hadoop.hbase.client.Admin;
@ -34,7 +35,6 @@ import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Threads;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
@ -61,12 +61,13 @@ public class TestRegionLoad {
private static final TableName TABLE_2 = TableName.valueOf("table_2");
private static final TableName TABLE_3 = TableName.valueOf("table_3");
private static final TableName[] tables = new TableName[]{TABLE_1, TABLE_2, TABLE_3};
private static final int MSG_INTERVAL = 500; // ms
@BeforeClass
public static void beforeClass() throws Exception {
// Make servers report eagerly. This test is about looking at the cluster status reported.
// Make it so we don't have to wait around too long to see change.
UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 500);
UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", MSG_INTERVAL);
UTIL.startMiniCluster(4);
admin = UTIL.getAdmin();
admin.setBalancerRunning(false, true);
@ -117,11 +118,13 @@ public class TestRegionLoad {
}
checkRegionsAndRegionLoads(tableRegions, regionLoads);
}
int pause = UTIL.getConfiguration().getInt("hbase.regionserver.msginterval", 3000);
// Just wait here. If this fixes the test, come back and do a better job.
// Would have to redo the below so can wait on cluster status changing.
Threads.sleep(2 * pause);
// Admin#getClusterMetrics retrieves data from HMaster. Admin#getRegionMetrics, by contrast,
// get the data from RS. Hence, it will fail if we do the assert check before RS has done
// the report.
TimeUnit.MILLISECONDS.sleep(3 * MSG_INTERVAL);
// Check RegionLoad matches the regionLoad from ClusterStatus
ClusterStatus clusterStatus
@ -133,10 +136,10 @@ public class TestRegionLoad {
(v1, v2) -> {
throw new RuntimeException("impossible!!");
}, () -> new TreeMap<>(Bytes.BYTES_COMPARATOR)));
LOG.info("serverName=" + serverName + ", getRegionLoads=" +
LOG.debug("serverName=" + serverName + ", getRegionLoads=" +
serverLoad.getRegionsLoad().keySet().stream().map(r -> Bytes.toString(r)).
collect(Collectors.toList()));
LOG.info("serverName=" + serverName + ", regionLoads=" +
LOG.debug("serverName=" + serverName + ", regionLoads=" +
regionLoads.keySet().stream().map(r -> Bytes.toString(r)).
collect(Collectors.toList()));
compareRegionLoads(serverLoad.getRegionsLoad(), regionLoads);

View File

@ -25,6 +25,8 @@ import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.hadoop.hbase.ClusterMetrics.Option;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.RegionInfo;
@ -37,6 +39,8 @@ import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.collect.Maps;
@ -47,6 +51,7 @@ public class TestRegionMetrics {
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRegionMetrics.class);
private static final Logger LOG = LoggerFactory.getLogger(TestRegionMetrics.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static Admin admin;
@ -54,9 +59,13 @@ public class TestRegionMetrics {
private static final TableName TABLE_2 = TableName.valueOf("table_2");
private static final TableName TABLE_3 = TableName.valueOf("table_3");
private static final TableName[] tables = new TableName[] { TABLE_1, TABLE_2, TABLE_3 };
private static final int MSG_INTERVAL = 500; // ms
@BeforeClass
public static void beforeClass() throws Exception {
// Make servers report eagerly. This test is about looking at the cluster status reported.
// Make it so we don't have to wait around too long to see change.
UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", MSG_INTERVAL);
UTIL.startMiniCluster(4);
admin = UTIL.getAdmin();
admin.balancerSwitch(false, true);
@ -101,13 +110,25 @@ public class TestRegionMetrics {
checkRegionsAndRegionMetrics(tableRegions, regionMetrics);
}
// Check RegionMetrics matches the RegionMetrics from ClusterStatus
ClusterMetrics clusterStatus = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
for (Map.Entry<ServerName, ServerMetrics> entry : clusterStatus.getLiveServerMetrics()
.entrySet()) {
// Just wait here. If this fixes the test, come back and do a better job.
// Would have to redo the below so can wait on cluster status changing.
// Admin#getClusterMetrics retrieves data from HMaster. Admin#getRegionMetrics, by contrast,
// get the data from RS. Hence, it will fail if we do the assert check before RS has done
// the report.
TimeUnit.MILLISECONDS.sleep(3 * MSG_INTERVAL);
// Check RegionMetrics matches the RegionMetrics from ClusterMetrics
for (Map.Entry<ServerName, ServerMetrics> entry : admin
.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().entrySet()) {
ServerName serverName = entry.getKey();
ServerMetrics serverMetrics = entry.getValue();
List<RegionMetrics> regionMetrics = admin.getRegionMetrics(serverName);
LOG.debug("serverName=" + serverName + ", getRegionLoads=" +
serverMetrics.getRegionMetrics().keySet().stream().map(r -> Bytes.toString(r)).
collect(Collectors.toList()));
LOG.debug("serverName=" + serverName + ", regionLoads=" +
regionMetrics.stream().map(r -> Bytes.toString(r.getRegionName())).
collect(Collectors.toList()));
assertEquals(serverMetrics.getRegionMetrics().size(), regionMetrics.size());
}
}