Search in sources :

Example 96 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class DataGenerator method getElement.

@Override
public Element getElement(final String line) {
    final String[] t = line.split(",");
    final Element element;
    if (t.length > 2) {
        element = new Edge.Builder().group("edge").source(Integer.parseInt(t[0])).dest(Integer.parseInt(t[1])).directed(true).property("count", Integer.parseInt(t[2])).build();
    } else {
        element = new Entity.Builder().group("entity").vertex(Integer.parseInt(t[0])).property("count", Integer.parseInt(t[1])).build();
    }
    return element;
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 97 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class CoreOperationChainOptimiserTest method shouldAddValidateOperationsForAllValidatableOperations.

@Test
public void shouldAddValidateOperationsForAllValidatableOperations() throws Exception {
    // Given
    final Store store = mock(Store.class);
    final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
    final CloseableIterable<Element> elements = mock(CloseableIterable.class);
    final Validatable<Integer> validatable1 = mock(Validatable.class);
    final Operation<Iterable<Element>, Iterable<Element>> nonValidatable1 = mock(Operation.class);
    final Validatable<Iterable<Element>> validatable2 = mock(Validatable.class);
    final Validatable<Iterable<Element>> validatable3 = mock(Validatable.class);
    final Operation<Iterable<Element>, Iterable<Element>> nonValidatable2 = mock(Operation.class);
    final boolean skipInvalidElements = true;
    final OperationChain<Integer> opChain = new OperationChain.Builder().first(nonValidatable2).then(validatable3).then(validatable2).then(nonValidatable1).then(validatable1).build();
    given(validatable1.getElements()).willReturn(elements);
    given(validatable1.isSkipInvalidElements()).willReturn(skipInvalidElements);
    given(validatable2.isSkipInvalidElements()).willReturn(skipInvalidElements);
    given(validatable1.isValidate()).willReturn(true);
    given(validatable2.isValidate()).willReturn(true);
    given(validatable3.isValidate()).willReturn(false);
    // When
    final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
    // Then
    assertEquals(7, optimisedOpChain.getOperations().size());
    assertSame(nonValidatable2, optimisedOpChain.getOperations().get(0));
    assertSame(validatable3, optimisedOpChain.getOperations().get(1));
    assertTrue(optimisedOpChain.getOperations().get(2) instanceof Validate);
    assertSame(validatable2, optimisedOpChain.getOperations().get(3));
    assertSame(nonValidatable1, optimisedOpChain.getOperations().get(4));
    assertTrue(optimisedOpChain.getOperations().get(5) instanceof Validate);
    assertSame(elements, ((Validate) optimisedOpChain.getOperations().get(5)).getElements());
    assertSame(validatable1, optimisedOpChain.getOperations().get(6));
    verify(validatable2).setElements(null);
    verify(validatable1).setElements(null);
    verify(validatable3, never()).setElements(null);
}
Also used : CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) Store(uk.gov.gchq.gaffer.store.Store) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) Test(org.junit.Test)

Example 98 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class ValidatedElementsTest method shouldThrowExceptionIfNextCalledWhenNoNextElement.

@Test
public void shouldThrowExceptionIfNextCalledWhenNoNextElement() {
    // Given
    final boolean skipInvalidElements = true;
    final ValidatedElements validElements = new ValidatedElements(elements, schema, skipInvalidElements);
    final Iterator<Element> itr = validElements.iterator();
    // When 1
    final Element next0 = itr.next();
    final Element next1 = itr.next();
    // Then 1
    assertSame(elements.get(0), next0);
    assertSame(elements.get(2), next1);
    // When 2 / Then 2
    try {
        itr.next();
        fail("Exception expected");
    } catch (NoSuchElementException e) {
        assertNotNull(e);
    }
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 99 with Element

use of uk.gov.gchq.gaffer.data.element.Element 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)

Example 100 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class ValidateHandlerTest method shouldReturnNullIfElementsAreNull.

@Test
public void shouldReturnNullIfElementsAreNull() throws OperationException {
    // Given
    final ValidateHandler handler = new ValidateHandler();
    final Store store = mock(Store.class);
    final Validate validate = mock(Validate.class);
    given(validate.getElements()).willReturn(null);
    final Context context = new Context();
    // When
    final Iterable<Element> result = handler.doOperation(validate, context, store);
    // Then
    assertNull(result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) Element(uk.gov.gchq.gaffer.data.element.Element) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Aggregations

Element (uk.gov.gchq.gaffer.data.element.Element)182 Test (org.junit.Test)102 Edge (uk.gov.gchq.gaffer.data.element.Edge)72 User (uk.gov.gchq.gaffer.user.User)53 Entity (uk.gov.gchq.gaffer.data.element.Entity)52 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)50 HashSet (java.util.HashSet)47 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)42 ArrayList (java.util.ArrayList)33 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)32 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)26 Key (org.apache.accumulo.core.data.Key)23 Value (org.apache.accumulo.core.data.Value)23 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)21 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 HashMap (java.util.HashMap)14 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)14 Configuration (org.apache.hadoop.conf.Configuration)12 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)12