Search in sources :

Example 96 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class WhileScoreResolverTest method shouldGetScoreWithOperationChainAsOperation.

@Test
public void shouldGetScoreWithOperationChainAsOperation() {
    // Given
    final Object input = new EntitySeed(3);
    final int repeats = 3;
    final GetElements getElements = mock(GetElements.class);
    final Map map = mock(Map.class);
    final ToSet toSet = mock(ToSet.class);
    final OperationChain transformChain = mock(OperationChain.class);
    final List<Operation> transformOps = new LinkedList<>();
    transformOps.add(map);
    transformOps.add(toSet);
    given(transformChain.getOperations()).willReturn(transformOps);
    final Conditional conditional = mock(Conditional.class);
    given(conditional.getTransform()).willReturn(transformChain);
    final While operation = new While.Builder<>().input(input).maxRepeats(repeats).conditional(conditional).operation(getElements).build();
    final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Operation.class, 1);
    opScores.put(Map.class, 3);
    opScores.put(ToSet.class, 1);
    opScores.put(GetElements.class, 2);
    final WhileScoreResolver resolver = new WhileScoreResolver();
    final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
    // When
    final int score = resolver.getScore(operation, defaultResolver);
    // Then
    assertEquals(18, score);
}
Also used : GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Operation(uk.gov.gchq.gaffer.operation.Operation) While(uk.gov.gchq.gaffer.operation.impl.While) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) LinkedHashMap(java.util.LinkedHashMap) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.jupiter.api.Test)

Example 97 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class IfScoreResolverTest method shouldGetScoreWithFullyPopulatedOperation.

@Test
public void shouldGetScoreWithFullyPopulatedOperation() {
    // Given
    final Count count = mock(Count.class);
    final GetAllElements getAllElements = mock(GetAllElements.class);
    final GetWalks getWalks = mock(GetWalks.class);
    final Conditional conditional = mock(Conditional.class);
    given(conditional.getTransform()).willReturn(count);
    final If operation = new If.Builder<>().conditional(conditional).then(getWalks).otherwise(getAllElements).build();
    final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Count.class, 1);
    opScores.put(GetAllElements.class, 3);
    opScores.put(GetWalks.class, 4);
    final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
    final IfScoreResolver resolver = new IfScoreResolver();
    // When
    final int score = resolver.getScore(operation, defaultResolver);
    // Then
    assertEquals(4, score);
}
Also used : GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Count(uk.gov.gchq.gaffer.operation.impl.Count) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 98 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class IfTest method shouldGetOperations.

@Test
public void shouldGetOperations() {
    // Given
    final GetElements getElements = new GetElements.Builder().input(new EntitySeed("A")).build();
    final OperationChain opChain = new OperationChain.Builder().first(new GetAllElements()).then(new Limit<>(3)).build();
    final If<Object, Object> ifOp = new If.Builder<>().condition(true).then(getElements).otherwise(opChain).build();
    final Collection<Operation> expectedOps = Lists.newArrayList(new OperationChain<>(), OperationChain.wrap(getElements), opChain);
    // When
    final Collection<Operation> result = ifOp.getOperations();
    // Then
    assertEquals(expectedOps, result);
}
Also used : OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 99 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class WhileTest method shouldShallowCloneOperation.

@Test
@Override
public void shouldShallowCloneOperation() {
    // Given
    final EntitySeed input = new EntitySeed("E");
    final Predicate predicate = new Exists();
    final Operation delegate = new GetAdjacentIds();
    final int maxRepeats = 5;
    final While operation = new While.Builder<>().input(input).maxRepeats(maxRepeats).conditional(predicate).operation(delegate).build();
    // When
    final While clone = operation.shallowClone();
    // Then
    assertNotSame(operation, clone);
    assertEquals(input, clone.getInput());
    assertEquals(maxRepeats, clone.getMaxRepeats());
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Operation(uk.gov.gchq.gaffer.operation.Operation) Predicate(java.util.function.Predicate) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 100 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class StoreTest method shouldCloseOperationIfExceptionThrown.

@Test
public void shouldCloseOperationIfExceptionThrown() throws Exception {
    // Given
    final Schema schema = createSchemaMock();
    final StoreProperties properties = mock(StoreProperties.class);
    given(properties.getJobExecutorThreadCount()).willReturn(1);
    final Operation operation = mock(Operation.class);
    final StoreImpl store = new StoreImpl();
    final OperationHandler opHandler = mock(OperationHandler.class);
    store.addOperationHandler(Operation.class, opHandler);
    store.initialise("graphId", schema, properties);
    given(opHandler.doOperation(operation, context, store)).willThrow(new RuntimeException());
    // When / Then
    try {
        store.handleOperation(operation, context);
    } catch (final Exception e) {
        verify(operation).close();
    }
}
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) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) OutputOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler) OperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OperationHandler) Test(org.junit.jupiter.api.Test)

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