|
35 | 35 | import java.util.List; |
36 | 36 | import java.util.Map; |
37 | 37 |
|
| 38 | +import java.util.concurrent.TimeoutException; |
38 | 39 | import org.junit.Assert; |
39 | 40 |
|
40 | 41 | import org.apache.commons.logging.Log; |
@@ -180,7 +181,10 @@ public void testCrashed() throws Exception { |
180 | 181 | Iterator<TaskAttempt> itr = mapTask1.getAttempts().values().iterator(); |
181 | 182 | itr.next(); |
182 | 183 | TaskAttempt task1Attempt2 = itr.next(); |
183 | | - |
| 184 | + |
| 185 | + // wait for the second task attempt to be assigned. |
| 186 | + waitForContainerAssignment(task1Attempt2); |
| 187 | + |
184 | 188 | // This attempt will automatically fail because of the way ContainerLauncher |
185 | 189 | // is setup |
186 | 190 | // This attempt 'disappears' from JobHistory and so causes MAPREDUCE-3846 |
@@ -317,6 +321,21 @@ public void testCrashed() throws Exception { |
317 | 321 | // available in the failed attempt should be available here |
318 | 322 | } |
319 | 323 |
|
| 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 | + |
320 | 339 | /** |
321 | 340 | * AM with 3 maps and 0 reduce. AM crashes after the first two tasks finishes |
322 | 341 | * and recovers completely and succeeds in the second generation. |
@@ -1197,14 +1216,9 @@ public void testSpeculative() throws Exception { |
1197 | 1216 | TaskAttempt task1Attempt1 = t1it.next(); |
1198 | 1217 | TaskAttempt task1Attempt2 = t1it.next(); |
1199 | 1218 | TaskAttempt task2Attempt = mapTask2.getAttempts().values().iterator().next(); |
1200 | | - final TaskAttempt t2a = task2Attempt; |
1201 | 1219 |
|
1202 | 1220 | // 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); |
1208 | 1222 | ContainerId t1a2contId = task1Attempt2.getAssignedContainerID(); |
1209 | 1223 |
|
1210 | 1224 | LOG.info(t1a2contId.toString()); |
|
0 commit comments