Search in sources :

Example 66 with User

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

the class AccumuloIDBetweenSetsRetrieverTest method shouldDealWithOutgoingEdgesOnlyOption.

/**
 * Tests that the options to set outgoing edges or incoming edges only options work correctly.
 *
 * @param store the Store instance
 */
private void shouldDealWithOutgoingEdgesOnlyOption(final AccumuloStore store) {
    try {
        /*
             Create table
             (this method creates the table, removes the versioning iterator, and adds the SetOfStatisticsCombiner iterator,
             and sets the age off iterator to age data off after it is more than ageOffTimeInMilliseconds milliseconds old).
              */
        final Set<Element> data = new HashSet<>();
        data.add(AccumuloTestData.EDGE_A1_B1);
        data.add(AccumuloTestData.EDGE_B2_A2);
        addElements(data, store, new User());
        // Query for edges between {A1} and {B1}, with outgoing edges only. Should get the edge A1>B1.
        final GetElementsBetweenSets opA1B1 = new GetElementsBetweenSets.Builder().input(AccumuloTestData.SEED_A1_SET).inputB(AccumuloTestData.SEED_B1_SET).view(edgeOnlyView).build();
        opA1B1.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.OUTGOING);
        final Set<Element> a1B1OutgoingEdgeResults = returnElementsFromOperation(store, opA1B1, new User(), false);
        assertThat(a1B1OutgoingEdgeResults).contains(AccumuloTestData.EDGE_A1_B1);
        // Query for edges between {A1} and {B1}, with incoming edges only. Should get nothing.
        opA1B1.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
        final Set<Element> a1B1EdgeIncomingResults = returnElementsFromOperation(store, opA1B1, new User(), false);
        assertThat(a1B1EdgeIncomingResults).isEmpty();
        // Query for edges between {A2} and {B2}, with incoming edges only. Should get the edge B2->A2.
        final GetElementsBetweenSets opA2B2 = new GetElementsBetweenSets.Builder().input(AccumuloTestData.SEED_A2_SET).inputB(AccumuloTestData.SEED_B2_SET).view(edgeOnlyView).build();
        opA2B2.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
        final Set<Element> a2B2EdgeIncomingResults = returnElementsFromOperation(store, opA2B2, new User(), false);
        assertThat(a2B2EdgeIncomingResults).contains(AccumuloTestData.EDGE_B2_A2);
        // Query for edges between {A2} and {B2}, with outgoing edges only. Should get nothing.
        opA2B2.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.OUTGOING);
        final Set<Element> a2B2EdgeOutgoingResults = returnElementsFromOperation(store, opA2B2, new User(), false);
        assertThat(a2B2EdgeOutgoingResults).isEmpty();
    } catch (final StoreException e) {
        fail("Failed to set up graph in Accumulo with exception: " + e);
    }
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) Element(uk.gov.gchq.gaffer.data.element.Element) HashSet(java.util.HashSet) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 67 with User

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

the class AccumuloIDBetweenSetsRetrieverTest method shouldLoadElementsWhenMoreElementsThanFitInBatchScanner.

private void shouldLoadElementsWhenMoreElementsThanFitInBatchScanner(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
    store.getProperties().setMaxEntriesForBatchScanner("1");
    // Query for all edges between the set {A0} and the set {A23}
    final GetElementsBetweenSets op = new GetElementsBetweenSets.Builder().input(AccumuloTestData.SEED_A0_SET).inputB(AccumuloTestData.SEED_A23_SET).view(defaultView).build();
    final Set<Element> betweenA0A23results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    assertThat(betweenA0A23results).hasSize(2).contains(AccumuloTestData.EDGE_A0_A23, AccumuloTestData.A0_ENTITY);
    // Query for all edges between set {A1} and the set {notpresent} - there shouldn't be any, but
    // we will get the entity for A1
    final GetElementsBetweenSets secondOp = new GetElementsBetweenSets.Builder().input(AccumuloTestData.SEED_A1_SET).inputB(AccumuloTestData.NOT_PRESENT_ENTITY_SEED_SET).view(defaultView).build();
    final Set<Element> betweenA1andNotPresentResults = returnElementsFromOperation(store, secondOp, new User(), loadIntoMemory);
    assertThat(betweenA1andNotPresentResults).hasSize(1).contains(AccumuloTestData.A1_ENTITY);
    // Query for all edges between set {A1} and the set {A2} - there shouldn't be any edges but will
    // get the entity for A1
    final GetElementsBetweenSets thirdOp = new GetElementsBetweenSets.Builder().input(AccumuloTestData.SEED_A1_SET).inputB(AccumuloTestData.SEED_A2_SET).view(defaultView).build();
    final Set<Element> betweenA1A2Results = returnElementsFromOperation(store, thirdOp, new User(), loadIntoMemory);
    assertThat(betweenA1A2Results).hasSize(1).contains(AccumuloTestData.A1_ENTITY);
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) Element(uk.gov.gchq.gaffer.data.element.Element)

