Search in sources :

Example 1 with GetIterableOperation

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

the class CoreOperationChainOptimiserTest method shouldNotAddLimitOperationForGetOperationsWithoutLimit.

@Test
public void shouldNotAddLimitOperationForGetOperationsWithoutLimit() 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 Integer resultLimit = null;
    given(getOperation.getResultLimit()).willReturn(resultLimit);
    // 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)

Example 2 with GetIterableOperation

use of uk.gov.gchq.gaffer.operation.GetIterableOperation 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 3 with GetIterableOperation

use of uk.gov.gchq.gaffer.operation.GetIterableOperation 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 4 with GetIterableOperation

use of uk.gov.gchq.gaffer.operation.GetIterableOperation 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 5 with GetIterableOperation

use of uk.gov.gchq.gaffer.operation.GetIterableOperation 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

Test (org.junit.Test)5 GetIterableOperation (uk.gov.gchq.gaffer.operation.GetIterableOperation)5 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)5 Store (uk.gov.gchq.gaffer.store.Store)5 Deduplicate (uk.gov.gchq.gaffer.operation.impl.Deduplicate)2 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)2