Search in sources :

Example 96 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class WhileHandlerTest method shouldThrowExceptionWhenPredicateCannotAcceptInputType.

@Test
public void shouldThrowExceptionWhenPredicateCannotAcceptInputType() throws OperationException {
    // Given
    final Predicate predicate = new IsFalse();
    final Object input = new EntitySeed();
    final Conditional conditional = new Conditional(predicate);
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final While operation = new While.Builder<>().input(input).conditional(conditional).operation(new GetElements()).build();
    final WhileHandler handler = new WhileHandler();
    // When / Then
    try {
        handler.doOperation(operation, context, store);
        fail("Exception expected");
    } catch (final OperationException e) {
        assertTrue(e.getMessage().contains("The predicate '" + predicate.getClass().getSimpleName() + "' cannot accept an input of type '" + input.getClass().getSimpleName() + "'"));
    }
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) IsFalse(uk.gov.gchq.koryphe.impl.predicate.IsFalse) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) While(uk.gov.gchq.gaffer.operation.impl.While) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Predicate(java.util.function.Predicate) Test(org.junit.jupiter.api.Test)

Example 97 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class WhileHandlerTest method shouldNotRepeatWhileConditionIsFalse.

@Test
public void shouldNotRepeatWhileConditionIsFalse() throws OperationException {
    // Given
    final EntitySeed input = mock(EntitySeed.class);
    final int maxRepeats = 3;
    final boolean condition = false;
    final Operation delegate = mock(GetElements.class);
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final While operation = new While.Builder<>().input(input).maxRepeats(maxRepeats).condition(condition).operation(delegate).build();
    final WhileHandler handler = new WhileHandler();
    // When
    handler.doOperation(operation, context, store);
    // Then
    verify(store, never()).execute((Output) delegate, context);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Store(uk.gov.gchq.gaffer.store.Store) Operation(uk.gov.gchq.gaffer.operation.Operation) While(uk.gov.gchq.gaffer.operation.impl.While) Test(org.junit.jupiter.api.Test)

Example 98 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class WhileHandlerTest method shouldRepeatDelegateOperationUntilMaxRepeatsReached.

@Test
public void shouldRepeatDelegateOperationUntilMaxRepeatsReached() throws OperationException {
    // Given
    final List<EntitySeed> input = Collections.singletonList(mock(EntitySeed.class));
    final int maxRepeats = 3;
    final GetAdjacentIds delegate = mock(GetAdjacentIds.class);
    final GetAdjacentIds delegateClone1 = mock(GetAdjacentIds.class);
    final GetAdjacentIds delegateClone2 = mock(GetAdjacentIds.class);
    final GetAdjacentIds delegateClone3 = mock(GetAdjacentIds.class);
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    given(delegate.shallowClone()).willReturn(delegateClone1, delegateClone2, delegateClone3);
    final CloseableIterable result1 = mock(CloseableIterable.class);
    final CloseableIterable result2 = mock(CloseableIterable.class);
    final CloseableIterable result3 = mock(CloseableIterable.class);
    given(store.execute(delegateClone1, context)).willReturn(result1);
    given(store.execute(delegateClone2, context)).willReturn(result2);
    given(store.execute(delegateClone3, context)).willReturn(result3);
    final While operation = new While.Builder<>().input(input).maxRepeats(maxRepeats).operation(delegate).build();
    final WhileHandler handler = new WhileHandler();
    // When
    final Object result = handler.doOperation(operation, context, store);
    // Then
    verify(delegateClone1, times(1)).getInput();
    verify(delegateClone2, times(1)).getInput();
    verify(delegateClone3, times(1)).getInput();
    verify(store).execute((Output) delegateClone1, context);
    verify(store).execute((Output) delegateClone2, context);
    verify(store).execute((Output) delegateClone3, context);
    assertSame(result3, result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Store(uk.gov.gchq.gaffer.store.Store) While(uk.gov.gchq.gaffer.operation.impl.While) Test(org.junit.jupiter.api.Test)

Example 99 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class GetJavaRDDOfElementsHandlerTest method checkGetCorrectElementsInJavaRDDForEntityId.

@Test
public void checkGetCorrectElementsInJavaRDDForEntityId() throws OperationException, IOException {
    final Graph graph1 = new Graph.Builder().config(new GraphConfig.Builder().graphId("graphId").build()).addSchema(getClass().getResourceAsStream("/schema/elements.json")).addSchema(getClass().getResourceAsStream("/schema/types.json")).addSchema(getClass().getResourceAsStream("/schema/serialisation.json")).storeProperties(PROPERTIES).build();
    final List<Element> elements = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        final Entity entity = new Entity.Builder().group(TestGroups.ENTITY).vertex("" + i).build();
        final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("" + i).dest("B").directed(false).property("count", 2).build();
        final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE).source("" + i).dest("C").directed(false).property("count", 4).build();
        elements.add(edge1);
        elements.add(edge2);
        elements.add(entity);
    }
    final User user = new User();
    graph1.execute(new AddElements.Builder().input(elements).build(), user);
    // Create Hadoop configuration and serialise to a string
    final Configuration configuration = new Configuration();
    final String configurationString = AbstractGetRDDHandler.convertConfigurationToString(configuration);
    // Check get correct edges for "1"
    GetJavaRDDOfElements rddQuery = new GetJavaRDDOfElements.Builder().input(Collections.singleton(new EntitySeed("1"))).build();
    rddQuery.addOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY, configurationString);
    JavaRDD<Element> rdd = graph1.execute(rddQuery, user);
    if (rdd == null) {
        fail("No RDD returned");
    }
    final Set<Element> results = new HashSet<>(rdd.collect());
    final Set<Element> expectedElements = new HashSet<>();
    final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY).vertex("1").build();
    final Edge edge1B = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("B").directed(false).property("count", 2).build();
    final Edge edge1C = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("C").directed(false).property("count", 4).build();
    expectedElements.add(entity1);
    expectedElements.add(edge1B);
    expectedElements.add(edge1C);
    assertEquals(expectedElements, results);
    // Check get correct edges for "1" when specify entities only
    rddQuery = new GetJavaRDDOfElements.Builder().input(new EntitySeed("1")).view(new View.Builder().entity(ENTITY_GROUP).build()).build();
    rddQuery.addOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY, configurationString);
    rdd = graph1.execute(rddQuery, user);
    if (rdd == null) {
        fail("No RDD returned");
    }
    results.clear();
    results.addAll(rdd.collect());
    expectedElements.clear();
    expectedElements.add(entity1);
    assertEquals(expectedElements, results);
    // Check get correct edges for "1" when specify edges only
    rddQuery = new GetJavaRDDOfElements.Builder().input(new EntitySeed("1")).view(new View.Builder().edge(EDGE_GROUP).build()).build();
    rddQuery.addOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY, configurationString);
    rdd = graph1.execute(rddQuery, user);
    if (rdd == null) {
        fail("No RDD returned");
    }
    results.clear();
    results.addAll(rdd.collect());
    expectedElements.clear();
    expectedElements.add(edge1B);
    expectedElements.add(edge1C);
    assertEquals(expectedElements, results);
    // Check get correct edges for "1" and "5"
    rddQuery = new GetJavaRDDOfElements.Builder().input(new EntitySeed("1"), new EntitySeed("5")).build();
    rddQuery.addOption(AbstractGetRDDHandler.HADOOP_CONFIGURATION_KEY, configurationString);
    rdd = graph1.execute(rddQuery, user);
    if (rdd == null) {
        fail("No RDD returned");
    }
    results.clear();
    results.addAll(rdd.collect());
    final Entity entity5 = new Entity.Builder().group(TestGroups.ENTITY).vertex("5").build();
    final Edge edge5B = new Edge.Builder().group(TestGroups.EDGE).source("5").dest("B").directed(false).property("count", 2).build();
    final Edge edge5C = new Edge.Builder().group(TestGroups.EDGE).source("5").dest("C").directed(false).property("count", 4).build();
    expectedElements.clear();
    expectedElements.add(entity1);
    expectedElements.add(edge1B);
    expectedElements.add(edge1C);
    expectedElements.add(entity5);
    expectedElements.add(edge5B);
    expectedElements.add(edge5C);
    assertEquals(expectedElements, results);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Configuration(org.apache.hadoop.conf.Configuration) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Graph(uk.gov.gchq.gaffer.graph.Graph) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetJavaRDDOfElements(uk.gov.gchq.gaffer.spark.operation.javardd.GetJavaRDDOfElements) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 100 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class AggregatorIteratorTest method test.

