Search in sources :

Example 76 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class GetElementsBetweenSetsHandlerTest method setupGraph.

private static void setupGraph(final AccumuloStore store) {
    List<Element> data = new ArrayList<>();
    // Create edges A0 -> A1, A0 -> A2, ..., A0 -> A99. Also create an Entity for each.
    final Entity entity = new Entity(TestGroups.ENTITY, "A0");
    entity.putProperty(AccumuloPropertyNames.COUNT, 10000);
    data.add(entity);
    for (int i = 1; i < 100; i++) {
        data.add(new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("A" + i).directed(true).property(AccumuloPropertyNames.COUNT, 23).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build());
        data.add(new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("A" + i).directed(true).property(AccumuloPropertyNames.COUNT, 23).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 2).build());
        data.add(new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("A" + i).directed(true).property(AccumuloPropertyNames.COUNT, 23).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 3).build());
        data.add(new Entity.Builder().group(TestGroups.ENTITY).vertex("A" + i).property(AccumuloPropertyNames.COUNT, i).build());
    }
    addElements(data, store, new User());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList)

Example 77 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testEntityIdQueryIncomingEdgesOnly.

private void testEntityIdQueryIncomingEdgesOnly(final AccumuloStore store) throws StoreException {
    setupGraph(store, NUM_ENTRIES);
    final User user = new User();
    // Create set to query for
    final Set<ElementId> ids = new HashSet<>();
    for (int i = 0; i < NUM_ENTRIES; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever<?> retriever = null;
    final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
    operation.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
    try {
        retriever = new AccumuloSingleIDRetriever<>(store, operation, user);
    } catch (final IteratorSettingException e) {
        throw new RuntimeException(e);
    }
    for (final Element element : retriever) {
        Edge edge = (Edge) element;
        assertEquals("B", edge.getDestination());
    }
    // Incoming option should find all edges i-B as undirected are both incoming and outgoing.
    assertEquals(NUM_ENTRIES, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) 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) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Example 78 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testEntityIdQueryOutgoingEdgesOnly.

private void testEntityIdQueryOutgoingEdgesOnly(final AccumuloStore store) throws StoreException {
    setupGraph(store, NUM_ENTRIES);
    final User user = new User();
    // Create set to query for
    Set<ElementId> ids = new HashSet<>();
    for (int i = 0; i < NUM_ENTRIES; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever<?> retriever = null;
    GetElements operation = new GetElements.Builder().view(view).input(ids).build();
    operation.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.OUTGOING);
    try {
        retriever = new AccumuloSingleIDRetriever<>(store, operation, user);
    } catch (final IteratorSettingException e) {
        throw new RuntimeException(e);
    }
    int count = 0;
    for (final Element element : retriever) {
        count++;
        assertEquals(TestGroups.EDGE, element.getGroup());
    }
    // Should find both i-B and i-C edges.
    assertEquals(NUM_ENTRIES * 2, count);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Example 79 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testDirectedEdgeIdQueries.

private void testDirectedEdgeIdQueries(final AccumuloStore store) throws StoreException {
    setupGraph(store, NUM_ENTRIES);
    final User user = new User();
    // Create set to query for
    final Set<ElementId> ids = new HashSet<>();
    for (int i = 0; i < NUM_ENTRIES; i++) {
        ids.add(new EdgeSeed("" + i, "B", false));
        ids.add(new EdgeSeed("" + i, "C", true));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever<?> retriever = null;
    final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
    operation.setDirectedType(DirectedType.DIRECTED);
    try {
        retriever = new AccumuloSingleIDRetriever<>(store, operation, user);
    } catch (final IteratorSettingException e) {
        throw new RuntimeException(e);
    }
    for (final Element element : retriever) {
        Edge edge = (Edge) element;
        assertEquals("C", edge.getDestination());
    }
    // Should find 1000 only A-C
    assertEquals(NUM_ENTRIES, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Example 80 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testEntityIdQueryEdgesAndEntities.

private void testEntityIdQueryEdgesAndEntities(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, NUM_ENTRIES);
    final User user = new User();
    // Create set to query for
    final Set<ElementId> ids = new HashSet<>();
    for (int i = 0; i < NUM_ENTRIES; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
    final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
    try {
        final AccumuloSingleIDRetriever retriever = new AccumuloSingleIDRetriever(store, operation, new User());
        assertEquals(NUM_ENTRIES * 3, Iterables.size(retriever));
    } catch (final IteratorSettingException e) {
        fail("Unable to construct SingleID Retriever");
    }
// Should find both i-B and i-C edges and entities i
}
Also used : User(uk.gov.gchq.gaffer.user.User) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Aggregations

User (uk.gov.gchq.gaffer.user.User)378 Test (org.junit.jupiter.api.Test)188 Graph (uk.gov.gchq.gaffer.graph.Graph)155 Element (uk.gov.gchq.gaffer.data.element.Element)143 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)128 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)110 HashSet (java.util.HashSet)109 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)104 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)103 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)98 Edge (uk.gov.gchq.gaffer.data.element.Edge)85 Context (uk.gov.gchq.gaffer.store.Context)85 Entity (uk.gov.gchq.gaffer.data.element.Entity)77 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)57 OperationException (uk.gov.gchq.gaffer.operation.OperationException)52 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)49 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)48 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)45 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)43