Search in sources :

Example 11 with Store

use of uk.gov.gchq.gaffer.store.Store in project Gaffer by gchq.

the class CoreOperationChainOptimiserTest method shouldAddDeduplicateOperationForGetOperationsWithDuplicateFlag.

@Test
public void shouldAddDeduplicateOperationForGetOperationsWithDuplicateFlag() 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(true);
    // When
    final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
    // Then
    assertEquals(2, optimisedOpChain.getOperations().size());
    assertSame(getOperation, optimisedOpChain.getOperations().get(0));
    assertTrue(optimisedOpChain.getOperations().get(1) instanceof Deduplicate);
}
Also used : Deduplicate(uk.gov.gchq.gaffer.operation.impl.Deduplicate) 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)

Example 12 with Store

use of uk.gov.gchq.gaffer.store.Store in project Gaffer by gchq.

the class CoreOperationChainOptimiserTest method shouldAddLimitOperationForGetOperationsWithLimit.

@Test
public void shouldAddLimitOperationForGetOperationsWithLimit() 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);
    final int resultLimit = 5;
    given(getOperation.getResultLimit()).willReturn(resultLimit);
    // When
    final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
    // Then
    assertEquals(2, optimisedOpChain.getOperations().size());
    assertSame(getOperation, optimisedOpChain.getOperations().get(0));
    assertTrue(optimisedOpChain.getOperations().get(1) instanceof Limit);
    assertEquals(resultLimit, (int) ((Limit) optimisedOpChain.getOperations().get(1)).getResultLimit());
}
Also used : GetIterableOperation(uk.gov.gchq.gaffer.operation.GetIterableOperation) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.Test)

Example 13 with Store

use of uk.gov.gchq.gaffer.store.Store in project Gaffer by gchq.

the class CoreOperationChainOptimiserTest method shouldAddLimitOperationBeforeDeduplicateOperationForPerformance.

@Test
public void shouldAddLimitOperationBeforeDeduplicateOperationForPerformance() 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);
    final int resultLimit = 5;
    given(getOperation.getResultLimit()).willReturn(resultLimit);
    given(getOperation.isDeduplicate()).willReturn(true);
    // When
    final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
    // Then
    assertEquals(3, optimisedOpChain.getOperations().size());
    assertSame(getOperation, optimisedOpChain.getOperations().get(0));
    assertTrue(optimisedOpChain.getOperations().get(1) instanceof Limit);
    assertEquals(resultLimit, (int) ((Limit) optimisedOpChain.getOperations().get(1)).getResultLimit());
    assertTrue(optimisedOpChain.getOperations().get(2) instanceof Deduplicate);
}
Also used : Deduplicate(uk.gov.gchq.gaffer.operation.impl.Deduplicate) GetIterableOperation(uk.gov.gchq.gaffer.operation.GetIterableOperation) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.Test)

Example 14 with Store

use of uk.gov.gchq.gaffer.store.Store in project Gaffer by gchq.

the class ValidateHandlerTest method shouldValidatedElements.

@Test
public void shouldValidatedElements() throws OperationException {
    // Given
    final ValidateHandler handler = new ValidateHandler();
    final Store store = mock(Store.class);
    final Validate validate = mock(Validate.class);
    final Element elm1 = mock(Element.class);
    final CloseableIterable<Element> elements = new WrappedCloseableIterable<>(Collections.singletonList(elm1));
    final Schema schema = mock(Schema.class);
    final Context context = new Context();
    given(validate.getElements()).willReturn(elements);
    given(validate.isSkipInvalidElements()).willReturn(false);
    given(store.getSchema()).willReturn(schema);
    final String group = "group";
    given(elm1.getGroup()).willReturn(group);
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    final ElementFilter validator = mock(ElementFilter.class);
    given(validator.filter(elm1)).willReturn(true);
    given(elementDef.getValidator(true)).willReturn(validator);
    given(schema.getElement(group)).willReturn(elementDef);
    // When
    final Iterable<Element> result = handler.doOperation(validate, context, store);
    // Then
    final Iterator<Element> itr = result.iterator();
    final Element elm1Result = itr.next();
    assertSame(elm1, elm1Result);
    assertFalse(itr.hasNext());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.Test)

Example 15 with Store

use of uk.gov.gchq.gaffer.store.Store in project Gaffer by gchq.

the class ValidateHandlerTest method shouldReturnNullIfElementsAreNull.

@Test
public void shouldReturnNullIfElementsAreNull() throws OperationException {
    // Given
    final ValidateHandler handler = new ValidateHandler();
    final Store store = mock(Store.class);
    final Validate validate = mock(Validate.class);
    given(validate.getElements()).willReturn(null);
    final Context context = new Context();
    // When
    final Iterable<Element> result = handler.doOperation(validate, context, store);
    // Then
    assertNull(result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) Element(uk.gov.gchq.gaffer.data.element.Element) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Aggregations

Store (uk.gov.gchq.gaffer.store.Store)37 Test (org.junit.Test)35 Context (uk.gov.gchq.gaffer.store.Context)17 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)13 User (uk.gov.gchq.gaffer.user.User)11 Element (uk.gov.gchq.gaffer.data.element.Element)10 Schema (uk.gov.gchq.gaffer.store.schema.Schema)9 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)6 GetIterableOperation (uk.gov.gchq.gaffer.operation.GetIterableOperation)5 GroupCounts (uk.gov.gchq.gaffer.data.GroupCounts)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)4 Graph (uk.gov.gchq.gaffer.graph.Graph)4 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)4 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)4 GafferResultCacheExporter (uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter)4 CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)4 CountGroupsHandler (uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler)4 HashSet (java.util.HashSet)3 InOrder (org.mockito.InOrder)3 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)3