From 78b7dad2c842c1c4532553631e04c8376df8d7ac Mon Sep 17 00:00:00 2001 From: jxiang Date: Thu, 6 Mar 2014 01:26:25 +0000 Subject: [PATCH] HBASE-10649 TestMasterMetrics fails occasionally git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1574738 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/regionserver/HRegionServer.java | 4 +++- .../hbase/master/TestMasterMetrics.java | 20 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 7b8293cda17..6191578ca4d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -50,6 +50,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import javax.management.ObjectName; +import com.google.common.annotations.VisibleForTesting; import com.google.protobuf.HBaseZeroCopyByteString; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -1046,7 +1047,8 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa return writeCount; } - void tryRegionServerReport(long reportStartTime, long reportEndTime) + @VisibleForTesting + protected void tryRegionServerReport(long reportStartTime, long reportEndTime) throws IOException { if (this.rssStub == null) { // the current server is stopping. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java index e1c6e8295c9..07a3b48df49 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java @@ -17,6 +17,8 @@ */ package org.apache.hadoop.hbase.master; +import java.io.IOException; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -25,6 +27,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.MediumTests; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.MiniHBaseCluster.MiniHBaseClusterRegionServer; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos; import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos; @@ -45,15 +48,24 @@ public class TestMasterMetrics { private static HMaster master; private static HBaseTestingUtility TEST_UTIL; + private static class MyRegionServer extends MiniHBaseClusterRegionServer { + public MyRegionServer(Configuration conf) throws IOException, + InterruptedException { + super(conf); + } + + @Override + protected void tryRegionServerReport( + long reportStartTime, long reportEndTime) { + // do nothing + } + } @BeforeClass public static void startCluster() throws Exception { LOG.info("Starting cluster"); TEST_UTIL = new HBaseTestingUtility(); - Configuration conf = TEST_UTIL.getConfiguration(); - // Prevent region server report any load during the test - conf.setInt("hbase.regionserver.msginterval", 3000000); - TEST_UTIL.startMiniCluster(1, 1); + TEST_UTIL.startMiniCluster(1, 1, 1, null, HMaster.class, MyRegionServer.class); cluster = TEST_UTIL.getHBaseCluster(); LOG.info("Waiting for active/ready master"); cluster.waitForActiveAndReadyMaster();