use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestBatchQueryExecutor method testExecuteBatchUpdateInsertDeleteRollBack.
public void testExecuteBatchUpdateInsertDeleteRollBack() throws Exception {
BatchQueryExecutor executor = BatchQueryExecutor.getInstance();
WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
WorkflowActionBean action1 = createWorkflowAction(job.getId(), "1", WorkflowAction.Status.PREP);
WorkflowActionBean action2 = createWorkflowAction(job.getId(), "2", WorkflowAction.Status.PREP);
job.setStatus(WorkflowJob.Status.RUNNING);
Collection<JsonBean> insertList = new ArrayList<JsonBean>();
insertList.add(action1);
insertList.add(action2);
List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
// Add two actions to insert list
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, job));
// set fault injection to true, so transaction is roll backed
setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
FaultInjection.activate("org.apache.oozie.command.SkipCommitFaultInjection");
try {
executor.executeBatchInsertUpdateDelete(insertList, updateList, null);
fail("Expected exception due to commit failure but didn't get any");
} catch (Exception e) {
}
FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
// Check whether transactions are rolled back or not
WorkflowJobBean wfBean = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, job.getId());
// status should not be RUNNING
assertEquals("PREP", wfBean.getStatusStr());
WorkflowActionBean waBean;
try {
waBean = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, action1.getId());
fail("Expected exception but didnt get any");
} catch (JPAExecutorException jpaee) {
assertEquals(ErrorCode.E0605, jpaee.getErrorCode());
}
try {
waBean = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, action2.getId());
fail("Expected exception but didnt get any");
} catch (JPAExecutorException jpaee) {
assertEquals(ErrorCode.E0605, jpaee.getErrorCode());
}
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestBulkWorkflowXCommand method testBulkSuspendNoOp.
public void testBulkSuspendNoOp() throws Exception {
WorkflowJobBean job1 = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
WorkflowActionBean action1 = this.addRecordToWfActionTable(job1.getId(), "1", WorkflowAction.Status.RUNNING);
WorkflowJobBean job2 = this.addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
WorkflowActionBean action2 = this.addRecordToWfActionTable(job2.getId(), "1", WorkflowAction.Status.DONE);
Map<String, List<String>> map = new HashMap<String, List<String>>();
List<String> names = new ArrayList<String>();
names.add("testApp");
map.put("name", names);
new BulkWorkflowXCommand(map, 1, 50, OperationType.Suspend).call();
verifyJobStatus(job1.getId(), WorkflowJob.Status.SUSPENDED);
verifyActionStatus(action1.getId(), WorkflowAction.Status.RUNNING);
verifyJobStatus(job2.getId(), WorkflowJob.Status.SUCCEEDED);
verifyActionStatus(action2.getId(), WorkflowAction.Status.DONE);
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestBulkWorkflowXCommand method testBulkResumeNegative.
public void testBulkResumeNegative() throws Exception {
WorkflowJobBean job1 = this.addRecordToWfJobTable(WorkflowJob.Status.SUSPENDED, WorkflowInstance.Status.SUSPENDED);
WorkflowActionBean action1 = this.addRecordToWfActionTable(job1.getId(), "1", WorkflowAction.Status.RUNNING);
Map<String, List<String>> map = new HashMap<String, List<String>>();
List<String> names = new ArrayList<String>();
names.add("testApp-new");
map.put("name", names);
new BulkWorkflowXCommand(map, 1, 50, OperationType.Resume).call();
verifyJobStatus(job1.getId(), WorkflowJob.Status.SUSPENDED);
verifyActionStatus(action1.getId(), WorkflowAction.Status.RUNNING);
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestBulkWorkflowXCommand method verifyJobStatus.
private void verifyJobStatus(String jobId, WorkflowJob.Status status) throws Exception {
WorkflowJobBean job = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQueryExecutor.WorkflowJobQuery.GET_WORKFLOW, jobId);
assertEquals(status, job.getStatus());
}
use of org.apache.oozie.WorkflowJobBean in project oozie by apache.
the class TestCompletedActionXCommand method testEarlyCallbackTimeout.
public void testEarlyCallbackTimeout() throws Exception {
final Instrumentation inst = Services.get().get(InstrumentationService.class).get();
WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
WorkflowActionBean action = addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.PREP);
final CompletedActionXCommand cmd = new CompletedActionXCommand(action.getId(), "SUCCEEDED", null);
long xexceptionCount;
try {
xexceptionCount = inst.getCounters().get(XCommand.INSTRUMENTATION_GROUP).get(cmd.getName() + ".xexceptions").getValue();
} catch (NullPointerException npe) {
// counter might be null
xexceptionCount = 0L;
}
assertEquals(0L, xexceptionCount);
long executionsCount;
try {
executionsCount = inst.getCounters().get(XCommand.INSTRUMENTATION_GROUP).get(cmd.getName() + ".executions").getValue();
} catch (NullPointerException npe) {
// counter might be null
executionsCount = 0L;
}
assertEquals(0L, executionsCount);
long executionCount;
try {
executionCount = inst.getCounters().get(XCommand.INSTRUMENTATION_GROUP).get(cmd.getName() + ".execution").getValue();
} catch (NullPointerException npe) {
// counter might be null
executionCount = 0L;
}
assertEquals(0L, executionCount);
cmd.call();
int timeout = 10000 * 5 * 2;
waitFor(timeout, new Predicate() {
@Override
public boolean evaluate() throws Exception {
long xexceptionCount;
try {
xexceptionCount = inst.getCounters().get(XCommand.INSTRUMENTATION_GROUP).get(cmd.getName() + ".xexceptions").getValue();
} catch (NullPointerException npe) {
// counter might be null
xexceptionCount = 0L;
}
return (xexceptionCount == 1L);
}
});
executionsCount = inst.getCounters().get(XCommand.INSTRUMENTATION_GROUP).get(cmd.getName() + ".executions").getValue();
assertEquals(6L, executionsCount);
try {
executionCount = inst.getCounters().get(XCommand.INSTRUMENTATION_GROUP).get(cmd.getName() + ".execution").getValue();
} catch (NullPointerException npe) {
// counter might be null
executionCount = 0L;
}
assertEquals(0L, executionCount);
xexceptionCount = inst.getCounters().get(XCommand.INSTRUMENTATION_GROUP).get(cmd.getName() + ".xexceptions").getValue();
assertEquals(1L, xexceptionCount);
}
Aggregations