use of uk.gov.gchq.gaffer.jobtracker.Job in project Gaffer by gchq.
the class PersistentCachingJobServiceV2IT method scheduleJob.
private JobDetail scheduleJob(final Repeat repeat) throws IOException {
final Job job = new Job(repeat, new OperationChain.Builder().first(new GetAllElements()).build());
final Response scheduleResponse = client.scheduleJob(job);
return scheduleResponse.readEntity(new GenericType<JobDetail>() {
});
}
use of uk.gov.gchq.gaffer.jobtracker.Job in project Gaffer by gchq.
the class JobControllerIT method shouldCorrectlyDoAndThenCancelScheduledJob.
@Test
public void shouldCorrectlyDoAndThenCancelScheduledJob() throws IOException, InterruptedException {
// When
final Repeat repeat = new Repeat(1, 2, TimeUnit.SECONDS);
Job job = new Job(repeat, new OperationChain.Builder().first(new GetAllElements()).build());
final ResponseEntity<JobDetail> jobSchedulingResponse = post("/graph/jobs/schedule", job, JobDetail.class);
JobDetail jobDetailParent = jobSchedulingResponse.getBody();
// Then
assertEquals(201, jobSchedulingResponse.getStatusCode().value());
String parentJobId = jobDetailParent.getJobId();
// Wait for first scheduled to run
Thread.sleep(1500);
final ResponseEntity<List> getAllJobDetailsResponse = post("/graph/operations/execute", new GetAllJobDetails(), List.class);
Iterable<JobDetail> jobDetails = deserialiseJobDetailIterable(getAllJobDetailsResponse.getBody());
for (JobDetail jobDetail : jobDetails) {
if (null != jobDetail.getParentJobId() && jobDetail.getParentJobId().equals(parentJobId)) {
assertEquals(JobStatus.FINISHED, jobDetail.getStatus());
}
if (jobDetail.getJobId().equals(parentJobId)) {
assertEquals(JobStatus.SCHEDULED_PARENT, jobDetail.getStatus());
}
}
post("/graph/operations/execute", new CancelScheduledJob.Builder().jobId(parentJobId).build(), Set.class);
final Iterable<JobDetail> cancelledJobDetails = deserialiseJobDetailIterable(post("/graph/operations/execute", new GetAllJobDetails(), List.class).getBody());
for (JobDetail jobDetail : cancelledJobDetails) {
if (parentJobId.equals(jobDetail.getJobId())) {
assertEquals(JobStatus.CANCELLED, jobDetail.getStatus());
}
}
}
use of uk.gov.gchq.gaffer.jobtracker.Job in project Gaffer by gchq.
the class GraphTest method shouldThrowExceptionOnExecuteJobUsingJobWithANullOperation.
@Test
public void shouldThrowExceptionOnExecuteJobUsingJobWithANullOperation() throws OperationException {
// Given
final Context context = new Context();
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).addSchemas(StreamUtil.schemas(getClass())).build();
final Job job = new Job(new Repeat(), new OperationChain<>());
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> graph.executeJob(job, context)).withMessage("An operation is required");
}
use of uk.gov.gchq.gaffer.jobtracker.Job in project Gaffer by gchq.
the class GraphTest method shouldThrowExceptionOnExecuteJobUsingJobWithANullContext.
@Test
public void shouldThrowExceptionOnExecuteJobUsingJobWithANullContext() throws OperationException {
// Given
final Context context = null;
final OperationChain opChain = mock(OperationChain.class);
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).addSchemas(StreamUtil.schemas(getClass())).build();
final Job job = new Job(null, opChain);
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> graph.executeJob(job, context)).withMessage("A context is required");
}
use of uk.gov.gchq.gaffer.jobtracker.Job in project Gaffer by gchq.
the class GraphTest method shouldThrowExceptionOnExecuteJobUsingJobWithANullUser.
@Test
public void shouldThrowExceptionOnExecuteJobUsingJobWithANullUser() throws OperationException {
// Given
final User user = null;
final OperationChain opChain = mock(OperationChain.class);
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).addSchemas(StreamUtil.schemas(getClass())).build();
final Job job = new Job(null, opChain);
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> graph.executeJob(job, user)).withMessage("User is required");
}
Aggregations