private void test(final AccumuloStore store) throws OperationException {
    // Given
    final Edge expectedResult = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COUNT, 13).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 1).property(AccumuloPropertyNames.PROP_4, 1).build();
    final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 1).property(AccumuloPropertyNames.PROP_4, 0).build();
    final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 2).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 1).build();
    final Edge edge3 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 10).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build();
    final User user = new User();
    store.execute(new AddElements.Builder().input(edge1, edge2, edge3).build(), new Context(user));
    final GetElements get = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).build()).input(new EntitySeed("1")).build();
    // When
    final List<Element> results = Lists.newArrayList(store.execute(get, new Context(user)));
    // Then
    assertThat(results).hasSize(1);
    final Edge aggregatedEdge = (Edge) results.get(0);
    assertEquals(expectedResult, aggregatedEdge);
    assertEquals(expectedResult.getProperties(), aggregatedEdge.getProperties());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Aggregations

EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)284 Test (org.junit.jupiter.api.Test)122 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)122 Element (uk.gov.gchq.gaffer.data.element.Element)102 User (uk.gov.gchq.gaffer.user.User)92 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)90 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)87 HashSet (java.util.HashSet)71 Graph (uk.gov.gchq.gaffer.graph.Graph)69 Entity (uk.gov.gchq.gaffer.data.element.Entity)65 Edge (uk.gov.gchq.gaffer.data.element.Edge)61 Test (org.junit.Test)58 ArrayList (java.util.ArrayList)55 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)46 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)41 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)40 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)38 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)36 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)36 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)35