hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1484052 - in /hbase/trunk: hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/ hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/ hbase-hado...
Date Sat, 18 May 2013 03:23:14 GMT
Author: stack
Date: Sat May 18 03:23:13 2013
New Revision: 1484052

URL: http://svn.apache.org/r1484052
Log:
HBASE-8564 TestMetricsRegionServer depends on test order; ADDENDUM

Modified:
    hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelper.java
    hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java
    hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
    hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServer.java

Modified: hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelper.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelper.java?rev=1484052&r1=1484051&r2=1484052&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelper.java
(original)
+++ hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelper.java
Sat May 18 03:23:13 2013
@@ -24,6 +24,12 @@ import org.apache.hadoop.hbase.metrics.B
 public interface MetricsAssertHelper {
 
   /**
+   * Init helper.  This method will make sure that the metrics system is set
+   * up for tests.
+   */
+  public void init();
+
+  /**
    * Assert that a tag exists and has a given value.
    *
    * @param name     The name of the tag.

Modified: hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java?rev=1484052&r1=1484051&r2=1484052&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java
(original)
+++ hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java
Sat May 18 03:23:13 2013
@@ -25,6 +25,7 @@ import org.apache.hadoop.metrics2.Metric
 import org.apache.hadoop.metrics2.MetricsRecordBuilder;
 import org.apache.hadoop.metrics2.MetricsSource;
 import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -111,6 +112,11 @@ public class MetricsAssertHelperImpl imp
   }
 
   @Override
+  public void init() {
+    // In hadoop 1 there's no minicluster mode so there's nothing to do here.
+  }
+
+  @Override
   public void assertTag(String name, String expected, BaseSource source) {
     getMetrics(source);
     String cName = canonicalizeMetricName(name);

Modified: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java?rev=1484052&r1=1484051&r2=1484052&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
(original)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
Sat May 18 03:23:13 2013
@@ -25,8 +25,6 @@ public class MetricsRegionServerSourceFa
   public static enum FactoryStorage {
     INSTANCE;
     private Object aggLock = new Object();
-    private Object serverLock = new Object();
-    private MetricsRegionServerSource serverSource;
     private MetricsRegionAggregateSourceImpl aggImpl;
   }
 
@@ -42,13 +40,7 @@ public class MetricsRegionServerSourceFa
 
   @Override
   public synchronized MetricsRegionServerSource createServer(MetricsRegionServerWrapper regionServerWrapper)
{
-    synchronized (FactoryStorage.INSTANCE.serverLock) {
-      if (FactoryStorage.INSTANCE.serverSource == null) {
-        FactoryStorage.INSTANCE.serverSource = new MetricsRegionServerSourceImpl(
-            regionServerWrapper);
-      }
-      return FactoryStorage.INSTANCE.serverSource;
-    }
+    return new MetricsRegionServerSourceImpl(regionServerWrapper);
   }
 
   @Override

Modified: hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java?rev=1484052&r1=1484051&r2=1484052&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java
(original)
+++ hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java
Sat May 18 03:23:13 2013
@@ -26,6 +26,7 @@ import org.apache.hadoop.metrics2.Metric
 import org.apache.hadoop.metrics2.MetricsRecordBuilder;
 import org.apache.hadoop.metrics2.MetricsSource;
 import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -36,7 +37,6 @@ import static org.junit.Assert.*;
  *  A helper class that will allow tests to get into hadoop2's metrics2 values.
  */
 public class MetricsAssertHelperImpl implements MetricsAssertHelper {
-
   private Map<String, String> tags = new HashMap<String, String>();
   private Map<String, Number> gauges = new HashMap<String, Number>();
   private Map<String, Long> counters = new HashMap<String, Long>();
@@ -130,6 +130,13 @@ public class MetricsAssertHelperImpl imp
   }
 
   @Override
+  public void init() {
+    // Make sure that the metrics system doesn't throw an exception when
+    // registering a source with the same name
+    DefaultMetricsSystem.setMiniClusterMode(true);
+  }
+
+  @Override
   public void assertTag(String name, String expected, BaseSource source) {
     getMetrics(source);
     String cName = canonicalizeMetricName(name);

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java?rev=1484052&r1=1484051&r2=1484052&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java Sat
May 18 03:23:13 2013
@@ -39,6 +39,7 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.hbase.security.User;
+import org.apache.hadoop.hbase.test.MetricsAssertHelper;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.JVMClusterUtil;
 import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread;
@@ -88,6 +89,10 @@ public class MiniHBaseCluster extends HB
       throws IOException, InterruptedException {
     super(conf);
     conf.set(HConstants.MASTER_PORT, "0");
+
+    // Hadoop 2
+    CompatibilityFactory.getInstance(MetricsAssertHelper.class).init();
+
     init(numMasters, numRegionServers, masterClass, regionserverClass);
     this.initialClusterStatus = getClusterStatus();
   }

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServer.java?rev=1484052&r1=1484051&r2=1484052&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServer.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServer.java
Sat May 18 03:23:13 2013
@@ -19,10 +19,9 @@ package org.apache.hadoop.hbase.regionse
 
 import org.apache.hadoop.hbase.CompatibilityFactory;
 import org.apache.hadoop.hbase.SmallTests;
-import org.apache.hadoop.hbase.regionserver.MetricsRegionServer;
-import org.apache.hadoop.hbase.regionserver.MetricsRegionServerWrapperStub;
-import org.apache.hadoop.hbase.regionserver.MetricsRegionServerSource;
 import org.apache.hadoop.hbase.test.MetricsAssertHelper;
+import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -33,17 +32,27 @@ import static org.junit.Assert.assertNot
  */
 @Category(SmallTests.class)
 public class TestMetricsRegionServer {
+  public static MetricsAssertHelper HELPER =
+      CompatibilityFactory.getInstance(MetricsAssertHelper.class);
 
-  public MetricsAssertHelper HELPER = CompatibilityFactory.getInstance(MetricsAssertHelper.class);
+  private MetricsRegionServerWrapperStub wrapper;
+  private MetricsRegionServer rsm;
+  private MetricsRegionServerSource serverSource;
+
+  @BeforeClass
+  public static void classSetUp() {
+    HELPER.init();
+  }
+
+  @Before
+  public void setUp() {
+    wrapper = new MetricsRegionServerWrapperStub();
+    rsm = new MetricsRegionServer(wrapper);
+    serverSource = rsm.getMetricsSource();
+  }
 
   @Test
   public void testWrapperSource() {
-    MetricsRegionServerWrapperStub wrapper = new MetricsRegionServerWrapperStub();
-    MetricsRegionServerSource source =
-        CompatibilityFactory.getInstance(MetricsRegionServerSourceFactory.class)
-            .createServer(wrapper);
-    MetricsRegionServer rsm = new MetricsRegionServer(wrapper, source);
-    MetricsRegionServerSource serverSource = rsm.getMetricsSource();
     HELPER.assertTag("serverName", "test", serverSource);
     HELPER.assertTag("clusterId", "tClusterId", serverSource);
     HELPER.assertTag("zookeeperQuorum", "zk", serverSource);
@@ -79,15 +88,12 @@ public class TestMetricsRegionServer {
 
   @Test
   public void testConstuctor() {
-    MetricsRegionServer rsm = new MetricsRegionServer(new MetricsRegionServerWrapperStub());
     assertNotNull("There should be a hadoop1/hadoop2 metrics source", rsm.getMetricsSource()
);
     assertNotNull("The RegionServerMetricsWrapper should be accessable", rsm.getRegionServerWrapper());
   }
 
   @Test
   public void testSlowCount() {
-    MetricsRegionServer rsm = new MetricsRegionServer(new MetricsRegionServerWrapperStub());
-    MetricsRegionServerSource serverSource = rsm.getMetricsSource();
     for (int i=0; i < 12; i ++) {
       rsm.updateAppend(12);
       rsm.updateAppend(1002);



Mime
View raw message