eubnara commented on code in PR #8691:
URL: https://github.com/apache/hadoop/pull/8691#discussion_r4663331121
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/TestResourceLocalizationService.java:
##########
@@ -818,6 +822,76 @@ public void testLocalizerRunnerException() throws
Exception {
}
}
+ @Test
+ @Timeout(value = 10)
+ @SuppressWarnings("unchecked") // mocked generics
+ public void testDownloadingResourcesCleanedUpWhenDispatchFails()
+ throws Exception {
+ Dispatcher dispatcher = mock(Dispatcher.class);
+ EventHandler<Event> eventHandler = mock(EventHandler.class);
+ when(dispatcher.getEventHandler()).thenReturn(eventHandler);
+ // Simulate the localizer thread being interrupted by a container kill:
+ // dispatching the failure event throws instead of completing.
+ Mockito.doThrow(new YarnRuntimeException(new InterruptedException()))
+ .when(eventHandler).handle(isA(ContainerResourceFailedEvent.class));
+
+ ContainerExecutor exec = mock(ContainerExecutor.class);
+ DeletionService delService = mock(DeletionService.class);
+ LocalDirsHandlerService dirsHandlerSpy = spy(new
LocalDirsHandlerService());
+ dirsHandlerSpy.init(conf);
+ // Fail localization so LocalizerRunner.run() takes the error path.
+ Mockito.doThrow(new IOException("Simulated disk failure"))
+ .when(dirsHandlerSpy).getLocalPathForWrite(isA(String.class));
+
+ ResourceLocalizationService rls =
+ new ResourceLocalizationService(dispatcher, exec, delService,
+ dirsHandlerSpy, nmContext, metrics);
+
+ final ApplicationId appId =
+ BuilderUtils.newApplicationId(314159265358979L, 3);
+ final Container c = getMockContainer(appId, 42, "user0");
+ LocalizerRunner runner = rls.new LocalizerRunner(
+ new LocalizerContext("user0", c.getContainerId(), null),
+ c.getContainerId().toString());
+
+ // A resource that was in DOWNLOADING state when the localizer died.
+ LocalizedResource rsrc = mock(LocalizedResource.class);
+ when(rsrc.getLocalPath()).thenReturn(
+ new Path("/local/usercache/user0/filecache/10/foo.jar"));
+ LocalizerResourceRequestEvent scheduledEvent =
+ mock(LocalizerResourceRequestEvent.class);
+ when(scheduledEvent.getResource()).thenReturn(rsrc);
+ runner.scheduled.put(mock(LocalResourceRequest.class), scheduledEvent);
+
+ // Must not propagate the dispatch failure, and must still unlock the
+ // DOWNLOADING resource and schedule the deletion tasks.
+ runner.run();
+
+ // The interrupt status must be restored after the dispatch failure was
+ // swallowed. Thread.interrupted() also clears it for the test thread.
+ assertTrue(Thread.interrupted());
Review Comment:
Done, added the assertFalse precondition and read the flag in a finally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]