use of uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter in project Gaffer by gchq.
the class ExportToGafferResultCacheHandlerTest method shouldHandleOperationByDelegatingToAnNewExporter.
@Test
public void shouldHandleOperationByDelegatingToAnNewExporter() throws OperationException {
// Given
final List<?> results = Arrays.asList(1, 2, 3);
final ExportToGafferResultCache export = new ExportToGafferResultCache.Builder().key("key").input(results).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 ExportToGafferResultCacheHandler handler = new ExportToGafferResultCacheHandler();
handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
handler.setJsonSerialiser(jsonSerialiser);
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
assertSame(handlerResult, results);
final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
verify(cacheStore).execute(opChain.capture(), Mockito.eq(context.getUser()));
assertEquals(1, opChain.getValue().getOperations().size());
assertTrue(opChain.getValue().getOperations().get(0) instanceof AddElements);
final GafferResultCacheExporter exporter = context.getExporter(GafferResultCacheExporter.class);
assertNotNull(exporter);
}
use of uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter in project Gaffer by gchq.
the class GafferResultCacheExporterTest method shouldGetEmptyResults.
@Test
public void shouldGetEmptyResults() throws OperationException, SerialisationException {
// Given
final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
given(store.execute(opChain.capture(), Mockito.eq(user))).willReturn(null);
final GafferResultCacheExporter exporter = new GafferResultCacheExporter(user, jobId, resultCache, SERIALISER, visibility, requiredOpAuths);
// When
final CloseableIterable<?> cachedResults = exporter.get(key);
// Then
assertEquals(Collections.emptyList(), Lists.newArrayList(cachedResults));
}
use of uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter 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.operation.export.resultcache.GafferResultCacheExporter 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 JSONSerialiser jsonSerialiser = mock(JSONSerialiser.class);
final Long timeToLive = 10000L;
final String visibility = "visibility value";
final GetGafferResultCacheExportHandler handler = new GetGafferResultCacheExportHandler();
handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
handler.setJsonSerialiser(jsonSerialiser);
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
assertEquals(0, Iterables.size((Iterable) handlerResult));
final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
verify(cacheStore).execute(opChain.capture(), Mockito.eq(context.getUser()));
assertEquals(1, opChain.getValue().getOperations().size());
assertTrue(opChain.getValue().getOperations().get(0) instanceof GetEdges);
final GafferResultCacheExporter exporter = context.getExporter(GafferResultCacheExporter.class);
assertNotNull(exporter);
}
use of uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter in project Gaffer by gchq.
the class ExportToGafferResultCacheHandlerTest method shouldHandleOperationByDelegatingToAnExistingExporter.
@Test
public void shouldHandleOperationByDelegatingToAnExistingExporter() throws OperationException {
// Given
final List<?> results = Arrays.asList(1, 2, 3);
final ExportToGafferResultCache export = new ExportToGafferResultCache.Builder().key("key").input(results).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);
context.addExporter(exporter);
final ExportToGafferResultCacheHandler handler = new ExportToGafferResultCacheHandler();
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).add("key", results);
assertSame(handlerResult, results);
}
Aggregations