Search in sources :

Example 61 with Operation

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());
}
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 62 with Operation

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);
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) HashMapCacheService(uk.gov.gchq.gaffer.cache.impl.HashMapCacheService) 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) Properties(java.util.Properties) CacheProperties(uk.gov.gchq.gaffer.cache.util.CacheProperties) Test(org.junit.jupiter.api.Test)

Example 63 with Operation

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);
    }
}
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) Test(org.junit.jupiter.api.Test)

Example 64 with Operation

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());
}
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 65 with Operation

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));
}
Also used : OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ArrayList(java.util.ArrayList) Operation(uk.gov.gchq.gaffer.operation.Operation)

Aggregations

Operation (uk.gov.gchq.gaffer.operation.Operation)136 Test (org.junit.jupiter.api.Test)88 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)49 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)44 Schema (uk.gov.gchq.gaffer.store.schema.Schema)41 Context (uk.gov.gchq.gaffer.store.Context)35 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)34 Store (uk.gov.gchq.gaffer.store.Store)28 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)26 LinkedHashMap (java.util.LinkedHashMap)21 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)21 User (uk.gov.gchq.gaffer.user.User)21 ArrayList (java.util.ArrayList)18 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)18 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)17 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)16 HashSet (java.util.HashSet)15 HashMap (java.util.HashMap)13 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)13 OperationException (uk.gov.gchq.gaffer.operation.OperationException)13