use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class AccumuloIDWithinSetRetrieverTest method shouldDealWithDirectedEdgesOnlyOption.
private void shouldDealWithDirectedEdgesOnlyOption(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
final Set<EntitySeed> seeds = new HashSet<>();
seeds.add(new EntitySeed("C"));
seeds.add(new EntitySeed("D"));
final GetElements<EntitySeed, ?> op = new GetElements<>(defaultView, seeds);
// Set undirected edges only option, and query for edges in set {C, D} - should get the undirected edge
op.setIncludeEdges(GetOperation.IncludeEdgeType.UNDIRECTED);
op.setIncludeEntities(false);
final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
assertThat(results, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_C_D_UNDIRECTED));
// Set directed edges only option, and query for edges in set {C, D} - should get the directed edge
final GetElements<EntitySeed, ?> directedCOop = new GetElements<>(defaultView, seeds);
directedCOop.setIncludeEdges(IncludeEdgeType.DIRECTED);
final Set<Element> directedCDResults = returnElementsFromOperation(store, directedCOop, new User(), loadIntoMemory);
assertThat(directedCDResults, IsCollectionContaining.hasItem(AccumuloTestData.EDGE_C_D_DIRECTED));
final GetElements<EntitySeed, ?> bothDirectedAndUndirectedOp = new GetElements<>(defaultView, seeds);
// Turn off directed / undirected edges only option and check get both the undirected and directed edge
bothDirectedAndUndirectedOp.setIncludeEdges(IncludeEdgeType.ALL);
final Set<Element> bothDirectedAndUndirectedResults = returnElementsFromOperation(store, bothDirectedAndUndirectedOp, new User(), loadIntoMemory);
assertThat(bothDirectedAndUndirectedResults, IsCollectionContaining.hasItems(AccumuloTestData.EDGE_C_D_DIRECTED, ((Element) AccumuloTestData.EDGE_C_D_UNDIRECTED)));
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class AccumuloIDWithinSetRetrieverTest method setupGraph.
private static void setupGraph(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).
TableUtils.createTable(store);
final Set<Element> data = new HashSet<>();
// Create edges A0 -> A1, A0 -> A2, ..., A0 -> A99. Also create an Entity for each.
final Entity entity = new Entity(TestGroups.ENTITY);
entity.setVertex("A0");
entity.putProperty(AccumuloPropertyNames.COUNT, 10000);
data.add(entity);
for (int i = 1; i < 100; i++) {
final Edge edge = new Edge(TestGroups.EDGE);
edge.setSource("A0");
edge.setDestination("A" + i);
edge.setDirected(true);
edge.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 1);
edge.putProperty(AccumuloPropertyNames.COUNT, i);
data.add(edge);
final Entity edgeEntity = new Entity(TestGroups.ENTITY);
edgeEntity.setVertex("A" + i);
edgeEntity.putProperty(AccumuloPropertyNames.COUNT, i);
data.add(edgeEntity);
}
data.add(AccumuloTestData.EDGE_C_D_DIRECTED);
data.add(AccumuloTestData.EDGE_C_D_UNDIRECTED);
addElements(data, store, new User());
} catch (TableExistsException | StoreException e) {
fail("Failed to set up graph in Accumulo with exception: " + e);
}
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class AccumuloIDWithinSetRetrieverTest method shouldGetCorrectEdges.
private void shouldGetCorrectEdges(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
// Query for all edges in set {A0, A23}
final Set<EntitySeed> seeds = new HashSet<>();
seeds.add(AccumuloTestData.SEED_A0);
seeds.add(AccumuloTestData.SEED_A23);
final GetElements<EntitySeed, ?> op = new GetElements<>(defaultView, seeds);
final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
assertThat(results, IsCollectionContaining.hasItems(AccumuloTestData.EDGE_A0_A23, AccumuloTestData.A0_ENTITY, AccumuloTestData.A23_ENTITY));
// Query for all edges in set {A1} - there shouldn't be any, but we will get the entity for A1
final GetElements<EntitySeed, ?> a1Operation = new GetElements<>(defaultView, AccumuloTestData.SEED_A1_SET);
final Set<Element> a1Results = returnElementsFromOperation(store, a1Operation, new User(), loadIntoMemory);
assertEquals(1, a1Results.size());
assertThat(a1Results, IsCollectionContaining.hasItem(AccumuloTestData.A1_ENTITY));
// Query for all edges in set {A1, A2} - there shouldn't be any edges but will
// get the two entities
final Set<EntitySeed> a1A2Seeds = new HashSet<>();
a1A2Seeds.add(AccumuloTestData.SEED_A1);
a1A2Seeds.add(AccumuloTestData.SEED_A2);
final GetElements<EntitySeed, ?> a1A2Operation = new GetElements<>(defaultView, a1A2Seeds);
final Set<Element> a1A2Results = returnElementsFromOperation(store, a1A2Operation, new User(), loadIntoMemory);
assertEquals(2, a1A2Results.size());
assertThat(a1A2Results, IsCollectionContaining.hasItems(AccumuloTestData.A1_ENTITY, AccumuloTestData.A2_ENTITY));
}
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));
}
Aggregations