Search in sources :

Example 6 with GafferResultCacheExporter

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));
}
Also used : GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Element(uk.gov.gchq.gaffer.data.element.Element) Test(org.junit.Test)

Example 7 with GafferResultCacheExporter

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));
}
Also used : GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.Test)

Example 8 with GafferResultCacheExporter

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"));
        }
    }
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Element(uk.gov.gchq.gaffer.data.element.Element) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 GafferResultCacheExporter (uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter)8 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)6 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)4 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)4 Context (uk.gov.gchq.gaffer.store.Context)4 Store (uk.gov.gchq.gaffer.store.Store)4 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)2 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)2 ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)2 GetGafferResultCacheExport (uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport)2 GetEdges (uk.gov.gchq.gaffer.operation.impl.get.GetEdges)1