Example 68 with User

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

the class AccumuloIDBetweenSetsRetrieverTest method shouldDealWithDirectedEdgesOnlyOption.

private void shouldDealWithDirectedEdgesOnlyOption(final boolean loadIntoMemory, final AccumuloStore store) {
    try {
        final Set<Element> data = new HashSet<>();
        data.add(AccumuloTestData.EDGE_A_B_1);
        data.add(AccumuloTestData.EDGE_A_B_2);
        addElements(data, store, new User());
        // Set undirected edges only option, and query for edges between {A} and {B} - should get EDGE_B2_A2
        final GetElementsBetweenSets op = new GetElementsBetweenSets.Builder().input(AccumuloTestData.SEED_A_SET).inputB(AccumuloTestData.SEED_B_SET).view(edgeOnlyView).build();
        op.setDirectedType(DirectedType.UNDIRECTED);
        final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
        assertThat(results).contains(AccumuloTestData.EDGE_A_B_2);
        op.setDirectedType(DirectedType.DIRECTED);
        final Set<Element> secondResults = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
        assertThat(secondResults).contains(AccumuloTestData.EDGE_A_B_1);
        // Turn off directed / undirected edges only option and check get both EDGE_A1_B1 and EDGE_B2_A2
        op.setDirectedType(DirectedType.EITHER);
        final Set<Element> thirdResults = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
        assertThat(thirdResults).contains(AccumuloTestData.EDGE_A_B_2);
    } catch (final StoreException e) {
        fail("Failed to set up graph in Accumulo with exception: " + e);
    }
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) Element(uk.gov.gchq.gaffer.data.element.Element) HashSet(java.util.HashSet) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 69 with User

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

the class AccumuloIDBetweenSetsRetrieverTest method testEdgesWithinSetAAreNotReturned.

private void testEdgesWithinSetAAreNotReturned(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
    final GetElementsBetweenSets op = new GetElementsBetweenSets.Builder().input(AccumuloTestData.SEED_A0_A23_SET).inputB(AccumuloTestData.SEED_B_SET).view(defaultView).build();
    final Set<Element> betweenA0A23_B_Results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
    // Should have the two entities A0 A23 but not the edge A0-23
    assertThat(betweenA0A23_B_Results).hasSize(2).contains(AccumuloTestData.A0_ENTITY, AccumuloTestData.A23_ENTITY);
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) Element(uk.gov.gchq.gaffer.data.element.Element)

Example 70 with User

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

the class AccumuloRangeIDRetrieverTest method setupGraph.

private static void setupGraph(final AccumuloStore store, final int numEntries) {
    final List<Element> elements = new ArrayList<>();
    for (int i = 0; i < numEntries; i++) {
        String s = "" + i;
        while (s.length() < 4) {
            s = "0" + s;
        }
        elements.add(new Edge.Builder().group(TestGroups.EDGE).source(s).dest("B").directed(false).build());
    }
    try {
        final User user = new User();
        store.execute(new AddElements.Builder().input(elements).build(), new Context(user));
    } catch (final OperationException e) {
        fail("Couldn't add element: " + e);
    }
}
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) ArrayList(java.util.ArrayList) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

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