use of uk.gov.gchq.gaffer.operation.Operation 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.operation.Operation in project Gaffer by gchq.
the class StoreTest method shouldReturnAllSupportedOperations.
@Test
public void shouldReturnAllSupportedOperations() throws Exception {
// Given
final Properties cacheProperties = new Properties();
cacheProperties.setProperty(CacheProperties.CACHE_SERVICE_CLASS, HashMapCacheService.class.getName());
CacheServiceLoader.initialise(cacheProperties);
final Schema schema = createSchemaMock();
final StoreProperties properties = mock(StoreProperties.class);
given(properties.getJobExecutorThreadCount()).willReturn(1);
given(properties.getJobTrackerEnabled()).willReturn(true);
store.initialise("graphId", schema, properties);
// When
final List<Class<? extends Operation>> supportedOperations = Lists.newArrayList(store.getSupportedOperations());
// Then
assertNotNull(supportedOperations);
final List<Class<? extends Operation>> expectedOperations = Lists.newArrayList(AddElements.class, GetElements.class, GetAdjacentIds.class, GetAllElements.class, mock(AddElements.class).getClass(), mock(GetElements.class).getClass(), mock(GetAdjacentIds.class).getClass(), // Export
ExportToSet.class, GetSetExport.class, GetExports.class, ExportToGafferResultCache.class, GetGafferResultCacheExport.class, // Jobs
GetJobDetails.class, GetAllJobDetails.class, GetJobResults.class, // Output
ToArray.class, ToEntitySeeds.class, ToList.class, ToMap.class, ToCsv.class, ToSet.class, ToStream.class, ToVertices.class, // Named Operations
NamedOperation.class, AddNamedOperation.class, GetAllNamedOperations.class, DeleteNamedOperation.class, // Named View
AddNamedView.class, GetAllNamedViews.class, DeleteNamedView.class, // ElementComparison
Max.class, Min.class, Sort.class, // Validation
ValidateOperationChain.class, // Algorithm
GetWalks.class, // OperationChain
OperationChain.class, OperationChainDAO.class, // Other
GenerateElements.class, GenerateObjects.class, Validate.class, Count.class, CountGroups.class, Limit.class, DiscardOutput.class, GetSchema.class, Map.class, If.class, GetTraits.class, While.class, Join.class, ToSingletonList.class, ForEach.class, Reduce.class, CancelScheduledJob.class, // Function
Filter.class, Transform.class, Aggregate.class, // Context variables
SetVariable.class, GetVariable.class, GetVariables.class);
expectedOperations.sort(Comparator.comparing(Class::getName));
supportedOperations.sort(Comparator.comparing(Class::getName));
assertEquals(expectedOperations, supportedOperations);
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class StoreTest method shouldReturnTrueWhenOperationSupported.
@Test
public void shouldReturnTrueWhenOperationSupported() throws Exception {
// Given
final Schema schema = createSchemaMock();
final StoreProperties properties = mock(StoreProperties.class);
given(properties.getJobExecutorThreadCount()).willReturn(1);
store.initialise("graphId", schema, properties);
// WHen
final Set<Class<? extends Operation>> supportedOperations = store.getSupportedOperations();
for (final Class<? extends Operation> operationClass : supportedOperations) {
final boolean isOperationClassSupported = store.isSupported(operationClass);
// Then
assertTrue(isOperationClassSupported);
}
}
use of uk.gov.gchq.gaffer.operation.Operation 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());
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class AbstractOperationChainOptimiser method optimise.
@Override
public final <O> OperationChain<O> optimise(final OperationChain<O> operationChain) {
final List<Operation> ops = operationChain.getOperations();
final int numOps = ops.size();
if (numOps == 0) {
return operationChain;
}
final List<Operation> optimisedOps = new ArrayList<>();
Operation previousOp;
Operation currentOp = null;
Operation nextOp = ops.get(0);
for (int index = 0; index < numOps; index++) {
previousOp = currentOp;
currentOp = nextOp;
nextOp = ((index + 1) < numOps) ? ops.get(index + 1) : null;
optimisedOps.addAll(addPreOperations(previousOp, currentOp));
optimisedOps.addAll(optimiseCurrentOperation(previousOp, currentOp, nextOp));
optimisedOps.addAll(addPostOperations(currentOp, nextOp));
}
return new OperationChain<>(optimiseAll(optimisedOps));
}
Aggregations