Search in sources :

Example 1 with GetGafferResultCacheExport

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetGafferResultCacheExport(uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.jupiter.api.Test)

Example 2 with GetGafferResultCacheExport

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetGafferResultCacheExport(uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.jupiter.api.Test)

Example 3 with GetGafferResultCacheExport

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());
}
Also used : GetGafferResultCacheExport(uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 4 with GetGafferResultCacheExport

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);
}
Also used : EntityIdExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntityIdExtractor) GetGafferResultCacheExport(uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 5 with GetGafferResultCacheExport

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

Aggregations

GetGafferResultCacheExport (uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport)7 Test (org.junit.jupiter.api.Test)5 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)4 Test (org.junit.Test)2 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)2 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)2 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)2 GafferResultCacheExporter (uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter)2 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)2 Context (uk.gov.gchq.gaffer.store.Context)2 Store (uk.gov.gchq.gaffer.store.Store)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 Builder (uk.gov.gchq.gaffer.operation.OperationChain.Builder)1 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)1 EntityIdExtractor (uk.gov.gchq.gaffer.operation.data.generator.EntityIdExtractor)1 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)1 ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)1