use of org.apache.oozie.service.StatusTransitService in project oozie by apache.
the class TestCoordKillXCommand method testCoordKillSuccess1.
/**
* Test : kill job and action (READY) successfully
*
* @throws Exception
*/
public void testCoordKillSuccess1() throws Exception {
String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 0);
CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.READY, "coord-action-get.xml", 0);
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(job.getId());
CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(action.getId());
job = jpaService.execute(coordJobGetCmd);
action = jpaService.execute(coordActionGetCmd);
assertEquals(job.getStatus(), CoordinatorJob.Status.RUNNING);
assertEquals(action.getStatus(), CoordinatorAction.Status.READY);
assertFalse(job.isDoneMaterialization());
new CoordKillXCommand(job.getId()).call();
job = jpaService.execute(coordJobGetCmd);
action = jpaService.execute(coordActionGetCmd);
assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
assertTrue(job.isDoneMaterialization());
assertNotNull(job.getLastModifiedTime());
assertEquals(action.getStatus(), CoordinatorAction.Status.KILLED);
// Change job status to RUNNINGWITHERROR to simulate StatusTransitService changing it to
// RUNNINGWITHERROR if it had loaded status and had it as RUNNING in memory when CoordKill
// executes and updates status to KILLED in database.
job.setStatus(CoordinatorJob.Status.RUNNINGWITHERROR);
CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_STATUS, job);
job = jpaService.execute(coordJobGetCmd);
assertEquals(job.getStatus(), CoordinatorJob.Status.RUNNINGWITHERROR);
final CoordMaterializeTransitionXCommand transitionCmd = new CoordMaterializeTransitionXCommand(job.getId(), 3600);
try {
transitionCmd.loadState();
transitionCmd.verifyPrecondition();
fail();
} catch (PreconditionException e) {
// Materialization should not happen as done materialization is set to true by coord kill
}
StatusTransitService.StatusTransitRunnable statusTransit = new StatusTransitService.StatusTransitRunnable();
statusTransit.run();
// StatusTransitService should change the job back to KILLED
job = jpaService.execute(coordJobGetCmd);
assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
assertTrue(job.isDoneMaterialization());
assertNotNull(job.getLastModifiedTime());
}
Aggregations