From 95c2c24cd0007ece9d7cd0fbe4c5932828e639d4 Mon Sep 17 00:00:00 2001 From: Daniel Templeton Date: Thu, 29 Dec 2016 10:49:29 -0800 Subject: [PATCH] MAPREDUCE-5155. Race condition in test case TestFetchFailure cause it to fail (Contributed by Haibo Chen via Daniel Templeton) --- .../mapreduce/v2/app/TestFetchFailure.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestFetchFailure.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestFetchFailure.java index 8d25079b97..cb2a29e390 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestFetchFailure.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestFetchFailure.java @@ -24,6 +24,7 @@ import java.util.Arrays; import java.util.Iterator; +import com.google.common.base.Supplier; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.mapred.TaskCompletionEvent; import org.apache.hadoop.mapreduce.Counters; @@ -45,6 +46,7 @@ import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptEvent; import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptEventType; import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptStatusUpdateEvent; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.yarn.event.EventHandler; import org.junit.Assert; import org.junit.Test; @@ -79,8 +81,19 @@ public void testFetchFailure() throws Exception { // wait for map success app.waitForState(mapTask, TaskState.SUCCEEDED); - - TaskAttemptCompletionEvent[] events = + + final int checkIntervalMillis = 10; + final int waitForMillis = 800; + GenericTestUtils.waitFor(new Supplier() { + @Override + public Boolean get() { + TaskAttemptCompletionEvent[] events = job + .getTaskAttemptCompletionEvents(0, 100); + return events.length >= 1; + } + }, checkIntervalMillis, waitForMillis); + + TaskAttemptCompletionEvent[] events = job.getTaskAttemptCompletionEvents(0, 100); Assert.assertEquals("Num completion events not correct", 1, events.length);