use of org.apache.oozie.service.StatusTransitService.StatusTransitRunnable in project oozie by apache.
the class TestStatusTransitService method testCoordStatusTransitServiceKilledByUser1.
/**
* Tests functionality of the StatusTransitService Runnable command. </p> Insert a coordinator job with RUNNING and
* pending false and coordinator actions with pending false. Then, runs the CoordKillXCommand and
* StatusTransitService runnable and ensures the job pending changes to false.
*
* @throws Exception
*/
public void testCoordStatusTransitServiceKilledByUser1() throws Exception {
final JPAService jpaService = Services.get().get(JPAService.class);
String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 1);
WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
final String wfJobId = wfJob.getId();
CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJobId, "RUNNING", 0);
new CoordKillXCommand(coordJob.getId()).call();
waitFor(5 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
WorkflowJobBean wfBean = jpaService.execute(wfGetCmd);
return wfBean.getStatusStr().equals("KILLED");
}
});
assertNotNull(jpaService);
final CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(coordAction.getId());
WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
coordJob = jpaService.execute(coordJobGetCmd);
coordAction = jpaService.execute(coordActionGetCmd);
wfJob = jpaService.execute(wfGetCmd);
assertEquals(CoordinatorJob.Status.KILLED, coordJob.getStatus());
assertEquals(CoordinatorAction.Status.KILLED, coordAction.getStatus());
assertEquals(WorkflowJob.Status.KILLED, wfJob.getStatus());
assertEquals(false, coordAction.isPending());
Runnable runnable = new StatusTransitRunnable();
runnable.run();
// Status of coordJobBean is being updated asynchronously.
// Increasing wait time to atmost 10s to make sure there is
// sufficient time for the status to get updated. Thus, resulting
// in following assertion not failing.
waitFor(10 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
CoordinatorJobBean coordJobBean = jpaService.execute(coordJobGetCmd);
return !coordJobBean.isPending();
}
});
coordJob = jpaService.execute(coordJobGetCmd);
assertEquals(false, coordJob.isPending());
}
use of org.apache.oozie.service.StatusTransitService.StatusTransitRunnable in project oozie by apache.
the class TestStatusTransitService method testFoo.
/**
* If you have a PREP coordinator job (with no actions) and you suspend it, it goes into PREPSUSPENDED.
* The StatusTransitService should not transition it to RUNNING automatically. This test verifies that the job remains in
* PREPSUSPENDED; and transitions back to PREP after a resume command.
*
* @throws Exception
*/
public void testFoo() throws Exception {
final JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, start, end, true, false, 0);
final String coordJobId = coordJob.getId();
new CoordSuspendXCommand(coordJobId).call();
CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJobId);
coordJob = jpaService.execute(coordJobGetCmd);
assertEquals(Job.Status.PREPSUSPENDED, coordJob.getStatus());
new StatusTransitRunnable().run();
CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
assertEquals(Job.Status.PREPSUSPENDED, coordJob1.getStatus());
new CoordResumeXCommand(coordJobId).call();
coordJob = jpaService.execute(coordJobGetCmd);
assertEquals(Job.Status.PREP, coordJob.getStatus());
new StatusTransitRunnable().run();
waitFor(20 * 1000, new Predicate() {
@Override
public boolean evaluate() throws Exception {
CoordinatorJobBean job = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
return job.getStatus().equals(Job.Status.PREP);
}
});
coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
assertEquals(Job.Status.PREP, coordJob1.getStatus());
}
use of org.apache.oozie.service.StatusTransitService.StatusTransitRunnable in project oozie by apache.
the class TestStatusTransitService method testBundleStatusTransitWithLock.
public void testBundleStatusTransitWithLock() throws Exception {
setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "false");
services = new Services();
services.init();
BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.RUNNING, true);
final String jobId = bundleJob.getId();
final String bundleId = bundleJob.getId();
addRecordToBundleActionTable(bundleId, "action1-C", 0, Job.Status.PREP);
addRecordToBundleActionTable(bundleId, "action2-C", 0, Job.Status.RUNNING);
addRecordToBundleActionTable(bundleId, "action3-C", 0, Job.Status.DONEWITHERROR);
JobLock lockThread = new JobLock(jobId);
new Thread(lockThread).start();
sleep(1000);
Runnable runnable = new StatusTransitRunnable();
runnable.run();
bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_STATUS, bundleId);
assertEquals(Job.Status.RUNNING, bundleJob.getStatus());
synchronized (lockThread) {
lockThread.notifyAll();
}
sleep(1000);
runnable.run();
bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_STATUS, bundleId);
assertEquals(Job.Status.RUNNINGWITHERROR, bundleJob.getStatus());
}
use of org.apache.oozie.service.StatusTransitService.StatusTransitRunnable in project oozie by apache.
the class TestStatusTransitService method testCoordNotTransitionfromKilled.
/**
* Inserts a coordinator job in KILLED state with pending materialization.
* Make sure the status doesn't change to DONEWITHERROR
*
* @throws Exception
*/
public void testCoordNotTransitionfromKilled() throws Exception {
CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.KILLED, true, false);
addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
Runnable runnable = new StatusTransitRunnable();
runnable.run();
sleep(1000);
JPAService jpaService = Services.get().get(JPAService.class);
CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
assertEquals(CoordinatorJob.Status.KILLED, coordJob.getStatus());
}
use of org.apache.oozie.service.StatusTransitService.StatusTransitRunnable in project oozie by apache.
the class TestStatusTransitService method testCoordStatusTransitWithLock.
public void testCoordStatusTransitWithLock() throws Exception {
setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "false");
services = new Services();
services.init();
final JPAService jpaService = Services.get().get(JPAService.class);
String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, true, false, 1);
addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.KILLED, "coord-action-get.xml", null, "KILLED", 0);
final CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
JobLock lockThread = new JobLock(coordJob.getId());
new Thread(lockThread).start();
Runnable runnable = new StatusTransitRunnable();
runnable.run();
sleep(1000);
coordJob = jpaService.execute(coordJobGetCmd);
assertEquals(CoordinatorJob.Status.RUNNING, coordJob.getStatus());
synchronized (lockThread) {
lockThread.notifyAll();
}
runnable.run();
coordJob = jpaService.execute(coordJobGetCmd);
assertEquals(CoordinatorJob.Status.RUNNINGWITHERROR, coordJob.getStatus());
}
Aggregations