use of uk.gov.gchq.gaffer.operation.impl.DiscardOutput in project Gaffer by gchq.
the class ValidateOperationChainHandlerTest method shouldValidateOperationChain.
@Test
public void shouldValidateOperationChain() throws OperationException {
// Given
final AddElements addElements = new AddElements();
final GetAdjacentIds getAdj = new GetAdjacentIds();
final GetElements getElements = new GetElements();
final DiscardOutput discardOutput = new DiscardOutput();
OperationChain chain = new OperationChain.Builder().first(addElements).then(getAdj).then(getElements).then(discardOutput).build();
ValidateOperationChain validateOperationChain = new ValidateOperationChain.Builder().operationChain(chain).build();
given(store.getOperationChainValidator()).willReturn(new OperationChainValidator(new ViewValidator()));
ValidateOperationChainHandler handler = new ValidateOperationChainHandler();
// When
ValidationResult result = handler.doOperation(validateOperationChain, context, store);
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.gaffer.operation.impl.DiscardOutput in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldFailQuietlyIfNestedOperationsCannotBeModified.
@Test
public void shouldFailQuietlyIfNestedOperationsCannotBeModified() throws SerialisationException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
Operation validate = new Validate();
Operation getAdjacentIds = new GetAdjacentIds();
Operation count = new Count<>();
Operation getElements = new GetElements();
Operation getAllElements = new GetAllElements();
TestUnmodifiableOperationsImpl nestedUnmodifiableOps = new TestUnmodifiableOperationsImpl(Arrays.asList(getAllElements, getElements));
final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(nestedUnmodifiableOps).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(validate).then(getAdjacentIds).then(count).then(discardOutput).then(nestedUnmodifiableOps).then(count).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.DiscardOutput in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldHandleIfOperationWithNoConditionalOrOtherwise.
@Test
public void shouldHandleIfOperationWithNoConditionalOrOtherwise() throws SerialisationException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
If ifOp = new If.Builder<>().then(new GetElements()).build();
final OperationChain opChain = new OperationChain.Builder().first(ifOp).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(new If.Builder<>().then(new OperationChain<>(new CountGroups(), new GetElements())).build()).then(new Count()).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.DiscardOutput in project Gaffer by gchq.
the class StoreTest method shouldRescheduleJobsCorrectlyWhenInitialisationCountIs.
private void shouldRescheduleJobsCorrectlyWhenInitialisationCountIs(final int initialisationCount) throws Exception {
// Given
final StoreProperties properties = mock(StoreProperties.class);
given(properties.getJobTrackerEnabled()).willReturn(true);
given(properties.getJobExecutorThreadCount()).willReturn(1);
final Repeat repeat = new Repeat(0, 100, TimeUnit.SECONDS);
final OperationChain opChain = new OperationChain.Builder().first(new DiscardOutput()).build();
final User user = new User.Builder().userId("testUser").opAuth("opAuth").dataAuth("dataAuth").build();
final JobDetail scheduledJobDetail = new JobDetail.Builder().jobId("jobId").user(user).opChain(opChain.toOverviewString()).serialisedOperationChain(opChain).repeat(repeat).build();
given(jobTracker.getAllScheduledJobs()).willReturn(new WrappedCloseableIterable(singletonList(scheduledJobDetail)));
StoreImpl2 store = new StoreImpl2();
// When - initialise store
for (int i = 0; i < initialisationCount; i++) {
store.initialise("graphId", schema, properties);
}
ScheduledExecutorService service = store.getExecutorService();
// Then - assert scheduled
final ArgumentCaptor<ScheduledJobRunnable> scheduledJobRunnableCaptor = ArgumentCaptor.forClass(ScheduledJobRunnable.class);
verify(service).scheduleAtFixedRate(scheduledJobRunnableCaptor.capture(), eq(repeat.getInitialDelay()), eq(repeat.getRepeatPeriod()), eq(repeat.getTimeUnit()));
assertEquals(scheduledJobDetail, scheduledJobRunnableCaptor.getValue().getJobDetail());
assertEquals(user, scheduledJobRunnableCaptor.getValue().getContext().getUser());
assertArrayEquals(JSONSerialiser.serialise(opChain), JSONSerialiser.serialise(scheduledJobRunnableCaptor.getValue().getOperationChain()));
}
use of uk.gov.gchq.gaffer.operation.impl.DiscardOutput in project Gaffer by gchq.
the class StoreTest method shouldCorrectlySetUpScheduledJobDetail.
@Test
public void shouldCorrectlySetUpScheduledJobDetail() throws Exception {
// Given
final StoreProperties properties = mock(StoreProperties.class);
given(properties.getJobTrackerEnabled()).willReturn(true);
given(properties.getJobExecutorThreadCount()).willReturn(1);
StoreImpl2 store = new StoreImpl2();
store.initialise("graphId", schema, properties);
final Repeat repeat = new Repeat(0, 100, TimeUnit.SECONDS);
final OperationChain opChain = new OperationChain.Builder().first(new DiscardOutput()).build();
final Context context = new Context(user);
final String operationChainOverviewString = opChain.toOverviewString();
final String serialisedOperationChain = new String(JSONSerialiser.serialise(opChain), Charset.forName(CommonConstants.UTF_8));
// When - setup job
JobDetail parentJobDetail = store.executeJob(new Job(repeat, opChain), context);
ScheduledExecutorService service = store.getExecutorService();
// Then - assert scheduled
verify(service).scheduleAtFixedRate(any(Runnable.class), eq(repeat.getInitialDelay()), eq(repeat.getRepeatPeriod()), eq(repeat.getTimeUnit()));
// Then - assert job detail is as expected
assertEquals(JobStatus.SCHEDULED_PARENT, parentJobDetail.getStatus());
assertEquals(operationChainOverviewString, parentJobDetail.getOpChain());
assertEquals(serialisedOperationChain, parentJobDetail.getSerialisedOperationChain());
assertEquals(context.getUser(), parentJobDetail.getUser());
}
Aggregations