use of uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException in project Gaffer by gchq.
the class AbstractSampleElementsForSplitPointsHandlerTest method shouldThrowExceptionIfNumberOfSampledElementsIsMoreThanMaxAllowed.
@Test
public void shouldThrowExceptionIfNumberOfSampledElementsIsMoreThanMaxAllowed() throws OperationException {
// Given
int maxSampledElements = 5;
final AbstractSampleElementsForSplitPointsHandler<?, ?> handler = createHandler();
handler.setMaxSampledElements(maxSampledElements);
final List<Element> elements = IntStream.range(0, 6).mapToObj(i -> new Entity(TestGroups.ENTITY, "vertex_" + i)).collect(Collectors.toList());
final SampleElementsForSplitPoints operation = new SampleElementsForSplitPoints.Builder<>().input(elements).numSplits(3).build();
// When / Then
try {
handler.doOperation(operation, new Context(), createStore());
fail("Exception expected");
} catch (final LimitExceededException e) {
assertTrue(e.getMessage().equals("Limit of " + maxSampledElements + " exceeded."), e.getMessage());
}
}
use of uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException in project Gaffer by gchq.
the class JoinHandler method doOperation.
@Override
public Iterable<? extends MapTuple> doOperation(final Join<I> operation, final Context context, final Store store) throws OperationException {
final int limit = operation.getCollectionLimit() != null ? operation.getCollectionLimit() : 100000;
if (null == operation.getJoinType()) {
throw new OperationException("A join type must be specified");
}
if (null == operation.getMatchMethod()) {
throw new OperationException("A match method must be supplied");
}
if (null == operation.getInput()) {
operation.setInput(new ArrayList<>());
}
MatchKey matchKey = operation.getMatchKey();
if (null == matchKey) {
if (!operation.getJoinType().equals(JoinType.INNER)) {
throw new OperationException("You must specify an Iterable side to match on");
}
// setting match key to avoid swapping inputs
matchKey = MatchKey.LEFT;
}
JoinFunction joinFunction = operation.getJoinType().createInstance();
updateOperationInput(operation.getOperation(), null);
Iterable<I> rightIterable = (Iterable<I>) getResultsOrNull(operation.getOperation(), context, store);
final Iterable limitedLeftIterable;
final Iterable limitedRightIterable;
try {
limitedLeftIterable = new LimitedCloseableIterable(operation.getInput(), 0, limit, false);
limitedRightIterable = new LimitedCloseableIterable(rightIterable, 0, limit, false);
return joinFunction.join(limitedLeftIterable, limitedRightIterable, operation.getMatchMethod(), matchKey, operation.isFlatten());
} catch (final LimitExceededException e) {
throw new OperationException("Join exceeded the collectionLimit, a solution is to increasing collectionLimit value in the join operation.", e);
}
}
Aggregations