Skip to content

Commit f70f522

Browse files
committed
MAPREDUCE-4784. TestRecovery occasionally fails. Contributed by Haibo Chen
(cherry picked from commit af50860) Conflicts: hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestRecovery.java
1 parent 320be1b commit f70f522

File tree

1 file changed

+21
-7
lines changed
  • hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app

1 file changed

+21
-7
lines changed

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/TestRecovery.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.List;
3636
import java.util.Map;
3737

38+
import java.util.concurrent.TimeoutException;
3839
import org.junit.Assert;
3940

4041
import org.apache.commons.logging.Log;
@@ -180,7 +181,10 @@ public void testCrashed() throws Exception {
180181
Iterator<TaskAttempt> itr = mapTask1.getAttempts().values().iterator();
181182
itr.next();
182183
TaskAttempt task1Attempt2 = itr.next();
183-
184+
185+
// wait for the second task attempt to be assigned.
186+
waitForContainerAssignment(task1Attempt2);
187+
184188
// This attempt will automatically fail because of the way ContainerLauncher
185189
// is setup
186190
// This attempt 'disappears' from JobHistory and so causes MAPREDUCE-3846
@@ -317,6 +321,21 @@ public void testCrashed() throws Exception {
317321
// available in the failed attempt should be available here
318322
}
319323

324+
/**
325+
* Wait for a task attempt to be assigned a container to.
326+
* @param task1Attempt2 the task attempt to wait for its container assignment
327+
* @throws TimeoutException if times out
328+
* @throws InterruptedException if interrupted
329+
*/
330+
public static void waitForContainerAssignment(final TaskAttempt task1Attempt2)
331+
throws TimeoutException, InterruptedException {
332+
GenericTestUtils.waitFor(new Supplier<Boolean>() {
333+
@Override public Boolean get() {
334+
return task1Attempt2.getAssignedContainerID() != null;
335+
}
336+
}, 10, 10000);
337+
}
338+
320339
/**
321340
* AM with 3 maps and 0 reduce. AM crashes after the first two tasks finishes
322341
* and recovers completely and succeeds in the second generation.
@@ -1197,14 +1216,9 @@ public void testSpeculative() throws Exception {
11971216
TaskAttempt task1Attempt1 = t1it.next();
11981217
TaskAttempt task1Attempt2 = t1it.next();
11991218
TaskAttempt task2Attempt = mapTask2.getAttempts().values().iterator().next();
1200-
final TaskAttempt t2a = task2Attempt;
12011219

12021220
// wait for the second task attempt to be assigned.
1203-
GenericTestUtils.waitFor(new Supplier<Boolean>() {
1204-
@Override public Boolean get() {
1205-
return t2a.getAssignedContainerID() != null;
1206-
}
1207-
}, 10, 10000);
1221+
waitForContainerAssignment(task1Attempt2);
12081222
ContainerId t1a2contId = task1Attempt2.getAssignedContainerID();
12091223

12101224
LOG.info(t1a2contId.toString());

0 commit comments

Comments
 (0)