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);
}
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);
}
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);
}
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());
}
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();
}
}
Aggregations