From f69f5ab3b6964b9124c07c97f13141227d5b87b9 Mon Sep 17 00:00:00 2001 From: Kai Zheng Date: Fri, 27 May 2016 04:42:53 +0800 Subject: [PATCH] HDFS-10434. Fix intermittent test failure of TestDataNodeErasureCodingMetrics. Contributed by Rakesh R --- .../TestDataNodeErasureCodingMetrics.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeErasureCodingMetrics.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeErasureCodingMetrics.java index e401fed1f7..c7e99c2d65 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeErasureCodingMetrics.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeErasureCodingMetrics.java @@ -36,6 +36,7 @@ import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; import org.apache.hadoop.metrics2.MetricsRecordBuilder; import static org.apache.hadoop.test.MetricsAsserts.assertCounter; +import static org.apache.hadoop.test.MetricsAsserts.getLongCounter; import static org.apache.hadoop.test.MetricsAsserts.getMetrics; import static org.junit.Assert.assertEquals; @@ -89,6 +90,21 @@ public void tearDown() { public void testEcTasks() throws Exception { DataNode workerDn = doTest("/testEcTasks"); MetricsRecordBuilder rb = getMetrics(workerDn.getMetrics().name()); + + // EcReconstructionTasks metric value will be updated in the finally block + // of striped reconstruction thread. Here, giving a grace period to finish + // EC reconstruction metric updates in DN. + LOG.info("Waiting to finish EC reconstruction metric updates in DN"); + int retries = 0; + while (retries < 20) { + long taskMetricValue = getLongCounter("EcReconstructionTasks", rb); + if (taskMetricValue > 0) { + break; + } + Thread.sleep(500); + retries++; + rb = getMetrics(workerDn.getMetrics().name()); + } assertCounter("EcReconstructionTasks", (long) 1, rb); assertCounter("EcFailedReconstructionTasks", (long) 0, rb); }