hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iwasak...@apache.org
Subject hadoop git commit: HADOOP-13439. Fix race between TestMetricsSystemImpl and TestGangliaMetrics. Contributed by Chen Liang.
Date Tue, 09 Aug 2016 01:42:33 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 0ad48aa2c -> 8f9b61852


HADOOP-13439. Fix race between TestMetricsSystemImpl and TestGangliaMetrics. Contributed by
Chen Liang.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/8f9b6185
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/8f9b6185
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/8f9b6185

Branch: refs/heads/trunk
Commit: 8f9b61852bf6600b65e49875fec172bac9e0a85d
Parents: 0ad48aa
Author: Masatake Iwasaki <iwasakims@apache.org>
Authored: Tue Aug 9 09:54:44 2016 +0900
Committer: Masatake Iwasaki <iwasakims@apache.org>
Committed: Tue Aug 9 09:54:44 2016 +0900

----------------------------------------------------------------------
 .../metrics2/impl/TestGangliaMetrics.java       | 48 ++++++++++++--------
 1 file changed, 28 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/8f9b6185/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java
index daf64bd..7e094ed 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java
@@ -50,23 +50,28 @@ import org.junit.Test;
 
 public class TestGangliaMetrics {
   public static final Log LOG = LogFactory.getLog(TestMetricsSystemImpl.class);
-  private final String[] expectedMetrics =
-    { "test.s1rec.C1",
-      "test.s1rec.G1",
-      "test.s1rec.Xxx",
-      "test.s1rec.Yyy",
-      "test.s1rec.S1NumOps",
-      "test.s1rec.S1AvgTime" };
+  // This is the prefix to locate the config file for this particular test
+  // This is to avoid using the same config file with other test cases,
+  // which can cause race conditions.
+  private String testNamePrefix = "gangliametrics";
+  private final String[] expectedMetrics = {
+      testNamePrefix + ".s1rec.C1",
+      testNamePrefix + ".s1rec.G1",
+      testNamePrefix + ".s1rec.Xxx",
+      testNamePrefix + ".s1rec.Yyy",
+      testNamePrefix + ".s1rec.S1NumOps",
+      testNamePrefix + ".s1rec.S1AvgTime"
+  };
 
   @Test
   public void testTagsForPrefix() throws Exception {
     ConfigBuilder cb = new ConfigBuilder()
-      .add("test.sink.ganglia.tagsForPrefix.all", "*")
-      .add("test.sink.ganglia.tagsForPrefix.some", "NumActiveSinks, " +
-              "NumActiveSources")
-      .add("test.sink.ganglia.tagsForPrefix.none", "");
+        .add(testNamePrefix + ".sink.ganglia.tagsForPrefix.all", "*")
+        .add(testNamePrefix + ".sink.ganglia.tagsForPrefix.some",
+          "NumActiveSinks, " + "NumActiveSources")
+        .add(testNamePrefix + ".sink.ganglia.tagsForPrefix.none", "");
     GangliaSink30 sink = new GangliaSink30();
-    sink.init(cb.subset("test.sink.ganglia"));
+    sink.init(cb.subset(testNamePrefix + ".sink.ganglia"));
 
     List<MetricsTag> tags = new ArrayList<MetricsTag>();
     tags.add(new MetricsTag(MsInfo.Context, "all"));
@@ -101,11 +106,14 @@ public class TestGangliaMetrics {
     // Setting long interval to avoid periodic publishing.
     // We manually publish metrics by MeticsSystem#publishMetricsNow here.
     ConfigBuilder cb = new ConfigBuilder().add("*.period", 120)
-        .add("test.sink.gsink30.context", "test") // filter out only "test"
-        .add("test.sink.gsink31.context", "test") // filter out only "test"
-        .save(TestMetricsConfig.getTestFilename("hadoop-metrics2-test"));
-
-    MetricsSystemImpl ms = new MetricsSystemImpl("Test");
+        .add(testNamePrefix
+            + ".sink.gsink30.context", testNamePrefix) // filter out only "test"
+        .add(testNamePrefix
+            + ".sink.gsink31.context", testNamePrefix) // filter out only "test"
+        .save(TestMetricsConfig.getTestFilename("hadoop-metrics2-"
+            + testNamePrefix));
+
+    MetricsSystemImpl ms = new MetricsSystemImpl(testNamePrefix);
     ms.start();
     TestSource s1 = ms.register("s1", "s1 desc", new TestSource("s1rec"));
     s1.c1.incr();
@@ -119,13 +127,13 @@ public class TestGangliaMetrics {
 
     // Setup test for GangliaSink30
     AbstractGangliaSink gsink30 = new GangliaSink30();
-    gsink30.init(cb.subset("test"));
+    gsink30.init(cb.subset(testNamePrefix));
     MockDatagramSocket mockds30 = new MockDatagramSocket();
     GangliaMetricsTestHelper.setDatagramSocket(gsink30, mockds30);
 
     // Setup test for GangliaSink31
     AbstractGangliaSink gsink31 = new GangliaSink31();
-    gsink31.init(cb.subset("test"));
+    gsink31.init(cb.subset(testNamePrefix));
     MockDatagramSocket mockds31 = new MockDatagramSocket();
     GangliaMetricsTestHelper.setDatagramSocket(gsink31, mockds31);
 
@@ -168,7 +176,7 @@ public class TestGangliaMetrics {
   }
 
   @SuppressWarnings("unused")
-  @Metrics(context="test")
+  @Metrics(context="gangliametrics")
   private static class TestSource {
     @Metric("C1 desc") MutableCounterLong c1;
     @Metric("XXX desc") MutableCounterLong xxx;


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message