Neilxzn commented on a change in pull request #3426:
URL: https://github.com/apache/hadoop/pull/3426#discussion_r710926210



##########
File path: 
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/sink/TestPrometheusMetricsSink.java
##########
@@ -219,6 +226,62 @@ public void testNamingWhitespaces() {
         sink.prometheusName(recordName, metricName));
   }
 
+  /**
+   * testTopMetricsPublish.
+   */
+  @Test
+  public void testTopMetricsPublish() throws IOException {
+    MetricsSystem metrics = DefaultMetricsSystem.instance();
+
+    metrics.init("test");
+
+    //GIVEN
+    PrometheusMetricsSink sink = new PrometheusMetricsSink();
+
+    metrics.register("prometheus", "prometheus", sink);
+    TestTopMetrics topMetrics = new TestTopMetrics();
+    topMetrics.add("60000");
+    topMetrics.add("1500000");
+    metrics.register(TestTopMetrics.TOPMETRICS_METRICS_SOURCE_NAME,
+        "Top N operations by user", topMetrics);
+
+    metrics.start();
+
+    metrics.publishMetricsNow();
+    ByteArrayOutputStream stream = new ByteArrayOutputStream();
+    OutputStreamWriter writer = new OutputStreamWriter(stream, UTF_8);
+
+    //WHEN
+    sink.writeMetrics(writer);
+    writer.flush();
+
+    //THEN
+    String writtenMetrics = stream.toString(UTF_8.name());
+    System.out.println(writtenMetrics);
+    Assert.assertTrue(
+        "The expected metric line is missing from prometheus metrics output",
+        writtenMetrics.contains(
+            
"nn_top_user_op_counts_window_ms_60000_total_count{context=\"dfs\"")
+    );
+    Assert.assertTrue(
+        "The expected metric line is missing from prometheus metrics output",
+        writtenMetrics.contains(
+            "nn_top_user_op_counts_window_ms_60000_count{"));
+
+    Assert.assertTrue(
+        "The expected metric line is missing from prometheus metrics output",
+        writtenMetrics.contains(
+            "nn_top_user_op_counts_window_ms_1500000_count{"));
+
+    Assert.assertTrue(
+        "The expected metric line is missing from prometheus metrics output",
+        writtenMetrics.contains(
+            "op=\"rename\",user=\"hadoop/[email protected]\""));

Review comment:
       done .  Replace these test with AssertJ
   ```
       assertThat(writtenMetrics)
           .contains(
               
"nn_top_user_op_counts_window_ms_60000_total_count{context=\"dfs\"");
       assertThat(writtenMetrics)
           .contains(
               "nn_top_user_op_counts_window_ms_60000_count{");
       assertThat(writtenMetrics)
           .contains(
               "nn_top_user_op_counts_window_ms_1500000_count{");
       assertThat(writtenMetrics)
           .contains(
               "op=\"rename\",user=\"hadoop/[email protected]\"");
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to