use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class GraphTest method shouldCallAllGraphHooksAfterJobExecuted.
@Test
public void shouldCallAllGraphHooksAfterJobExecuted() throws OperationException {
// Given
final GraphHook hook1 = mock(GraphHook.class);
final GraphHook hook2 = mock(GraphHook.class);
final Store store = mock(Store.class);
final Schema schema = new Schema();
final JobDetail result1 = mock(JobDetail.class);
final JobDetail result2 = mock(JobDetail.class);
final JobDetail result3 = mock(JobDetail.class);
given(store.getSchema()).willReturn(schema);
given(store.getProperties()).willReturn(new StoreProperties());
given(hook1.postExecute(result1, clonedOpChain, clonedContext)).willReturn(result2);
given(hook2.postExecute(result2, clonedOpChain, clonedContext)).willReturn(result3);
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(hook1).addHook(hook2).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(schema).build();
given(store.executeJob(clonedOpChain, clonedContext)).willReturn(result1);
// When
final JobDetail actualResult = graph.executeJob(opChain, context);
// Then
final InOrder inOrder = inOrder(hook1, hook2);
inOrder.verify(hook1).postExecute(result1, clonedOpChain, clonedContext);
inOrder.verify(hook2).postExecute(result2, clonedOpChain, clonedContext);
assertSame(actualResult, result3);
verify(context).setOriginalOpChain(opChain);
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class GetJobDetailsHandlerTest method shouldGetJobDetailsByDelegatingToJobTrackerWithContextJobId.
@Test
public void shouldGetJobDetailsByDelegatingToJobTrackerWithContextJobId() throws OperationException {
// Given
final GetJobDetailsHandler handler = new GetJobDetailsHandler();
final GetJobDetails operation = new GetJobDetails();
final Store store = mock(Store.class);
final JobTracker jobTracker = mock(JobTracker.class);
final User user = mock(User.class);
final JobDetail jobsDetail = mock(JobDetail.class);
final Context context = new Context.Builder().user(user).build();
final String jobId = context.getJobId();
given(store.getJobTracker()).willReturn(jobTracker);
given(jobTracker.getJob(jobId, user)).willReturn(jobsDetail);
// When
final JobDetail result = handler.doOperation(operation, context, store);
// Then
assertSame(jobsDetail, result);
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class StoreTest method shouldExecuteOperationChainJobAndExportResults.
@Test
public void shouldExecuteOperationChainJobAndExportResults() throws OperationException, InterruptedException, StoreException {
// Given
final Operation operation = new GetVariables.Builder().variableNames(Lists.newArrayList()).build();
final OperationChain<?> opChain = new OperationChain<>(operation);
final StoreProperties properties = mock(StoreProperties.class);
given(properties.getJobExecutorThreadCount()).willReturn(1);
given(properties.getJobTrackerEnabled()).willReturn(true);
final Store store = new StoreImpl();
final Schema schema = new Schema();
store.initialise("graphId", schema, properties);
// When
final JobDetail resultJobDetail = store.executeJob(opChain, context);
// Then
Thread.sleep(1000);
final ArgumentCaptor<JobDetail> jobDetail = ArgumentCaptor.forClass(JobDetail.class);
verify(jobTracker, times(2)).addOrUpdateJob(jobDetail.capture(), eq(user));
assertEquals(jobDetail.getAllValues().get(0), resultJobDetail);
assertEquals(JobStatus.FINISHED, jobDetail.getAllValues().get(1).getStatus());
final ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(exportToGafferResultCacheHandler).doOperation(Mockito.any(ExportToGafferResultCache.class), contextCaptor.capture(), eq(store));
assertSame(user, contextCaptor.getValue().getUser());
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class StoreTest method shouldExecuteOperationJobAndWrapJobOperationInChain.
@Test
public void shouldExecuteOperationJobAndWrapJobOperationInChain() throws OperationException, InterruptedException, StoreException, SerialisationException {
// Given
final Operation operation = new GetVariables.Builder().variableNames(Lists.newArrayList()).build();
final StoreProperties properties = mock(StoreProperties.class);
given(properties.getJobExecutorThreadCount()).willReturn(1);
given(properties.getJobTrackerEnabled()).willReturn(true);
final Store store = new StoreImpl();
final Schema schema = new Schema();
store.initialise("graphId", schema, properties);
// When
final JobDetail resultJobDetail = store.executeJob(operation, context);
// Then
Thread.sleep(1000);
final ArgumentCaptor<JobDetail> jobDetail = ArgumentCaptor.forClass(JobDetail.class);
verify(jobTracker, times(2)).addOrUpdateJob(jobDetail.capture(), eq(user));
assertEquals(jobDetail.getAllValues().get(0), resultJobDetail);
assertEquals(OperationChain.wrap(operation).toOverviewString(), resultJobDetail.getOpChain());
assertEquals(JobStatus.FINISHED, jobDetail.getAllValues().get(1).getStatus());
final ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(exportToGafferResultCacheHandler).doOperation(Mockito.any(ExportToGafferResultCache.class), contextCaptor.capture(), eq(store));
assertSame(user, contextCaptor.getValue().getUser());
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class StoreTest method shouldExecuteOperationChainJob.
@Test
public void shouldExecuteOperationChainJob() throws OperationException, InterruptedException, StoreException {
// Given
final Operation operation = new GetVariables.Builder().variableNames(Lists.newArrayList()).build();
final OperationChain<?> opChain = new OperationChain.Builder().first(operation).then(new ExportToGafferResultCache()).build();
final StoreProperties properties = mock(StoreProperties.class);
given(properties.getJobExecutorThreadCount()).willReturn(1);
given(properties.getJobTrackerEnabled()).willReturn(true);
final Store store = new StoreImpl();
final Schema schema = new Schema();
store.initialise("graphId", schema, properties);
// When
final JobDetail resultJobDetail = store.executeJob(opChain, context);
// Then
Thread.sleep(1000);
final ArgumentCaptor<JobDetail> jobDetail = ArgumentCaptor.forClass(JobDetail.class);
verify(jobTracker, times(2)).addOrUpdateJob(jobDetail.capture(), eq(user));
assertEquals(jobDetail.getAllValues().get(0), resultJobDetail);
assertEquals(JobStatus.FINISHED, jobDetail.getAllValues().get(1).getStatus());
final ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(exportToGafferResultCacheHandler).doOperation(Mockito.any(ExportToGafferResultCache.class), contextCaptor.capture(), eq(store));
assertSame(user, contextCaptor.getValue().getUser());
}
Aggregations