예제 #1
0
 @SuppressWarnings("resource")
 private void testDeletionofStagingOnUnregistrationFailure(
     int maxAttempts, boolean shouldHaveDeleted) throws IOException {
   conf.set(MRJobConfig.MAPREDUCE_JOB_DIR, stagingJobDir);
   fs = mock(FileSystem.class);
   when(fs.delete(any(Path.class), anyBoolean())).thenReturn(true);
   // Staging Dir exists
   String user = UserGroupInformation.getCurrentUser().getShortUserName();
   Path stagingDir = MRApps.getStagingAreaDir(conf, user);
   when(fs.exists(stagingDir)).thenReturn(true);
   ApplicationId appId = ApplicationId.newInstance(0, 1);
   ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 1);
   JobId jobid = recordFactory.newRecordInstance(JobId.class);
   jobid.setAppId(appId);
   TestMRApp appMaster = new TestMRApp(attemptId, null, JobStateInternal.RUNNING, maxAttempts);
   appMaster.crushUnregistration = true;
   appMaster.init(conf);
   appMaster.start();
   appMaster.shutDownJob();
   ((RunningAppContext) appMaster.getContext()).computeIsLastAMRetry();
   if (shouldHaveDeleted) {
     Assert.assertEquals(new Boolean(true), appMaster.isLastAMRetry());
     verify(fs).delete(stagingJobPath, true);
   } else {
     Assert.assertEquals(new Boolean(false), appMaster.isLastAMRetry());
     verify(fs, never()).delete(stagingJobPath, true);
   }
 }
예제 #2
0
 @Test
 public void testDeletionofStaging() throws IOException {
   conf.set(MRJobConfig.MAPREDUCE_JOB_DIR, stagingJobDir);
   fs = mock(FileSystem.class);
   when(fs.delete(any(Path.class), anyBoolean())).thenReturn(true);
   // Staging Dir exists
   String user = UserGroupInformation.getCurrentUser().getShortUserName();
   Path stagingDir = MRApps.getStagingAreaDir(conf, user);
   when(fs.exists(stagingDir)).thenReturn(true);
   ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(), 0);
   ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 0);
   JobId jobid = recordFactory.newRecordInstance(JobId.class);
   jobid.setAppId(appId);
   ContainerAllocator mockAlloc = mock(ContainerAllocator.class);
   Assert.assertTrue(MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS > 1);
   MRAppMaster appMaster =
       new TestMRApp(
           attemptId, mockAlloc, JobStateInternal.RUNNING, MRJobConfig.DEFAULT_MR_AM_MAX_ATTEMPTS);
   appMaster.init(conf);
   appMaster.start();
   appMaster.shutDownJob();
   // test whether notifyIsLastAMRetry called
   Assert.assertEquals(true, ((TestMRApp) appMaster).getTestIsLastAMRetry());
   verify(fs).delete(stagingJobPath, true);
 }
예제 #3
0
 // mostly useful for parsing task/attempt id like strings
 public static JobId toJobID(String prefix, String s, Iterator<String> it) {
   ApplicationId appId = toAppID(prefix, s, it);
   shouldHaveNext(prefix, s, it);
   JobId jobId = RecordFactoryProvider.getRecordFactory(null).newRecordInstance(JobId.class);
   jobId.setAppId(appId);
   jobId.setId(Integer.parseInt(it.next()));
   return jobId;
 }
예제 #4
0
 @Test(timeout = 30000)
 public void testDeletionofStagingOnKill() throws IOException {
   conf.set(MRJobConfig.MAPREDUCE_JOB_DIR, stagingJobDir);
   fs = mock(FileSystem.class);
   when(fs.delete(any(Path.class), anyBoolean())).thenReturn(true);
   // Staging Dir exists
   String user = UserGroupInformation.getCurrentUser().getShortUserName();
   Path stagingDir = MRApps.getStagingAreaDir(conf, user);
   when(fs.exists(stagingDir)).thenReturn(true);
   ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(), 0);
   ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 0);
   JobId jobid = recordFactory.newRecordInstance(JobId.class);
   jobid.setAppId(appId);
   ContainerAllocator mockAlloc = mock(ContainerAllocator.class);
   MRAppMaster appMaster = new TestMRApp(attemptId, mockAlloc, 4);
   appMaster.init(conf);
   // simulate the process being killed
   MRAppMaster.MRAppMasterShutdownHook hook = new MRAppMaster.MRAppMasterShutdownHook(appMaster);
   hook.run();
   verify(fs, times(0)).delete(stagingJobPath, true);
 }