@Test (timeout = 30000) public void testAppNewKill() throws IOException { LOG.info("--- START: testAppNewKill ---"); UserGroupInformation fooUser = UserGroupInformation.createUserForTesting( "fooTestAppNewKill", new String[] {"foo_group"}); RMApp application = createNewTestApp(null); // NEW => KILLED event RMAppEventType.KILL RMAppEvent event = new RMAppKillByClientEvent( application.getApplicationId(), "Application killed by user.", fooUser, Server.getRemoteIp()); application.handle(event); rmDispatcher.await(); sendAppUpdateSavedEvent(application); assertKilled(application); assertAppFinalStateNotSaved(application); verifyApplicationFinished(RMAppState.KILLED); verifyAppRemovedSchedulerEvent(RMAppState.KILLED); verifyRMAppFieldsForFinalTransitions(application); }
@Test public void testAppAcceptedAttemptKilled() throws IOException, InterruptedException { LOG.info("--- START: testAppAcceptedAttemptKilled ---"); RMApp application = testCreateAppAccepted(null); // ACCEPTED => FINAL_SAVING event RMAppEventType.ATTEMPT_KILLED // When application recovery happens for attempt is KILLED but app is // RUNNING. RMAppEvent event = new RMAppEvent(application.getApplicationId(), RMAppEventType.ATTEMPT_KILLED, "Application killed by user."); application.handle(event); rmDispatcher.await(); assertAppState(RMAppState.FINAL_SAVING, application); sendAppUpdateSavedEvent(application); assertKilled(application); assertAppFinalStateSaved(application); verifyApplicationFinished(RMAppState.KILLED); verifyAppRemovedSchedulerEvent(RMAppState.KILLED); }
@Test public void testAppNewReject() throws IOException { LOG.info("--- START: testAppNewReject ---"); RMApp application = createNewTestApp(null); // NEW => FAILED event RMAppEventType.APP_REJECTED String rejectedText = "Test Application Rejected"; RMAppEvent event = new RMAppEvent(application.getApplicationId(), RMAppEventType.APP_REJECTED, rejectedText); application.handle(event); rmDispatcher.await(); sendAppUpdateSavedEvent(application); assertFailed(application, rejectedText); assertAppFinalStateSaved(application); verifyApplicationFinished(RMAppState.FAILED); verifyRMAppFieldsForFinalTransitions(application); }
private void assertKilled(RMApp application) { assertTimesAtFinish(application); assertAppState(RMAppState.KILLED, application); assertFinalAppStatus(FinalApplicationStatus.KILLED, application); StringBuilder diag = application.getDiagnostics(); Assert.assertEquals("application diagnostics is not correct", "Application killed by user.", diag.toString()); }
@Test(timeout = 30000) public void testAppsRecoveringStates() throws Exception { RMState state = new RMState(); Map<ApplicationId, ApplicationStateData> applicationState = state.getApplicationState(); createRMStateForApplications(applicationState, RMAppState.FINISHED); createRMStateForApplications(applicationState, RMAppState.KILLED); createRMStateForApplications(applicationState, RMAppState.FAILED); for (ApplicationStateData appState : applicationState.values()) { testRecoverApplication(appState, state); } }
protected RMApp testCreateAppRunning( ApplicationSubmissionContext submissionContext) throws IOException { RMApp application = testCreateAppAccepted(submissionContext); // ACCEPTED => RUNNING event RMAppEventType.ATTEMPT_REGISTERED RMAppEvent event = new RMAppEvent(application.getApplicationId(), RMAppEventType.ATTEMPT_REGISTERED); application.handle(event); assertStartTimeSet(application); assertAppState(RMAppState.RUNNING, application); assertFinalAppStatus(FinalApplicationStatus.UNDEFINED, application); return application; }
@Test public void testAppSubmittedKill() throws IOException, InterruptedException { LOG.info("--- START: testAppSubmittedKill---"); RMApp application = testCreateAppSubmittedNoRecovery(null); UserGroupInformation fooUser = UserGroupInformation.createUserForTesting( "fooTestAppSubmittedKill", new String[] {"foo_group"}); // SUBMITTED => KILLED event RMAppEventType.KILL RMAppEvent event = new RMAppKillByClientEvent( application.getApplicationId(), "Application killed by user.", fooUser, Server.getRemoteIp()); application.handle(event); rmDispatcher.await(); sendAppUpdateSavedEvent(application); assertKilled(application); assertAppFinalStateSaved(application); verifyApplicationFinished(RMAppState.KILLED); verifyAppRemovedSchedulerEvent(RMAppState.KILLED); verifyRMAppFieldsForFinalTransitions(application); }
@Test public void testAppRunningKill() throws IOException { LOG.info("--- START: testAppRunningKill ---"); RMApp application = testCreateAppRunning(null); // RUNNING => KILLED event RMAppEventType.KILL UserGroupInformation fooUser = UserGroupInformation.createUserForTesting( "fooTestAppRunningKill", new String[] {"foo_group"}); // SUBMITTED => KILLED event RMAppEventType.KILL RMAppEvent event = new RMAppKillByClientEvent( application.getApplicationId(), "Application killed by user.", fooUser, Server.getRemoteIp()); application.handle(event); rmDispatcher.await(); sendAttemptUpdateSavedEvent(application); sendAppUpdateSavedEvent(application); assertKilled(application); verifyApplicationFinished(RMAppState.KILLED); verifyAppRemovedSchedulerEvent(RMAppState.KILLED); verifyRMAppFieldsForFinalTransitions(application); }
UserGroupInformation fooUser = UserGroupInformation.createUserForTesting( "fooTestAppKilledKill", new String[] { "foo_group" }); RMApp application = testCreateAppRunning(null); application.handle(event); rmDispatcher.await(); sendAttemptUpdateSavedEvent(application); sendAppUpdateSavedEvent(application); assertTimesAtFinish(application); assertAppState(RMAppState.KILLED, application); application.handle(event); rmDispatcher.await(); assertTimesAtFinish(application); assertAppState(RMAppState.KILLED, application); application.handle(event); rmDispatcher.await(); assertTimesAtFinish(application); assertAppState(RMAppState.KILLED, application); application.handle(event); rmDispatcher.await(); assertTimesAtFinish(application); assertAppState(RMAppState.KILLED, application); verifyApplicationFinished(RMAppState.KILLED); assertTimesAtFinish(application); assertAppState(RMAppState.KILLED, application);
RMApp application = testCreateAppRunning(null); RMAppAttempt appAttempt = application.getCurrentAppAttempt(); int expectedAttemptId = 1; application.handle(event); rmDispatcher.await(); assertAppState(RMAppState.ACCEPTED, application); appAttempt = application.getCurrentAppAttempt(); Assert.assertEquals(++expectedAttemptId, application.handle(event); rmDispatcher.await(); assertAppState(RMAppState.ACCEPTED, application); event = new RMAppEvent(application.getApplicationId(), application.handle(event); rmDispatcher.await(); assertAppState(RMAppState.RUNNING, application); application.handle(event); rmDispatcher.await(); sendAppUpdateSavedEvent(application); assertFailed(application, ".*Failing the application.*"); assertAppFinalStateSaved(application); application.handle(event); rmDispatcher.await(); assertFailed(application, ".*Failing the application.*");
LOG.info("--- START: testAppAcceptedFailed ---"); RMApp application = testCreateAppAccepted(null); RMAppEventType.ATTEMPT_FAILED, "", false); application.handle(event); assertAppState(RMAppState.ACCEPTED, application); event = new RMAppEvent(application.getApplicationId(), application.handle(event); rmDispatcher.await(); assertAppState(RMAppState.ACCEPTED, application); application.handle(event); rmDispatcher.await(); sendAppUpdateSavedEvent(application); assertFailed(application, ".*" + message + ".*Failing the application.*"); assertAppFinalStateSaved(application); verifyApplicationFinished(RMAppState.FAILED);
@Test (timeout = 30000) public void testAppSubmittedRejected() throws IOException { LOG.info("--- START: testAppSubmittedRejected ---"); RMApp application = testCreateAppSubmittedNoRecovery(null); // SUBMITTED => FAILED event RMAppEventType.APP_REJECTED String rejectedText = "app rejected"; RMAppEvent event = new RMAppEvent(application.getApplicationId(), RMAppEventType.APP_REJECTED, rejectedText); application.handle(event); rmDispatcher.await(); sendAppUpdateSavedEvent(application); assertFailed(application, rejectedText); assertAppFinalStateSaved(application); verifyApplicationFinished(RMAppState.FAILED); verifyRMAppFieldsForFinalTransitions(application); }
@Test (timeout = 30000) public void testAppNewSavingKill() throws IOException { LOG.info("--- START: testAppNewSavingKill ---"); RMApp application = testCreateAppNewSaving(null); // NEW_SAVING => KILLED event RMAppEventType.KILL UserGroupInformation fooUser = UserGroupInformation.createUserForTesting( "fooTestAppNewSavingKill", new String[] {"foo_group"}); RMAppEvent event = new RMAppKillByClientEvent( application.getApplicationId(), "Application killed by user.", fooUser, Server.getRemoteIp()); application.handle(event); rmDispatcher.await(); sendAppUpdateSavedEvent(application); assertKilled(application); verifyApplicationFinished(RMAppState.KILLED); verifyAppRemovedSchedulerEvent(RMAppState.KILLED); verifyRMAppFieldsForFinalTransitions(application); }
@Test (timeout = 30000) public void testAppNewSavingReject() throws IOException { LOG.info("--- START: testAppNewSavingReject ---"); RMApp application = testCreateAppNewSaving(null); // NEW_SAVING => FAILED event RMAppEventType.APP_REJECTED String rejectedText = "Test Application Rejected"; RMAppEvent event = new RMAppEvent(application.getApplicationId(), RMAppEventType.APP_REJECTED, rejectedText); application.handle(event); rmDispatcher.await(); sendAppUpdateSavedEvent(application); assertFailed(application, rejectedText); assertAppFinalStateSaved(application); verifyApplicationFinished(RMAppState.FAILED); verifyRMAppFieldsForFinalTransitions(application); }
@Test (timeout = 30000) public void testAppFailedFailed() throws IOException { LOG.info("--- START: testAppFailedFailed ---"); RMApp application = testCreateAppNewSaving(null); // NEW_SAVING => FAILED event RMAppEventType.APP_REJECTED RMAppEvent event = new RMAppEvent(application.getApplicationId(), RMAppEventType.APP_REJECTED, ""); application.handle(event); rmDispatcher.await(); sendAppUpdateSavedEvent(application); assertTimesAtFinish(application); assertAppState(RMAppState.FAILED, application); // FAILED => FAILED event RMAppEventType.KILL event = new RMAppEvent(application.getApplicationId(), RMAppEventType.KILL, "Application killed by user."); application.handle(event); rmDispatcher.await(); assertTimesAtFinish(application); assertAppState(RMAppState.FAILED, application); verifyApplicationFinished(RMAppState.FAILED); assertTimesAtFinish(application); assertAppState(RMAppState.FAILED, application); verifyRMAppFieldsForFinalTransitions(application); }
@Test public void testUnmanagedApp() throws IOException { ApplicationSubmissionContext subContext = new ApplicationSubmissionContextPBImpl(); subContext.setUnmanagedAM(true); // test success path LOG.info("--- START: testUnmanagedAppSuccessPath ---"); final String diagMsg = "some diagnostics"; RMApp application = testCreateAppFinished(subContext, diagMsg); Assert.assertTrue("Finished app missing diagnostics", application.getDiagnostics().indexOf(diagMsg) != -1); // reset the counter of Mockito.verify reset(writer); reset(publisher); // test app fails after 1 app attempt failure LOG.info("--- START: testUnmanagedAppFailPath ---"); application = testCreateAppRunning(subContext); RMAppEvent event = new RMAppFailedAttemptEvent( application.getApplicationId(), RMAppEventType.ATTEMPT_FAILED, "", false); application.handle(event); rmDispatcher.await(); RMAppAttempt appAttempt = application.getCurrentAppAttempt(); Assert.assertEquals(1, appAttempt.getAppAttemptId().getAttemptId()); sendAppUpdateSavedEvent(application); assertFailed(application, ".*Unmanaged application.*Failing the application.*"); assertAppFinalStateSaved(application); verifyRMAppFieldsForFinalTransitions(application); }
protected RMApp testCreateAppFinished( ApplicationSubmissionContext submissionContext, String diagnostics) throws IOException { // unmanaged AMs don't use the FINISHING state RMApp application = null; if (submissionContext != null && submissionContext.getUnmanagedAM()) { application = testCreateAppRunning(submissionContext); } else { application = testCreateAppFinishing(submissionContext); } // RUNNING/FINISHING => FINISHED event RMAppEventType.ATTEMPT_FINISHED RMAppEvent finishedEvent = new RMAppEvent(application.getApplicationId(), RMAppEventType.ATTEMPT_FINISHED, diagnostics); application.handle(finishedEvent); assertAppState(RMAppState.FINISHED, application); assertTimesAtFinish(application); // finished without a proper unregister implies failed assertFinalAppStatus(FinalApplicationStatus.FAILED, application); Assert.assertTrue("Finished app missing diagnostics", application.getDiagnostics().indexOf(diagnostics) != -1); return application; }
@Test public void testAppFinishedFinished() throws IOException { LOG.info("--- START: testAppFinishedFinished ---"); RMApp application = testCreateAppFinished(null, ""); // FINISHED => FINISHED event RMAppEventType.KILL RMAppEvent event = new RMAppEvent(application.getApplicationId(), RMAppEventType.KILL, "Application killed by user."); application.handle(event); rmDispatcher.await(); assertTimesAtFinish(application); assertAppState(RMAppState.FINISHED, application); StringBuilder diag = application.getDiagnostics(); Assert.assertEquals("application diagnostics is not correct", "", diag.toString()); verifyApplicationFinished(RMAppState.FINISHED); verifyRMAppFieldsForFinalTransitions(application); }
@Test public void testAppFinalSavingToFinished() throws IOException { LOG.info("--- START: testAppFinalSavingToFinished ---"); RMApp application = testCreateAppFinalSaving(null); final String diagMsg = "some diagnostics"; // attempt_finished event comes before attempt_saved event RMAppEvent event = new RMAppEvent(application.getApplicationId(), RMAppEventType.ATTEMPT_FINISHED, diagMsg); application.handle(event); assertAppState(RMAppState.FINAL_SAVING, application); RMAppEvent appUpdated = new RMAppEvent(application.getApplicationId(), RMAppEventType.APP_UPDATE_SAVED); application.handle(appUpdated); assertAppState(RMAppState.FINISHED, application); assertTimesAtFinish(application); // finished without a proper unregister implies failed assertFinalAppStatus(FinalApplicationStatus.FAILED, application); Assert.assertTrue("Finished app missing diagnostics", application .getDiagnostics().indexOf(diagMsg) != -1); verifyRMAppFieldsForFinalTransitions(application); }
@Test (timeout = 30000) public void testAppNewSavingSaveReject() throws IOException { LOG.info("--- START: testAppNewSavingSaveReject ---"); RMApp application = testCreateAppNewSaving(null); // NEW_SAVING => FAILED event RMAppEventType.APP_SAVE_FAILED String rejectedText = "Test Application Rejected"; RMAppEvent event = new RMAppEvent(application.getApplicationId(), RMAppEventType.APP_SAVE_FAILED, rejectedText); application.handle(event); rmDispatcher.await(); assertFailed(application, rejectedText); verify(store, times(0)).updateApplicationState( any(ApplicationStateData.class)); verifyApplicationFinished(RMAppState.FAILED); assertTimesAtFinish(application); }