Search in sources :

Example 6 with WrappedCloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable in project Gaffer by gchq.

the class DeduplicateHandlerTest method shouldDeduplicateResultsAndMaintainOrder.

@Test
public void shouldDeduplicateResultsAndMaintainOrder() throws OperationException {
    // Given
    final CloseableIterable<Integer> originalResults = new WrappedCloseableIterable<>(Arrays.asList(10, 9, 8, 10, 7, 8, 7, 6, 6, 5, 6, 9, 4, 5, 3, 4, 2, 2, 2, 1, 1));
    final DeduplicateHandler<Integer> handler = new DeduplicateHandler<>();
    final Deduplicate<Integer> operation = mock(Deduplicate.class);
    given(operation.getInput()).willReturn(originalResults);
    // When
    final Iterable<Integer> results = handler.doOperation(operation, new Context(), null);
    // Then
    assertEquals(Arrays.asList(10, 9, 8, 7, 6, 5, 4, 3, 2, 1), Lists.newArrayList(results));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Test(org.junit.Test)

Example 7 with WrappedCloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable in project Gaffer by gchq.

the class ValidateHandlerTest method shouldValidatedElements.

@Test
public void shouldValidatedElements() throws OperationException {
    // Given
    final ValidateHandler handler = new ValidateHandler();
    final Store store = mock(Store.class);
    final Validate validate = mock(Validate.class);
    final Element elm1 = mock(Element.class);
    final CloseableIterable<Element> elements = new WrappedCloseableIterable<>(Collections.singletonList(elm1));
    final Schema schema = mock(Schema.class);
    final Context context = new Context();
    given(validate.getElements()).willReturn(elements);
    given(validate.isSkipInvalidElements()).willReturn(false);
    given(store.getSchema()).willReturn(schema);
    final String group = "group";
    given(elm1.getGroup()).willReturn(group);
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    final ElementFilter validator = mock(ElementFilter.class);
    given(validator.filter(elm1)).willReturn(true);
    given(elementDef.getValidator(true)).willReturn(validator);
    given(schema.getElement(group)).willReturn(elementDef);
    // When
    final Iterable<Element> result = handler.doOperation(validate, context, store);
    // Then
    final Iterator<Element> itr = result.iterator();
    final Element elm1Result = itr.next();
    assertSame(elm1, elm1Result);
    assertFalse(itr.hasNext());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.Test)

Aggregations

WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)7 Test (org.junit.Test)4 Context (uk.gov.gchq.gaffer.store.Context)4 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)2 Store (uk.gov.gchq.gaffer.store.Store)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 Entity (uk.gov.gchq.gaffer.data.element.Entity)1 AreIn (uk.gov.gchq.gaffer.function.filter.AreIn)1 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)1 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)1 ExtendedNamedOperation (uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation)1 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)1 CacheOperationFailedException (uk.gov.gchq.gaffer.named.operation.cache.CacheOperationFailedException)1 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)1 GafferResultCacheExporter (uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter)1 Validate (uk.gov.gchq.gaffer.operation.impl.Validate)1