Search in sources :

Example 16 with JobDetail

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);
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 17 with JobDetail

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) User(uk.gov.gchq.gaffer.user.User) JobTracker(uk.gov.gchq.gaffer.jobtracker.JobTracker) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.jupiter.api.Test)

Example 18 with JobDetail

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());
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) DeleteNamedOperation(uk.gov.gchq.gaffer.named.operation.DeleteNamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) Test(org.junit.jupiter.api.Test)

Example 19 with JobDetail

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());
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) DeleteNamedOperation(uk.gov.gchq.gaffer.named.operation.DeleteNamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) Test(org.junit.jupiter.api.Test)

Example 20 with JobDetail

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());
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) DeleteNamedOperation(uk.gov.gchq.gaffer.named.operation.DeleteNamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) Test(org.junit.jupiter.api.Test)

Aggregations

JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)42 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)22 Test (org.junit.jupiter.api.Test)14 GetJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails)14 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)11 User (uk.gov.gchq.gaffer.user.User)11 ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)10 Context (uk.gov.gchq.gaffer.store.Context)8 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)7 Job (uk.gov.gchq.gaffer.jobtracker.Job)6 OperationException (uk.gov.gchq.gaffer.operation.OperationException)6 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)6 GetAllJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails)6 Schema (uk.gov.gchq.gaffer.store.schema.Schema)6 List (java.util.List)5 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)5 Repeat (uk.gov.gchq.gaffer.jobtracker.Repeat)5 Operation (uk.gov.gchq.gaffer.operation.Operation)5 ValidateOperationChain (uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain)5 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)5