use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class AccumuloIDWithinSetRetrieverTest method shouldDealWithDirectedEdgesOnlyOption.
private void shouldDealWithDirectedEdgesOnlyOption(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException {
final Set<EntityId> seeds = new HashSet<>();
seeds.add(new EntitySeed("C"));
seeds.add(new EntitySeed("D"));
final GetElementsWithinSet op = new GetElementsWithinSet.Builder().view(defaultView).input(seeds).build();
// Set undirected edges only option, and query for edges in set {C, D} - should get the undirected edge
op.setDirectedType(DirectedType.UNDIRECTED);
final Set<Element> results = returnElementsFromOperation(store, op, new User(), loadIntoMemory);
assertThat(results).contains(AccumuloTestData.EDGE_C_D_UNDIRECTED);
// Set directed edges only option, and query for edges in set {C, D} - should get the directed edge
final GetElementsWithinSet directedCOop = new GetElementsWithinSet.Builder().view(defaultView).input(seeds).build();
directedCOop.setDirectedType(DirectedType.DIRECTED);
final Set<Element> directedCDResults = returnElementsFromOperation(store, directedCOop, new User(), loadIntoMemory);
assertThat(directedCDResults).contains(AccumuloTestData.EDGE_C_D_DIRECTED);
final GetElementsWithinSet bothDirectedAndUndirectedOp = new GetElementsWithinSet.Builder().view(defaultView).input(seeds).build();
// Turn off directed / undirected edges only option and check get both the undirected and directed edge
bothDirectedAndUndirectedOp.setDirectedType(DirectedType.EITHER);
final Set<Element> bothDirectedAndUndirectedResults = returnElementsFromOperation(store, bothDirectedAndUndirectedOp, new User(), loadIntoMemory);
assertThat(bothDirectedAndUndirectedResults).contains(AccumuloTestData.EDGE_C_D_DIRECTED, (Element) AccumuloTestData.EDGE_C_D_UNDIRECTED);
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class GetElementsInRangesHandlerTest method shouldSummarise.
private void shouldSummarise(final AccumuloStore store) throws OperationException {
// Given - get everything between 0 and 1 (Note we are using strings and string serialisers, with this ordering 0999 is before 1)
final Set<Pair<ElementId, ElementId>> simpleEntityRanges = new HashSet<>();
simpleEntityRanges.add(new Pair<>(new EntitySeed("0"), new EntitySeed("1")));
final View view = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
final Output operation = createOperation(simpleEntityRanges, view, IncludeIncomingOutgoingType.EITHER, DirectedType.EITHER);
// When
List<Element> results = executeOperation(operation, store);
// Then
ElementUtil.assertElementEquals(createSummarisedElements(NUM_ENTRIES), results);
// Given - this should get everything between 0 and 0799 (again being string ordering 0800 is more than 08)
simpleEntityRanges.clear();
simpleEntityRanges.add(new Pair<>(new EntitySeed("0"), new EntitySeed("08")));
// When
results = executeOperation(operation, store);
// Then
ElementUtil.assertElementEquals(createSummarisedElements(800), results);
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed 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));
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed 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);
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed 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
}
Aggregations