Search in sources :

Example 1 with LimitExceededException

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());
    }
}
Also used : IntStream(java.util.stream.IntStream) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) ArgumentCaptor(org.mockito.ArgumentCaptor) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) StreamSupport(java.util.stream.StreamSupport) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) Entity(uk.gov.gchq.gaffer.data.element.Entity) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Store(uk.gov.gchq.gaffer.store.Store) List(java.util.List) Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) LimitExceededException(uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TestTypes(uk.gov.gchq.gaffer.store.TestTypes) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) Element(uk.gov.gchq.gaffer.data.element.Element) LimitExceededException(uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException) Test(org.junit.jupiter.api.Test)

Example 2 with LimitExceededException

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);
    }
}
Also used : LimitedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.LimitedCloseableIterable) LimitedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.LimitedCloseableIterable) MatchKey(uk.gov.gchq.gaffer.operation.impl.join.match.MatchKey) JoinFunction(uk.gov.gchq.gaffer.operation.impl.join.methods.JoinFunction) LimitExceededException(uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Aggregations

LimitExceededException (uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 StreamSupport (java.util.stream.StreamSupport)1 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 Assertions.fail (org.junit.jupiter.api.Assertions.fail)1 Test (org.junit.jupiter.api.Test)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito.verify (org.mockito.Mockito.verify)1 TestGroups (uk.gov.gchq.gaffer.commonutil.TestGroups)1 LimitedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.LimitedCloseableIterable)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 Entity (uk.gov.gchq.gaffer.data.element.Entity)1 GenerateSplitPointsFromSample (uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample)1