public virtual void TestDeletionofStaging() { conf.Set(MRJobConfig.MapreduceJobDir, stagingJobDir); fs = Org.Mockito.Mockito.Mock <FileSystem>(); Org.Mockito.Mockito.When(fs.Delete(Matchers.Any <Path>(), Matchers.AnyBoolean())). ThenReturn(true); //Staging Dir exists string user = UserGroupInformation.GetCurrentUser().GetShortUserName(); Path stagingDir = MRApps.GetStagingAreaDir(conf, user); Org.Mockito.Mockito.When(fs.Exists(stagingDir)).ThenReturn(true); ApplicationId appId = ApplicationId.NewInstance(Runtime.CurrentTimeMillis(), 0); ApplicationAttemptId attemptId = ApplicationAttemptId.NewInstance(appId, 1); JobId jobid = recordFactory.NewRecordInstance <JobId>(); jobid.SetAppId(appId); ContainerAllocator mockAlloc = Org.Mockito.Mockito.Mock <ContainerAllocator>(); NUnit.Framework.Assert.IsTrue(MRJobConfig.DefaultMrAmMaxAttempts > 1); MRAppMaster appMaster = new TestStagingCleanup.TestMRApp(this, attemptId, mockAlloc , JobStateInternal.Running, MRJobConfig.DefaultMrAmMaxAttempts); appMaster.Init(conf); appMaster.Start(); appMaster.ShutDownJob(); //test whether notifyIsLastAMRetry called NUnit.Framework.Assert.AreEqual(true, ((TestStagingCleanup.TestMRApp)appMaster).GetTestIsLastAMRetry ()); Org.Mockito.Mockito.Verify(fs).Delete(stagingJobPath, true); }
// FIXME: // Disabled this test because currently, when shutdown hook triggered at // lastRetry in RM view, cleanup will not do. This should be supported after // YARN-2261 completed // @Test (timeout = 30000) /// <exception cref="System.IO.IOException"/> public virtual void TestDeletionofStagingOnKillLastTry() { conf.Set(MRJobConfig.MapreduceJobDir, stagingJobDir); fs = Org.Mockito.Mockito.Mock <FileSystem>(); Org.Mockito.Mockito.When(fs.Delete(Matchers.Any <Path>(), Matchers.AnyBoolean())). ThenReturn(true); //Staging Dir exists string user = UserGroupInformation.GetCurrentUser().GetShortUserName(); Path stagingDir = MRApps.GetStagingAreaDir(conf, user); Org.Mockito.Mockito.When(fs.Exists(stagingDir)).ThenReturn(true); ApplicationId appId = ApplicationId.NewInstance(Runtime.CurrentTimeMillis(), 0); ApplicationAttemptId attemptId = ApplicationAttemptId.NewInstance(appId, 1); JobId jobid = recordFactory.NewRecordInstance <JobId>(); jobid.SetAppId(appId); ContainerAllocator mockAlloc = Org.Mockito.Mockito.Mock <ContainerAllocator>(); MRAppMaster appMaster = new TestStagingCleanup.TestMRApp(this, attemptId, mockAlloc ); //no retry appMaster.Init(conf); NUnit.Framework.Assert.IsTrue("appMaster.isLastAMRetry() is false", appMaster.IsLastAMRetry ()); //simulate the process being killed MRAppMaster.MRAppMasterShutdownHook hook = new MRAppMaster.MRAppMasterShutdownHook (appMaster); hook.Run(); NUnit.Framework.Assert.IsTrue("MRAppMaster isn't stopped", appMaster.IsInState(Service.STATE .Stopped)); Org.Mockito.Mockito.Verify(fs).Delete(stagingJobPath, true); }
/// <exception cref="System.IO.IOException"/> private void TestDeletionofStagingOnUnregistrationFailure(int maxAttempts, bool shouldHaveDeleted ) { conf.Set(MRJobConfig.MapreduceJobDir, stagingJobDir); fs = Org.Mockito.Mockito.Mock <FileSystem>(); Org.Mockito.Mockito.When(fs.Delete(Matchers.Any <Path>(), Matchers.AnyBoolean())). ThenReturn(true); //Staging Dir exists string user = UserGroupInformation.GetCurrentUser().GetShortUserName(); Path stagingDir = MRApps.GetStagingAreaDir(conf, user); Org.Mockito.Mockito.When(fs.Exists(stagingDir)).ThenReturn(true); ApplicationId appId = ApplicationId.NewInstance(0, 1); ApplicationAttemptId attemptId = ApplicationAttemptId.NewInstance(appId, 1); JobId jobid = recordFactory.NewRecordInstance <JobId>(); jobid.SetAppId(appId); TestStagingCleanup.TestMRApp appMaster = new TestStagingCleanup.TestMRApp(this, attemptId , null, JobStateInternal.Running, maxAttempts); appMaster.crushUnregistration = true; appMaster.Init(conf); appMaster.Start(); appMaster.ShutDownJob(); ((MRAppMaster.RunningAppContext)appMaster.GetContext()).ResetIsLastAMRetry(); if (shouldHaveDeleted) { NUnit.Framework.Assert.AreEqual(true, appMaster.IsLastAMRetry()); Org.Mockito.Mockito.Verify(fs).Delete(stagingJobPath, true); } else { NUnit.Framework.Assert.AreEqual(false, appMaster.IsLastAMRetry()); Org.Mockito.Mockito.Verify(fs, Org.Mockito.Mockito.Never()).Delete(stagingJobPath , true); } }