Search in sources :

Example 16 with DiscardOutput

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());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 17 with DiscardOutput

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));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) Count(uk.gov.gchq.gaffer.operation.impl.Count) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) TestUnmodifiableOperationsImpl(uk.gov.gchq.gaffer.operation.TestUnmodifiableOperationsImpl) Test(org.junit.jupiter.api.Test)

Example 18 with DiscardOutput

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));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) Count(uk.gov.gchq.gaffer.operation.impl.Count) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 19 with DiscardOutput

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()));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) User(uk.gov.gchq.gaffer.user.User) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Repeat(uk.gov.gchq.gaffer.jobtracker.Repeat) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) ScheduledJobRunnable(uk.gov.gchq.gaffer.store.Store.ScheduledJobRunnable) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput)

Example 20 with DiscardOutput

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());
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ScheduledJobRunnable(uk.gov.gchq.gaffer.store.Store.ScheduledJobRunnable) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) Repeat(uk.gov.gchq.gaffer.jobtracker.Repeat) Job(uk.gov.gchq.gaffer.jobtracker.Job) CancelScheduledJob(uk.gov.gchq.gaffer.operation.impl.job.CancelScheduledJob) Test(org.junit.jupiter.api.Test)

Aggregations

DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)24 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)17 Test (org.junit.jupiter.api.Test)16 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)15 User (uk.gov.gchq.gaffer.user.User)12 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)11 Context (uk.gov.gchq.gaffer.store.Context)10 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)8 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)7 Operation (uk.gov.gchq.gaffer.operation.Operation)7 SplitStoreFromFile (uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile)7 Count (uk.gov.gchq.gaffer.operation.impl.Count)6 CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)5 GetJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails)5 Builder (uk.gov.gchq.gaffer.operation.OperationChain.Builder)4 Validate (uk.gov.gchq.gaffer.operation.impl.Validate)4 ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)3 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)3 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)3