Response response = doCreateJob("Test", "/tmp/script.pig", "-useHCatalog");
Assert.assertEquals("-useHCatalog", do_stream.toString());
Assert.assertEquals(201, response.getStatus());
PigJob job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
Assert.assertEquals(PigJob.Status.SUBMITTED, job.getStatus());
Assert.assertTrue(job.isInProgress());
// Retrieve status:
// SUBMITTED
reset(api);
TempletonApi.JobInfo info = api.new JobInfo();
expect(api.checkJob(eq("job_id_#"))).andReturn(info);
replay(api);
response = jobService.getJob(job.getId());
Assert.assertEquals(200, response.getStatus());
job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
Assert.assertEquals(PigJob.Status.SUBMITTED, job.getStatus());
// RUNNING
reset(api);
info = api.new JobInfo();
info.status = new HashMap<String, Object>();
info.status.put("runState", (double)PigJob.RUN_STATE_RUNNING);
info.percentComplete = "30% complete";
expect(api.checkJob(eq("job_id_#"))).andReturn(info);
replay(api);
response = jobService.getJob(job.getId());
Assert.assertEquals(200, response.getStatus());
job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
Assert.assertEquals(PigJob.Status.RUNNING, job.getStatus());
Assert.assertTrue(job.isInProgress());
Assert.assertEquals(30, (Object) job.getPercentComplete());
// SUCCEED
reset(api);
info = api.new JobInfo();
info.status = new HashMap<String, Object>();
info.status.put("runState", (double)PigJob.RUN_STATE_SUCCEEDED);
expect(api.checkJob(eq("job_id_#"))).andReturn(info);
replay(api);
response = jobService.getJob(job.getId());
Assert.assertEquals(200, response.getStatus());
job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
Assert.assertEquals(PigJob.Status.COMPLETED, job.getStatus());
Assert.assertFalse(job.isInProgress());
Assert.assertNull(job.getPercentComplete());
// PREP
reset(api);
info = api.new JobInfo();
info.status = new HashMap<String, Object>();
info.status.put("runState", (double)PigJob.RUN_STATE_PREP);
expect(api.checkJob(eq("job_id_#"))).andReturn(info);
replay(api);
response = jobService.getJob(job.getId());
Assert.assertEquals(200, response.getStatus());
job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
Assert.assertEquals(PigJob.Status.RUNNING, job.getStatus());
// FAILED
reset(api);
info = api.new JobInfo();
info.status = new HashMap<String, Object>();
info.status.put("runState", (double)PigJob.RUN_STATE_FAILED);
expect(api.checkJob(eq("job_id_#"))).andReturn(info);
replay(api);
response = jobService.getJob(job.getId());
Assert.assertEquals(200, response.getStatus());
job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
Assert.assertEquals(PigJob.Status.FAILED, job.getStatus());
Assert.assertFalse(job.isInProgress());
// KILLED
reset(api);
info = api.new JobInfo();
info.status = new HashMap<String, Object>();
info.status.put("runState", (double)PigJob.RUN_STATE_KILLED);
expect(api.checkJob(eq("job_id_#"))).andReturn(info);
replay(api);
response = jobService.getJob(job.getId());
Assert.assertEquals(200, response.getStatus());
job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
Assert.assertEquals(PigJob.Status.KILLED, job.getStatus());
Assert.assertFalse(job.isInProgress());
}