public void testFsFailover() throws Exception {
Reader reader = IOUtils.getResourceAsReader("failover-fs-wf.xml", -1);
Writer writer = new FileWriter(getTestCaseDir() + "/workflow.xml");
IOUtils.copyCharStream(reader, writer);
final OozieClient wfClient = LocalOozie.getClient();
Properties conf = wfClient.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, getTestCaseDir() + File.separator + "workflow.xml");
conf.setProperty(OozieClient.USER_NAME, getTestUser());
conf.setProperty(OozieClient.GROUP_NAME, getTestGroup());
injectKerberosInfo(conf);
final Path source = new Path(getFsTestCaseDir(), "fsfailover-source");
getFileSystem().mkdirs(source);
final Path target = new Path(getFsTestCaseDir().toString(), "fsfailover-target");
conf.setProperty("source", source.toString());
conf.setProperty("target", target.toUri().getPath());
setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
final String jobId1 = wfClient.submit(conf);
wfClient.start(jobId1);
waitFor(10 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return getFileSystem().exists(target);
}
});
assertTrue(getFileSystem().exists(target));
waitFor(10 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection");
}
});
assertFalse(FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection"));
assertEquals(WorkflowJob.Status.RUNNING, wfClient.getJobInfo(jobId1).getStatus());
WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId1, false);
WorkflowActionBean action = actions.get(0);
assertEquals(WorkflowAction.Status.PREP, action.getStatus());
setSystemProperty(FaultInjection.FAULT_INJECTION, "false");
setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "false");
ActionStartCommand actionStartCommand = new ActionStartCommand(action.getId(), action.getType());
actionStartCommand.call();
store = Services.get().get(WorkflowStoreService.class).create();
actions = store.getActionsForWorkflow(jobId1, false);
action = actions.get(0);
assertEquals(WorkflowAction.Status.DONE, action.getStatus());
waitFor(5 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
}
});
assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
final String jobId2 = wfClient.submit(conf);
wfClient.start(jobId2);
waitFor(10 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
return wfClient.getJobInfo(jobId2).getStatus() == WorkflowJob.Status.KILLED;
}
});
assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId2).getStatus());
}