use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class ToArrayHandlerTest method shouldConvertIterableOfElementIdsToArray.
@Test
public void shouldConvertIterableOfElementIdsToArray() throws OperationException {
// Given
final ElementId[] originalArray = new ElementId[] { new EntitySeed("vertex"), new EdgeSeed("src", "dest", true) };
final Iterable<ElementId> originalResults = new WrappedCloseableIterable<>(Arrays.asList(originalArray));
final ToArrayHandler<ElementId> handler = new ToArrayHandler<>();
final ToArray operation = mock(ToArray.class);
given(operation.getInput()).willReturn(originalResults);
// When
final ElementId[] results = handler.doOperation(operation, new Context(), null);
// Then
assertArrayEquals(originalArray, results);
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class ToArrayHandlerTest method shouldConvertIterableOfElementsAndElementIdsToArray.
@Test
public void shouldConvertIterableOfElementsAndElementIdsToArray() throws OperationException {
// Given
final ElementId[] originalArray = new ElementId[] { new Entity.Builder().group("entity").build(), new Edge.Builder().group("edge").build(), new EntitySeed("vertex"), new EdgeSeed("src", "dest", true) };
final Iterable<ElementId> originalResults = new WrappedCloseableIterable<>(Arrays.asList(originalArray));
final ToArrayHandler<ElementId> handler = new ToArrayHandler<>();
final ToArray operation = mock(ToArray.class);
given(operation.getInput()).willReturn(originalResults);
// When
final ElementId[] results = handler.doOperation(operation, new Context(), null);
// Then
assertArrayEquals(originalArray, results);
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class AbstractGetRDDHandler method addRanges.
public <INPUT_OP extends Operation & GraphFilters & Input<Iterable<? extends ElementId>>> void addRanges(final AccumuloStore accumuloStore, final Configuration conf, final INPUT_OP operation) throws OperationException {
final List<Range> ranges = new ArrayList<>();
for (final ElementId entityId : operation.getInput()) {
try {
ranges.addAll(accumuloStore.getKeyPackage().getRangeFactory().getRange(entityId, operation));
} catch (final RangeFactoryException e) {
throw new OperationException("Failed to add ranges to configuration", e);
}
}
InputConfigurator.setRanges(AccumuloInputFormat.class, conf, ranges);
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId 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.data.element.id.ElementId 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);
}
Aggregations