use of uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter in project Gaffer by gchq.
the class GafferResultCacheExporterTest method shouldGetResults.
@Test
public void shouldGetResults() throws OperationException, SerialisationException {
// Given
final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
long timestamp = System.currentTimeMillis();
final List<Element> cachedEdges = createCachedEdges(timestamp, serialisedResults);
given(store.execute(opChain.capture(), Mockito.eq(user))).willReturn(new WrappedCloseableIterable<>(cachedEdges));
final GafferResultCacheExporter exporter = new GafferResultCacheExporter(user, jobId, resultCache, SERIALISER, visibility, requiredOpAuths);
// When
final CloseableIterable<?> cachedResults = exporter.get(key);
// Then
assertEquals(results, Lists.newArrayList(cachedResults));
}
use of uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter in project Gaffer by gchq.
the class GafferResultCacheExporterTest method shouldAddNotErrorWhenAddingANullResult.
@Test
public void shouldAddNotErrorWhenAddingANullResult() throws OperationException, SerialisationException {
// Given
final GafferResultCacheExporter exporter = new GafferResultCacheExporter(user, jobId, resultCache, SERIALISER, visibility, requiredOpAuths);
// When
exporter.add(key, null);
// Then
verify(store, never()).execute(Mockito.any(OperationChain.class), Mockito.eq(user));
}
use of uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter in project Gaffer by gchq.
the class GafferResultCacheExporterTest method shouldAddResults.
@Test
public void shouldAddResults() throws OperationException, SerialisationException {
// Given
final GafferResultCacheExporter exporter = new GafferResultCacheExporter(user, jobId, resultCache, SERIALISER, visibility, requiredOpAuths);
// When
exporter.add(key, results);
// Then
final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
verify(store).execute(opChain.capture(), Mockito.eq(user));
assertEquals(1, opChain.getValue().getOperations().size());
final AddElements addElements = (AddElements) opChain.getValue().getOperations().get(0);
final List<Element> elements = Lists.newArrayList(addElements.getElements());
final Object timestamp = elements.get(0).getProperty("timestamp");
final List<Element> expectedElements = createCachedEdges(timestamp, elements.get(0).getProperty("result"), elements.get(1).getProperty("result"), null);
assertEquals(expectedElements, elements);
for (int i = 0; i < elements.size(); i++) {
if (null == results.get(i)) {
assertNull(elements.get(i).getProperty("result"));
} else {
assertArrayEquals(SERIALISER.serialise(results.get(i)), (byte[]) elements.get(i).getProperty("result"));
}
}
}
Aggregations