Search in sources :

Example 61 with OperationChain

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

the class StoreTest method shouldHandleMultiStepOperations.

@Test
public void shouldHandleMultiStepOperations() throws Exception {
    // Given
    final Schema schema = createSchemaMock();
    final StoreProperties properties = mock(StoreProperties.class);
    final StoreImpl store = new StoreImpl();
    final CloseableIterable<Element> getElementsResult = mock(CloseableIterable.class);
    final AddElements addElements1 = new AddElements();
    final GetElements<ElementSeed, Element> getElements = new GetElements<>();
    final OperationChain<CloseableIterable<Element>> opChain = new OperationChain.Builder().first(addElements1).then(getElements).build();
    given(addElementsHandler.doOperation(addElements1, context, store)).willReturn(null);
    given(getElementsHandler.doOperation(getElements, context, store)).willReturn(getElementsResult);
    store.initialise(schema, properties);
    // When
    final CloseableIterable<Element> result = store.execute(opChain, user);
    // Then
    assertSame(getElementsResult, result);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Test(org.junit.Test)

Example 62 with OperationChain

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

the class CoreOperationChainOptimiserTest method shouldNotAddValidateOperationWhenValidatableHasValidateSetToFalse.

@Test
public void shouldNotAddValidateOperationWhenValidatableHasValidateSetToFalse() throws Exception {
    // Given
    final Store store = mock(Store.class);
    final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
    final Validatable<Integer> validatable1 = mock(Validatable.class);
    final boolean skipInvalidElements = true;
    final CloseableIterable<Element> elements = mock(CloseableIterable.class);
    final OperationChain<Integer> opChain = new OperationChain<>(validatable1);
    given(validatable1.isSkipInvalidElements()).willReturn(skipInvalidElements);
    given(validatable1.isValidate()).willReturn(false);
    given(validatable1.getElements()).willReturn(elements);
    // When
    final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
    // Then
    assertEquals(1, optimisedOpChain.getOperations().size());
    assertSame(validatable1, optimisedOpChain.getOperations().get(0));
    verify(validatable1, never()).setElements(null);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 63 with OperationChain

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

the class CoreOperationChainOptimiserTest method shouldThrowExceptionIfValidatableHasValidateSetToFalseAndStoreRequiresValidation.

@Test
public void shouldThrowExceptionIfValidatableHasValidateSetToFalseAndStoreRequiresValidation() throws Exception {
    // Given
    final Store store = mock(Store.class);
    final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
    final Schema schema = mock(Schema.class);
    final Validatable<Integer> validatable1 = mock(Validatable.class);
    final OperationChain<Integer> opChain = new OperationChain<>(validatable1);
    given(schema.validate()).willReturn(true);
    given(store.isValidationRequired()).willReturn(true);
    given(validatable1.isValidate()).willReturn(false);
    // When / then
    try {
        optimiser.optimise(opChain);
    } catch (UnsupportedOperationException e) {
        assertNotNull(e);
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 64 with OperationChain

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

the class CoreOperationChainOptimiserTest method shouldAddValidateOperationForValidatableOperation.

@Test
public void shouldAddValidateOperationForValidatableOperation() throws Exception {
    // Given
    final Store store = mock(Store.class);
    final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
    final Validatable<Integer> validatable1 = mock(Validatable.class);
    final boolean skipInvalidElements = true;
    final CloseableIterable<Element> elements = mock(CloseableIterable.class);
    final OperationChain<Integer> opChain = new OperationChain<>(validatable1);
    final Map<String, String> options = mock(HashMap.class);
    given(validatable1.getOptions()).willReturn(options);
    given(validatable1.isSkipInvalidElements()).willReturn(skipInvalidElements);
    given(validatable1.isValidate()).willReturn(true);
    given(validatable1.getElements()).willReturn(elements);
    // When
    final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
    // Then
    assertEquals(2, optimisedOpChain.getOperations().size());
    assertSame(elements, ((Validate) optimisedOpChain.getOperations().get(0)).getElements());
    assertSame(options, optimisedOpChain.getOperations().get(0).getOptions());
    assertSame(validatable1, optimisedOpChain.getOperations().get(1));
    verify(validatable1).setElements(null);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 65 with OperationChain

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

the class CoreOperationChainOptimiserTest method shouldNotAddDeduplicateOperationForGetOperationsWithoutFlag.

@Test
public void shouldNotAddDeduplicateOperationForGetOperationsWithoutFlag() throws Exception {
    // Given
    final Store store = mock(Store.class);
    final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
    final GetIterableOperation getOperation = mock(GetIterableOperation.class);
    final OperationChain<Integer> opChain = new OperationChain<>(getOperation);
    given(getOperation.getResultLimit()).willReturn(null);
    given(getOperation.isDeduplicate()).willReturn(false);
    // When
    final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
    // Then
    assertEquals(1, optimisedOpChain.getOperations().size());
    assertSame(getOperation, optimisedOpChain.getOperations().get(0));
}
Also used : GetIterableOperation(uk.gov.gchq.gaffer.operation.GetIterableOperation) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Aggregations

OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)65 Test (org.junit.Test)52 User (uk.gov.gchq.gaffer.user.User)38 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 Store (uk.gov.gchq.gaffer.store.Store)13 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)12 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)11 GenerateObjects (uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects)11 Schema (uk.gov.gchq.gaffer.store.schema.Schema)10 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)9 GetAdjacentEntitySeeds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds)8 Edge (uk.gov.gchq.gaffer.data.element.Edge)7 Element (uk.gov.gchq.gaffer.data.element.Element)7 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)7 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)7 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)7 InOrder (org.mockito.InOrder)6 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)6 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)6