use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class AccumuloRangeIDRetrieverTest method setupGraph.
private static void setupGraph(final AccumuloStore store, int numEntries) {
final List<Element> elements = new ArrayList<>();
for (int i = 0; i < numEntries; i++) {
final Edge edge = new Edge(TestGroups.EDGE);
String s = "" + i;
while (s.length() < 4) {
s = "0" + s;
}
edge.setSource(s);
edge.setDestination("B");
edge.setDirected(false);
elements.add(edge);
}
try {
final User user = new User();
store.execute(new AddElements(elements), user);
} catch (OperationException e) {
fail("Couldn't add element: " + e);
}
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class AccumuloSingleIDRetrieverTest method testUndirectedEdgeSeedQueries.
private void testUndirectedEdgeSeedQueries(final AccumuloStore store) throws AccumuloException, StoreException {
setupGraph(store, numEntries);
final User user = new User();
// Create set to query for
final Set<ElementSeed> ids = new HashSet<>();
for (int i = 0; i < numEntries; 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<ElementSeed, ?> operation = new GetElements<>(view, ids);
operation.setIncludeEdges(IncludeEdgeType.UNDIRECTED);
try {
retriever = new AccumuloSingleIDRetriever(store, operation, user);
} catch (IteratorSettingException e) {
e.printStackTrace();
}
for (final Element element : retriever) {
Edge edge = (Edge) element;
assertEquals("B", edge.getDestination());
}
//We should have only 1000 returned the i-B edges that are undirected
assertEquals(numEntries, Iterables.size(retriever));
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class AccumuloSingleIDRetrieverTest method testDirectedEdgeSeedQueries.
private void testDirectedEdgeSeedQueries(final AccumuloStore store) throws AccumuloException, StoreException {
setupGraph(store, numEntries);
final User user = new User();
// Create set to query for
final Set<ElementSeed> ids = new HashSet<>();
for (int i = 0; i < numEntries; 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<ElementSeed, ?> operation = new GetElements<>(view, ids);
operation.setIncludeEdges(IncludeEdgeType.DIRECTED);
try {
retriever = new AccumuloSingleIDRetriever(store, operation, user);
} catch (IteratorSettingException e) {
e.printStackTrace();
}
for (final Element element : retriever) {
Edge edge = (Edge) element;
assertEquals("C", edge.getDestination());
}
//Should find 1000 only A-C
assertEquals(numEntries, Iterables.size(retriever));
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class AccumuloSingleIDRetrieverTest method testEntitySeedQueryIncomingEdgesOnly.
private void testEntitySeedQueryIncomingEdgesOnly(final AccumuloStore store) throws AccumuloException, StoreException {
setupGraph(store, numEntries);
final User user = new User();
// Create set to query for
final Set<ElementSeed> ids = new HashSet<>();
for (int i = 0; i < numEntries; i++) {
ids.add(new EntitySeed("" + i));
}
final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
AccumuloSingleIDRetriever retriever = null;
final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
operation.setIncludeEntities(false);
operation.setIncludeIncomingOutGoing(IncludeIncomingOutgoingType.INCOMING);
try {
retriever = new AccumuloSingleIDRetriever(store, operation, user);
} catch (IteratorSettingException e) {
e.printStackTrace();
}
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(numEntries, Iterables.size(retriever));
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class AccumuloIDBetweenSetsRetrieverTest method shouldDealWithDirectedEdgesOnlyOption.
private void shouldDealWithDirectedEdgesOnlyOption(boolean loadIntoMemory, 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 AbstractAccumuloTwoSetSeededOperation<EntitySeed, Element> op = new GetElementsBetweenSets<>(AccumuloTestData.SEED_A_SET, AccumuloTestData.SEED_B_SET, defaultView);
op.setIncludeEdges(IncludeEdgeType.UNDIRECTED);
op.setIncludeEntities(false);
final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
assertThat(results, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_A_B_2));
op.setIncludeEdges(IncludeEdgeType.DIRECTED);
final Set<Element> secondResults = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
assertThat(secondResults, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_A_B_1));
// Turn off directed / undirected edges only option and check get both EDGE_A1_B1 and EDGE_B2_A2
op.setIncludeEdges(IncludeEdgeType.ALL);
final Set<Element> thirdResults = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
assertThat(thirdResults, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_A_B_2));
} catch (StoreException e) {
fail("Failed to set up graph in Accumulo with exception: " + e);
}
}
Aggregations