|
@@ -2766,4 +2766,75 @@ public class TestResourceLocalizationService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void testDirHandler() throws Exception {
|
|
|
+ File f = new File(basedir.toString());
|
|
|
+ String[] sDirs = new String[4];
|
|
|
+ List<Path> localDirs = new ArrayList<Path>(sDirs.length);
|
|
|
+ for (int i = 0; i < 4; ++i) {
|
|
|
+ sDirs[i] = f.getAbsolutePath() + i;
|
|
|
+ localDirs.add(new Path(sDirs[i]));
|
|
|
+ }
|
|
|
+ conf.setStrings(YarnConfiguration.NM_LOCAL_DIRS, sDirs);
|
|
|
+ LocalizerTracker mockLocalizerTracker = mock(LocalizerTracker.class);
|
|
|
+ DrainDispatcher dispatcher = new DrainDispatcher();
|
|
|
+ dispatcher.init(conf);
|
|
|
+ dispatcher.start();
|
|
|
+ EventHandler<ApplicationEvent> applicationBus = mock(EventHandler.class);
|
|
|
+ dispatcher.register(ApplicationEventType.class, applicationBus);
|
|
|
+ EventHandler<LocalizerEvent> localizerBus = mock(EventHandler.class);
|
|
|
+ dispatcher.register(LocalizerEventType.class, localizerBus);
|
|
|
+
|
|
|
+ ContainerExecutor exec = mock(ContainerExecutor.class);
|
|
|
+ LocalDirsHandlerService mockDirsHandler =
|
|
|
+ mock(LocalDirsHandlerService.class);
|
|
|
+ doReturn(new ArrayList<String>(Arrays.asList(sDirs))).when(
|
|
|
+ mockDirsHandler).getLocalDirsForCleanup();
|
|
|
+ // setup mocks
|
|
|
+ DeletionService delService = mock(DeletionService.class);
|
|
|
+ ResourceLocalizationService rawService =
|
|
|
+ new ResourceLocalizationService(dispatcher, exec, delService,
|
|
|
+ mockDirsHandler, nmContext);
|
|
|
+ ResourceLocalizationService spyService = spy(rawService);
|
|
|
+ doReturn(mockServer).when(spyService).createServer();
|
|
|
+ doReturn(mockLocalizerTracker).when(spyService).createLocalizerTracker(
|
|
|
+ isA(Configuration.class));
|
|
|
+
|
|
|
+ final String user = "user0";
|
|
|
+ // init application
|
|
|
+ final Application app = mock(Application.class);
|
|
|
+ final ApplicationId appId =
|
|
|
+ BuilderUtils.newApplicationId(314159265358979L, 3);
|
|
|
+ when(app.getUser()).thenReturn(user);
|
|
|
+ when(app.getAppId()).thenReturn(appId);
|
|
|
+ when(app.toString()).thenReturn(appId.toString());
|
|
|
+ try {
|
|
|
+ spyService.init(conf);
|
|
|
+ spyService.start();
|
|
|
+
|
|
|
+ spyService.handle(new ApplicationLocalizationEvent(
|
|
|
+ LocalizationEventType.INIT_APPLICATION_RESOURCES, app));
|
|
|
+ dispatcher.await();
|
|
|
+
|
|
|
+ LocalResourcesTracker appTracker =
|
|
|
+ spyService.getLocalResourcesTracker(
|
|
|
+ LocalResourceVisibility.APPLICATION, user, appId);
|
|
|
+ LocalResourcesTracker privTracker =
|
|
|
+ spyService.getLocalResourcesTracker(LocalResourceVisibility.PRIVATE,
|
|
|
+ user, appId);
|
|
|
+ LocalResourcesTracker pubTracker =
|
|
|
+ spyService.getLocalResourcesTracker(LocalResourceVisibility.PUBLIC,
|
|
|
+ user, appId);
|
|
|
+ Assert.assertNotNull("dirHandler for appTracker is null!",
|
|
|
+ ((LocalResourcesTrackerImpl)appTracker).getDirsHandler());
|
|
|
+ Assert.assertNotNull("dirHandler for privTracker is null!",
|
|
|
+ ((LocalResourcesTrackerImpl)privTracker).getDirsHandler());
|
|
|
+ Assert.assertNotNull("dirHandler for pubTracker is null!",
|
|
|
+ ((LocalResourcesTrackerImpl)pubTracker).getDirsHandler());
|
|
|
+ } finally {
|
|
|
+ dispatcher.stop();
|
|
|
+ delService.stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|