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);
}
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;
}
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;
}
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());
}
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());
}
Aggregations