Search in sources :

Example 1 with ExportToGafferResultCache

use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache 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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) Test(org.junit.Test)

Example 2 with ExportToGafferResultCache

use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache in project Gaffer by gchq.

the class ExportToGafferResultCacheExample method exportAndGetJobDetails.

public JobDetail exportAndGetJobDetails() {
    // ---------------------------------------------------------
    final OperationChain<JobDetail> exportOpChain = new OperationChain.Builder().first(new GetAllEdges()).then(new ExportToGafferResultCache()).then(new GetJobDetails()).build();
    // ---------------------------------------------------------
    jobDetail = runExample(exportOpChain);
    return jobDetail;
}
Also used : GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)

Example 3 with ExportToGafferResultCache

use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache in project Gaffer by gchq.

the class GetGafferResultCacheExportExample method exportAndGetJobDetails.

public JobDetail exportAndGetJobDetails() {
    // ---------------------------------------------------------
    final OperationChain<JobDetail> exportOpChain = new OperationChain.Builder().first(new GetAllEdges()).then(new ExportToGafferResultCache()).then(new GetJobDetails()).build();
    // ---------------------------------------------------------
    jobDetail = runExample(exportOpChain);
    return jobDetail;
}
Also used : GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)

Example 4 with ExportToGafferResultCache

use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache in project Gaffer by gchq.

the class StoreTest method shouldExecuteOperationChainJob.

@Test
public void shouldExecuteOperationChainJob() throws OperationException, ExecutionException, InterruptedException, StoreException {
    // Given
    final Operation<?, ?> operation = mock(Operation.class);
    final OperationChain<?> opChain = new OperationChain.Builder().first(operation).then(new ExportToGafferResultCache()).build();
    final StoreProperties properties = mock(StoreProperties.class);
    given(properties.getJobTrackerClass()).willReturn("jobTrackerClass");
    final Store store = new StoreImpl();
    final Schema schema = new Schema();
    store.initialise(schema, properties);
    // When
    final JobDetail resultJobDetail = store.executeJob(opChain, user);
    // Then
    Thread.sleep(1000);
    final ArgumentCaptor<JobDetail> jobDetail = ArgumentCaptor.forClass(JobDetail.class);
    verify(jobTracker, times(2)).addOrUpdateJob(jobDetail.capture(), Mockito.eq(user));
    assertEquals(jobDetail.getAllValues().get(0), resultJobDetail);
    assertEquals(JobStatus.FINISHED, jobDetail.getAllValues().get(1).getStatus());
    final ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
    verify(exportToGafferResultCacheHandler).doOperation(Mockito.any(ExportToGafferResultCache.class), contextCaptor.capture(), Mockito.eq(store));
    assertSame(user, contextCaptor.getValue().getUser());
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) Test(org.junit.Test)

Example 5 with ExportToGafferResultCache

use of uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache in project Gaffer by gchq.

the class ExportToGafferResultCacheTest method shouldSerialiseAndDeserialiseOperation.

@Test
@Override
public void shouldSerialiseAndDeserialiseOperation() throws SerialisationException {
    // Given
    final String key = "key";
    final HashSet<String> opAuths = Sets.newHashSet("1", "2");
    final ExportToGafferResultCache op = new ExportToGafferResultCache.Builder().opAuths(opAuths).key(key).build();
    // When
    byte[] json = serialiser.serialise(op, true);
    final ExportToGafferResultCache deserialisedOp = serialiser.deserialise(json, ExportToGafferResultCache.class);
    // Then
    assertEquals(key, deserialisedOp.getKey());
    assertEquals(opAuths, deserialisedOp.getOpAuths());
}
Also used : ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.Test)

Aggregations

ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)9 Test (org.junit.Test)5 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)5 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)3 GetJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails)3 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)2 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)2 GafferResultCacheExporter (uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter)2 Context (uk.gov.gchq.gaffer.store.Context)2 Store (uk.gov.gchq.gaffer.store.Store)2 Operation (uk.gov.gchq.gaffer.operation.Operation)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 Schema (uk.gov.gchq.gaffer.store.schema.Schema)1 User (uk.gov.gchq.gaffer.user.User)1