|
18 | 18 |
|
19 | 19 | package org.apache.tez.dag.app.dag.impl;
|
20 | 20 |
|
| 21 | +import org.apache.hadoop.yarn.util.MonotonicClock; |
| 22 | +import org.apache.tez.common.counters.DAGCounter; |
21 | 23 | import org.apache.tez.dag.app.MockClock;
|
22 | 24 | import static org.junit.Assert.assertEquals;
|
23 | 25 | import static org.junit.Assert.assertFalse;
|
@@ -2261,6 +2263,85 @@ public void testMapTaskIsBlamedByDownstreamAttemptsFromDifferentHosts() {
|
2261 | 2263 | Assert.assertEquals(TaskAttemptStateInternal.FAILED, resultState2);
|
2262 | 2264 | }
|
2263 | 2265 |
|
| 2266 | + @Test |
| 2267 | + public void testDAGCounterUpdateEvent(){ |
| 2268 | + TaskAttemptImpl taImpl = getMockTaskAttempt(); |
| 2269 | + |
| 2270 | + DAGEventCounterUpdate counterUpdateSucceeded = TaskAttemptImpl.createDAGCounterUpdateEventTAFinished(taImpl, |
| 2271 | + TaskAttemptState.SUCCEEDED); |
| 2272 | + List<DAGEventCounterUpdate.CounterIncrementalUpdate> succeededUpdates = counterUpdateSucceeded.getCounterUpdates(); |
| 2273 | + // SUCCEEDED task related counters are updated (+ WALL_CLOCK_MILLIS) |
| 2274 | + assertCounterIncrementalUpdate(succeededUpdates, DAGCounter.NUM_SUCCEEDED_TASKS, 1); |
| 2275 | + assertCounterIncrementalUpdate(succeededUpdates, DAGCounter.DURATION_SUCCEEDED_TASKS_MILLIS, 1000); |
| 2276 | + assertCounterIncrementalUpdate(succeededUpdates, DAGCounter.WALL_CLOCK_MILLIS, 1000); |
| 2277 | + // other counters are not updated (no FAILED, no KILLED) |
| 2278 | + assertCounterIncrementalUpdateNotFound(succeededUpdates, DAGCounter.NUM_FAILED_TASKS); |
| 2279 | + assertCounterIncrementalUpdateNotFound(succeededUpdates, DAGCounter.NUM_KILLED_TASKS); |
| 2280 | + assertCounterIncrementalUpdateNotFound(succeededUpdates, DAGCounter.DURATION_FAILED_TASKS_MILLIS); |
| 2281 | + assertCounterIncrementalUpdateNotFound(succeededUpdates, DAGCounter.DURATION_KILLED_TASKS_MILLIS); |
| 2282 | + |
| 2283 | + DAGEventCounterUpdate counterUpdateFailed = TaskAttemptImpl.createDAGCounterUpdateEventTAFinished(taImpl, |
| 2284 | + TaskAttemptState.FAILED); |
| 2285 | + List<DAGEventCounterUpdate.CounterIncrementalUpdate> failedUpdates = counterUpdateFailed.getCounterUpdates(); |
| 2286 | + // FAILED task related counters are updated (+ WALL_CLOCK_MILLIS) |
| 2287 | + assertCounterIncrementalUpdate(failedUpdates, DAGCounter.NUM_FAILED_TASKS, 1); |
| 2288 | + assertCounterIncrementalUpdate(failedUpdates, DAGCounter.DURATION_FAILED_TASKS_MILLIS, 1000); |
| 2289 | + assertCounterIncrementalUpdate(failedUpdates, DAGCounter.WALL_CLOCK_MILLIS, 1000); |
| 2290 | + // other counters are not updated (no SUCCEEDED, no KILLED) |
| 2291 | + assertCounterIncrementalUpdateNotFound(failedUpdates, DAGCounter.NUM_SUCCEEDED_TASKS); |
| 2292 | + assertCounterIncrementalUpdateNotFound(failedUpdates, DAGCounter.NUM_KILLED_TASKS); |
| 2293 | + assertCounterIncrementalUpdateNotFound(failedUpdates, DAGCounter.DURATION_KILLED_TASKS_MILLIS); |
| 2294 | + assertCounterIncrementalUpdateNotFound(failedUpdates, DAGCounter.DURATION_SUCCEEDED_TASKS_MILLIS); |
| 2295 | + |
| 2296 | + DAGEventCounterUpdate counterUpdateKilled = TaskAttemptImpl.createDAGCounterUpdateEventTAFinished(taImpl, |
| 2297 | + TaskAttemptState.KILLED); |
| 2298 | + List<DAGEventCounterUpdate.CounterIncrementalUpdate> killedUpdates = counterUpdateKilled.getCounterUpdates(); |
| 2299 | + // KILLED task related counters are updated (+ WALL_CLOCK_MILLIS) |
| 2300 | + assertCounterIncrementalUpdate(killedUpdates, DAGCounter.NUM_KILLED_TASKS, 1); |
| 2301 | + assertCounterIncrementalUpdate(killedUpdates, DAGCounter.DURATION_KILLED_TASKS_MILLIS, 1000); |
| 2302 | + assertCounterIncrementalUpdate(killedUpdates, DAGCounter.WALL_CLOCK_MILLIS, 1000); |
| 2303 | + // other counters are not updated (no SUCCEEDED, no FAILED) |
| 2304 | + assertCounterIncrementalUpdateNotFound(killedUpdates, DAGCounter.NUM_SUCCEEDED_TASKS); |
| 2305 | + assertCounterIncrementalUpdateNotFound(killedUpdates, DAGCounter.NUM_FAILED_TASKS); |
| 2306 | + assertCounterIncrementalUpdateNotFound(killedUpdates, DAGCounter.DURATION_FAILED_TASKS_MILLIS); |
| 2307 | + assertCounterIncrementalUpdateNotFound(failedUpdates, DAGCounter.DURATION_SUCCEEDED_TASKS_MILLIS); |
| 2308 | + } |
| 2309 | + |
| 2310 | + private TaskAttemptImpl getMockTaskAttempt() { |
| 2311 | + ApplicationId appId = ApplicationId.newInstance(1, 2); |
| 2312 | + ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance( |
| 2313 | + appId, 0); |
| 2314 | + TezDAGID dagID = TezDAGID.getInstance(appId, 1); |
| 2315 | + TezVertexID vertexID = TezVertexID.getInstance(dagID, 1); |
| 2316 | + TezTaskID taskID = TezTaskID.getInstance(vertexID, 1); |
| 2317 | + |
| 2318 | + return new MockTaskAttemptImpl(taskID, 1, mock(EventHandler.class), |
| 2319 | + mock(TaskCommunicatorManagerInterface.class), new Configuration(), new MonotonicClock(), |
| 2320 | + mock(TaskHeartbeatHandler.class), mock(AppContext.class), false, |
| 2321 | + mock(Resource.class), mock(ContainerContext.class), false); |
| 2322 | + } |
| 2323 | + |
| 2324 | + private void assertCounterIncrementalUpdate(List<DAGEventCounterUpdate.CounterIncrementalUpdate> counterUpdates, |
| 2325 | + DAGCounter counter, int expectedValue) { |
| 2326 | + for (DAGEventCounterUpdate.CounterIncrementalUpdate update : counterUpdates) { |
| 2327 | + if (update.getCounterKey().equals(counter) && update.getIncrementValue() == expectedValue) { |
| 2328 | + return; |
| 2329 | + } |
| 2330 | + } |
| 2331 | + Assert.fail( |
| 2332 | + String.format("Haven't found counter update %s=%d, instead seen: %s", counter, expectedValue, counterUpdates)); |
| 2333 | + } |
| 2334 | + |
| 2335 | + private void assertCounterIncrementalUpdateNotFound( |
| 2336 | + List<DAGEventCounterUpdate.CounterIncrementalUpdate> counterUpdates, DAGCounter counter) { |
| 2337 | + for (DAGEventCounterUpdate.CounterIncrementalUpdate update : counterUpdates) { |
| 2338 | + if (update.getCounterKey().equals(counter)) { |
| 2339 | + Assert.fail( |
| 2340 | + String.format("Found counter update %s=%d, which is not expected", counter, update.getIncrementValue())); |
| 2341 | + } |
| 2342 | + } |
| 2343 | + } |
| 2344 | + |
2264 | 2345 | private Event verifyEventType(List<Event> events,
|
2265 | 2346 | Class<? extends Event> eventClass, int expectedOccurences) {
|
2266 | 2347 | int count = 0;
|
@@ -2344,6 +2425,11 @@ protected void logJobHistoryAttemptUnsuccesfulCompletion(
|
2344 | 2425 | protected void sendInputFailedToConsumers() {
|
2345 | 2426 | inputFailedReported = true;
|
2346 | 2427 | }
|
| 2428 | + |
| 2429 | + @Override |
| 2430 | + public long getDurationNs(){ |
| 2431 | + return 1000000000L; // 1000000000ns = 1000ms |
| 2432 | + } |
2347 | 2433 | }
|
2348 | 2434 |
|
2349 | 2435 | private static ContainerContext createFakeContainerContext() {
|
|
0 commit comments