HDFS-10434. Fix intermittent test failure of TestDataNodeErasureCodingMetrics. Contributed by Rakesh R

This commit is contained in:
Kai Zheng 2016-05-27 04:42:53 +08:00
parent a6c79f92d5
commit f69f5ab3b6

View File

@ -36,6 +36,7 @@
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.hadoop.metrics2.MetricsRecordBuilder; import org.apache.hadoop.metrics2.MetricsRecordBuilder;
import static org.apache.hadoop.test.MetricsAsserts.assertCounter; 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.apache.hadoop.test.MetricsAsserts.getMetrics;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -89,6 +90,21 @@ public void tearDown() {
public void testEcTasks() throws Exception { public void testEcTasks() throws Exception {
DataNode workerDn = doTest("/testEcTasks"); DataNode workerDn = doTest("/testEcTasks");
MetricsRecordBuilder rb = getMetrics(workerDn.getMetrics().name()); 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("EcReconstructionTasks", (long) 1, rb);
assertCounter("EcFailedReconstructionTasks", (long) 0, rb); assertCounter("EcFailedReconstructionTasks", (long) 0, rb);
} }