use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport 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 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.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.operation.impl.export.resultcache.GetGafferResultCacheExport in project Gaffer by gchq.
the class GetGafferResultCacheExportHandlerTest method shouldHandleOperationByDelegatingToAnNewExporter.
@Test
public void shouldHandleOperationByDelegatingToAnNewExporter() throws OperationException {
// Given
final GetGafferResultCacheExport export = new GetGafferResultCacheExport.Builder().key("key").build();
final Context context = new Context();
final Store store = mock(Store.class);
final Long timeToLive = 10000L;
final String visibility = "visibility value";
final GetGafferResultCacheExportHandler handler = new GetGafferResultCacheExportHandler();
handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
handler.setTimeToLive(timeToLive);
handler.setVisibility(visibility);
final Store cacheStore = mock(Store.class);
TestStore.mockStore = cacheStore;
// When
final Object handlerResult = handler.doOperation(export, context, store);
// Then
assertThat((Iterable) handlerResult).isEmpty();
final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
verify(cacheStore).execute(opChain.capture(), Mockito.any());
assertThat(opChain.getValue().getOperations()).hasSize(1);
assertTrue(opChain.getValue().getOperations().get(0) instanceof GetElements);
final GafferResultCacheExporter exporter = context.getExporter(GafferResultCacheExporter.class);
assertNotNull(exporter);
}
use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport in project Gaffer by gchq.
the class GetGafferResultCacheExportTest method builderShouldCreatePopulatedOperation.
@Test
@Override
public void builderShouldCreatePopulatedOperation() {
// When
final String key = "key";
final GetGafferResultCacheExport op = new GetGafferResultCacheExport.Builder().key(key).build();
// Then
assertEquals(key, op.getKey());
}
use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport in project Gaffer by gchq.
the class ExportIT method shouldExportResultsToGafferCache.
@Test
public void shouldExportResultsToGafferCache() throws OperationException {
assumeThat(graph.isSupported(ExportToGafferResultCache.class)).as("Gaffer result cache has not been enabled for this store.").isTrue();
// Given
final View edgesView = new View.Builder().edge(TestGroups.EDGE).build();
final OperationChain<? extends Iterable<?>> exportOpChain = new Builder().first(new GetElements.Builder().input(new EntitySeed(SOURCE_DIR_0)).view(edgesView).build()).then(new ExportToGafferResultCache<>()).then(new GenerateObjects.Builder<EntityId>().generator(new EntityIdExtractor()).build()).then(new GetElements.Builder().view(edgesView).build()).then(new ExportToGafferResultCache<>()).then(new DiscardOutput()).then(new GetGafferResultCacheExport()).build();
// When
final Iterable<?> export = graph.execute(exportOpChain, getUser());
// Then
assertThat(Sets.newHashSet(export)).hasSize(2);
}
use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport in project Gaffer by gchq.
the class GetGafferResultCacheExportTest method shouldSerialiseAndDeserialiseOperation.
@Test
@Override
public void shouldSerialiseAndDeserialiseOperation() throws SerialisationException {
// Given
final String key = "key";
final GetGafferResultCacheExport op = new GetGafferResultCacheExport.Builder().key(key).build();
// When
byte[] json = serialiser.serialise(op, true);
final GetGafferResultCacheExport deserialisedOp = serialiser.deserialise(json, GetGafferResultCacheExport.class);
// Then
assertEquals(key, deserialisedOp.getKey());
}
Aggregations