use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.
the class GetGafferResultCacheExportHandlerTest method shouldHandleOperationByDelegatingToAnExistingExporter.
@Test
public void shouldHandleOperationByDelegatingToAnExistingExporter() throws OperationException {
// Given
final GetGafferResultCacheExport export = new GetGafferResultCacheExport.Builder().key("key").build();
final Context context = new Context();
final Store store = mock(Store.class);
final JSONSerialiser jsonSerialiser = mock(JSONSerialiser.class);
final Long timeToLive = 10000L;
final String visibility = "visibility value";
final GafferResultCacheExporter exporter = mock(GafferResultCacheExporter.class);
final CloseableIterable results = new WrappedCloseableIterable<>(Arrays.asList(1, 2, 3));
given(exporter.get("key")).willReturn(results);
context.addExporter(exporter);
final GetGafferResultCacheExportHandler handler = new GetGafferResultCacheExportHandler();
handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
handler.setJsonSerialiser(jsonSerialiser);
handler.setTimeToLive(timeToLive);
handler.setVisibility(visibility);
// When
final Object handlerResult = handler.doOperation(export, context, store);
// Then
verify(exporter).get("key");
assertSame(results, handlerResult);
}
use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.
the class AccumuloRangeIDRetrieverTest method shouldRetieveElementsInRangeBetweenSeeds.
private void shouldRetieveElementsInRangeBetweenSeeds(final AccumuloStore store) throws StoreException {
// Create set to query for
final Set<Pair<ElementSeed>> simpleEntityRanges = new HashSet<>();
simpleEntityRanges.add(new Pair<ElementSeed>(new EntitySeed("0000"), new EntitySeed("0999")));
// Retrieve elements when less simple entities are provided than the max number of entries for the batch scanner
final GetElementsOperation<Pair<ElementSeed>, CloseableIterable<Element>> operation = new GetElementsInRanges<>(defaultView, simpleEntityRanges);
try {
final AccumuloRangeIDRetriever retriever = new AccumuloRangeIDRetriever(store, operation, new User());
assertEquals(numEntries, Iterables.size(retriever));
} catch (IteratorSettingException e) {
fail("Unable to construct Range Retriever");
}
}
use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.
the class ArrayListStoreTest method shouldAddAndGetEntitiesBySeed.
@Test
public void shouldAddAndGetEntitiesBySeed() throws OperationException {
final Graph graph = createGraph();
addElementsToGraph(graph);
//set up the operation to fetch the entities
final OperationChain<CloseableIterable<SimpleEntityDataObject>> opChain = new OperationChain.Builder().first(new GetEntities.Builder().addSeed(new EntitySeed(1)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Entity, SimpleEntityDataObject>().generator(new SimpleEntityGenerator()).build()).build();
//now do the hop
final CloseableIterable<SimpleEntityDataObject> results = graph.execute(opChain, new User());
//check the results by converting our edges back into SimpleDataObjects
if (!results.iterator().hasNext()) {
fail("No results returned");
} else {
for (final SimpleEntityDataObject obj : results) {
LOGGER.info(obj.toString());
}
final List<SimpleEntityDataObject> resultList = Lists.newArrayList(results);
int index = 0;
SimpleEntityDataObject obj = resultList.get(index);
assertEquals(1, obj.getId());
assertEquals(1, obj.getVisibility());
assertEquals("Red", obj.getProperties());
}
results.close();
}
use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.
the class ArrayListStoreTest method shouldAddAndGetRelatedEdges.
@Test
public void shouldAddAndGetRelatedEdges() throws OperationException {
final Graph graph = createGraph();
addElementsToGraph(graph);
//set up the operation to fetch the edges
final OperationChain<CloseableIterable<SimpleEdgeDataObject>> opChain = new OperationChain.Builder().first(new GetEdges.Builder<>().addSeed(new EntitySeed(1)).addSeed(new EntitySeed(2)).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Edge, SimpleEdgeDataObject>().generator(new SimpleEdgeGenerator()).build()).build();
//now do the hop
final CloseableIterable<SimpleEdgeDataObject> results = graph.execute(opChain, new User());
//check the results by converting our edges back into SimpleDataObjects
if (!results.iterator().hasNext()) {
fail("No results returned");
} else {
for (final SimpleEdgeDataObject obj : results) {
LOGGER.info(obj.toString());
}
final List<SimpleEdgeDataObject> resultList = Lists.newArrayList(results);
assertEquals(3, resultList.size());
int index = 0;
SimpleEdgeDataObject obj = resultList.get(index++);
assertEquals(1, obj.getLeft());
assertEquals(2, obj.getRight());
assertEquals(1, obj.getVisibility());
assertEquals("121", obj.getProperties());
obj = resultList.get(index++);
assertEquals(2, obj.getLeft());
assertEquals(3, obj.getRight());
assertEquals(1, obj.getVisibility());
assertEquals("231", obj.getProperties());
obj = resultList.get(index);
assertEquals(4, obj.getLeft());
assertEquals(1, obj.getRight());
assertEquals(1, obj.getVisibility());
assertEquals("142", obj.getProperties());
}
results.close();
}
use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.
the class ArrayListStoreTest method shouldAddAndGetRelatedEntities.
@Test
public void shouldAddAndGetRelatedEntities() throws OperationException {
final Graph graph = createGraph();
addElementsToGraph(graph);
//set up the operation to fetch the entities
final OperationChain<CloseableIterable<SimpleEntityDataObject>> opChain = new OperationChain.Builder().first(new GetEntities.Builder<>().addSeed(new EdgeSeed(2, 1, false)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Entity, SimpleEntityDataObject>().generator(new SimpleEntityGenerator()).build()).build();
//now do the hop
final CloseableIterable<SimpleEntityDataObject> results = graph.execute(opChain, new User());
//check the results by converting our edges back into SimpleDataObjects
if (!results.iterator().hasNext()) {
fail("No results returned");
} else {
for (final SimpleEntityDataObject obj : results) {
LOGGER.info(obj.toString());
}
final List<SimpleEntityDataObject> resultList = Lists.newArrayList(results);
int index = 0;
SimpleEntityDataObject obj = resultList.get(index++);
assertEquals(1, obj.getId());
assertEquals(1, obj.getVisibility());
assertEquals("Red", obj.getProperties());
obj = resultList.get(index);
assertEquals(2, obj.getId());
assertEquals(1, obj.getVisibility());
assertEquals("Orange", obj.getProperties());
}
results.close();
}
Aggregations