slfan1989 commented on code in PR #6364:
URL: https://github.com/apache/hadoop/pull/6364#discussion_r1430952283


##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestReplicationPolicyExcludeSlowNodes.java:
##########
@@ -176,4 +185,58 @@ public void testSlowPeerTrackerEnabledClearSlowNodes() 
throws Exception {
     }
   }
 
+  /**
+   * Dependent on the SlowNode related config, therefore placing
+   * 'testCollectSlowNodesIpAddrFrequencyMetrics' unit test in the
+   * TestReplicationPolicyExcludeSlowNodes class.
+   * <br>
+   * Test metrics associated with CollectSlowNodesIpAddrFrequency.
+   */
+  @Test
+  public void testCollectSlowNodesIpAddrFrequencyMetrics() throws Exception {
+    namenode.getNamesystem().writeLock();
+    try {
+      FSNamesystem fsNamesystem = namenode.getNamesystem();
+      assertEquals("{}", fsNamesystem.getCollectSlowNodesIpAddrFrequencyMap(), 
"{}");
+      MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
+      ObjectName mxBeanName = new 
ObjectName("Hadoop:service=NameNode,name=FSNamesystemState");
+      String ipAddrFrequency =
+          (String) mBeanServer.getAttribute(mxBeanName, 
"CollectSlowNodesIpAddrFrequencyMap");
+      assertEquals("{}", ipAddrFrequency, "{}");
+
+      // add nodes
+      for (DatanodeDescriptor dataNode : dataNodes) {
+        dnManager.addDatanode(dataNode);
+      }
+
+      // mock slow nodes
+      SlowPeerTracker tracker = dnManager.getSlowPeerTracker();
+      Assert.assertNotNull(tracker);
+      OutlierMetrics outlierMetrics = new OutlierMetrics(0.0, 0.0, 0.0, 5.0);
+      tracker.addReport(dataNodes[0].getInfoAddr(), 
dataNodes[2].getInfoAddr(), outlierMetrics);
+      tracker.addReport(dataNodes[1].getInfoAddr(), 
dataNodes[2].getInfoAddr(), outlierMetrics);
+
+      // waiting for slow nodes collector run and collect at least 2 times
+      Thread.sleep(3000);

Review Comment:
   If we want to wait for a while, we use `GenericTestUtils.waitFor(..)` 
instead of `thread.sleep`.



-- 
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