use of uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser in project Gaffer by gchq.
the class OperationChainHandler method prepareOperationChain.
public <O> OperationChain<O> prepareOperationChain(final OperationChain<O> operationChain, final Context context, final Store store) {
final ValidationResult validationResult = opChainValidator.validate(operationChain, context.getUser(), store);
if (!validationResult.isValid()) {
throw new IllegalArgumentException("Operation chain is invalid. " + validationResult.getErrorString());
}
OperationChain<O> optimisedOperationChain = operationChain;
for (final OperationChainOptimiser opChainOptimiser : opChainOptimisers) {
optimisedOperationChain = opChainOptimiser.optimise(optimisedOperationChain);
}
return optimisedOperationChain;
}
use of uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser in project Gaffer by gchq.
the class OperationChainHandlerTest method shouldHandleNestedOperationChain.
@Test
public void shouldHandleNestedOperationChain() throws OperationException {
// Given
final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final StoreProperties storeProperties = new StoreProperties();
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final Limit op3 = mock(Limit.class);
final OperationChain opChain1 = new OperationChain(Arrays.asList(op1, op2));
final OperationChain opChain2 = new OperationChain(Arrays.asList(opChain1, op3));
final Entity entityA = new Entity.Builder().group(TestGroups.ENTITY).vertex("A").build();
final Entity entityB = new Entity.Builder().group(TestGroups.ENTITY).vertex("B").build();
given(context.getUser()).willReturn(user);
given(store.getProperties()).willReturn(storeProperties);
given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
given(store.handleOperation(op1, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(new EntitySeed("A"), new EntitySeed("B"))));
given(store.handleOperation(op2, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(entityA, entityB)));
given(store.handleOperation(op3, context)).willReturn(entityA);
// When
final Object result = opChainHandler.doOperation(opChain2, context, store);
// Then
assertSame(entityA, result);
}
use of uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser in project Gaffer by gchq.
the class Store method prepareOperationChain.
protected <OUTPUT> OperationChain<OUTPUT> prepareOperationChain(final OperationChain<OUTPUT> operationChain, final Context context) {
validateOperationChain(operationChain, context.getUser());
OperationChain<OUTPUT> optimisedOperationChain = operationChain;
for (final OperationChainOptimiser opChainOptimiser : opChainOptimisers) {
optimisedOperationChain = opChainOptimiser.optimise(optimisedOperationChain);
}
return optimisedOperationChain;
}
use of uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser in project Gaffer by gchq.
the class OperationChainHandlerTest method shouldHandleOperationChain.
@Test
public void shouldHandleOperationChain() throws OperationException {
// Given
final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final StoreProperties storeProperties = new StoreProperties();
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final OperationChain opChain = new OperationChain(Arrays.asList(op1, op2));
final Entity expectedResult = new Entity(TestGroups.ENTITY);
given(context.getUser()).willReturn(user);
given(store.getProperties()).willReturn(storeProperties);
given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
given(store.handleOperation(op1, context)).willReturn(new WrappedCloseableIterable<>(Collections.singletonList(new EntitySeed())));
given(store.handleOperation(op2, context)).willReturn(expectedResult);
// When
final Object result = opChainHandler.doOperation(opChain, context, store);
// Then
assertSame(expectedResult, result);
}
use of uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser in project Gaffer by gchq.
the class OperationChainHandlerTest method shouldHandleNonInputOperation.
@Test
public void shouldHandleNonInputOperation() throws OperationException {
// Given
final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final StoreProperties storeProperties = new StoreProperties();
final GetAllElements op = mock(GetAllElements.class);
final OperationChain opChain = new OperationChain(Collections.singletonList(op));
final Entity expectedResult = new Entity(TestGroups.ENTITY);
given(context.getUser()).willReturn(user);
given(store.getProperties()).willReturn(storeProperties);
given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
given(store.handleOperation(op, context)).willReturn(expectedResult);
// When
final Object result = opChainHandler.doOperation(opChain, context, store);
// Then
assertSame(expectedResult, result);
}
Aggregations