use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.
the class JcsJobTrackerTest method shouldGetAllJobs.
@Test
public void shouldGetAllJobs() {
// Given
final User user = mock(User.class);
final OperationChain<?> opChain = mock(OperationChain.class);
given(opChain.toString()).willReturn("op chain to string");
final JobDetail job1 = new JobDetail("jobId1", "userId1", opChain, JobStatus.RUNNING, "description");
final JobDetail job2 = new JobDetail("jobId2", "userId2", opChain, JobStatus.RUNNING, "description");
// When
jobTracker.addOrUpdateJob(job1, user);
jobTracker.addOrUpdateJob(job2, user);
final List<JobDetail> jobDetails = Lists.newArrayList(jobTracker.getAllJobs(user));
// Then
final List<JobDetail> expectedJobDetails = Lists.newArrayList(job1, job2);
final Comparator<JobDetail> jobDetailComparator = (o1, o2) -> o1.hashCode() - o2.hashCode();
jobDetails.sort(jobDetailComparator);
expectedJobDetails.sort(jobDetailComparator);
assertEquals(expectedJobDetails, jobDetails);
}
use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.
the class AddNamedOperationHandlerTest method shouldNotAllowUpdateToNamedOperationIfItCausesRecursion.
@Test
public void shouldNotAllowUpdateToNamedOperationIfItCausesRecursion() throws OperationException {
String innocentOpName = "innocent";
OperationChain innocent = new OperationChain.Builder().first(new GetElements<>()).build();
addNamedOperation.setOperationName(innocentOpName);
addNamedOperation.setOperationChain(innocent);
handler.doOperation(addNamedOperation, context, store);
OperationChain parent = new OperationChain.Builder().first(new NamedOperation(innocentOpName, "call down to currently innocent named op")).build();
addNamedOperation.setOperationChain(parent);
addNamedOperation.setOperationName(OPERATION_NAME);
handler.doOperation(addNamedOperation, context, store);
OperationChain recursive = new OperationChain.Builder().first(new NamedOperation(OPERATION_NAME, "")).build();
addNamedOperation.setOperationName(innocentOpName);
addNamedOperation.setOperationChain(recursive);
addNamedOperation.setOverwriteFlag(true);
exception.expect(OperationException.class);
handler.doOperation(addNamedOperation, context, store);
}
use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.
the class AddNamedOperationHandlerTest method shouldNotAddNamedOperationIfItContainsAnOperationWhichReferencesTheParent.
@Test
public void shouldNotAddNamedOperationIfItContainsAnOperationWhichReferencesTheParent() throws CacheOperationFailedException, OperationException {
NamedOperation op = new NamedOperation("parent", "this is the parent which has not yet been created");
OperationChain opChain = new OperationChain.Builder().first(op).build();
ExtendedNamedOperation child = new ExtendedNamedOperation.Builder().operationChain(opChain).operationName(OPERATION_NAME).build();
handler.getCache().addNamedOperation(child, false, context.getUser());
OperationChain parentOpChain = new OperationChain.Builder().first(operation).build();
addNamedOperation.setOperationName("parent");
addNamedOperation.setOperationChain(parentOpChain);
exception.expect(OperationException.class);
handler.doOperation(addNamedOperation, context, store);
}
use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.
the class ArrayListStoreTest method shouldAddAndGetEdgesThenEntities.
@Test
public void shouldAddAndGetEdgesThenEntities() throws OperationException {
final Graph graph = createGraph();
addElementsToGraph(graph);
//set up the operation to fetch the entities
final OperationChain<CloseableIterable<SimpleEntityDataObject>> opChain = new OperationChain.Builder().first(new GetEdges.Builder<>().addSeed(new EntitySeed(1)).build()).then(new GenerateObjects.Builder<Edge, EntitySeed>().generator(new EntitySeedExtractor(IdentifierType.DESTINATION)).build()).then(new GetEntities.Builder().view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Entity, SimpleEntityDataObject>().generator(new SimpleEntityGenerator()).build()).build();
//now do the hop
final CloseableIterable<SimpleEntityDataObject> results = graph.execute(opChain, new User());
//check the results by converting our edges back into SimpleDataObjects
if (!results.iterator().hasNext()) {
fail("No results returned");
} else {
for (final SimpleEntityDataObject obj : results) {
LOGGER.info(obj.toString());
}
final List<SimpleEntityDataObject> resultList = Lists.newArrayList(results);
assertEquals(1, resultList.size());
assertEquals(1, resultList.get(0).getId());
assertEquals(1, resultList.get(0).getVisibility());
assertEquals("Red", resultList.get(0).getProperties());
}
results.close();
}
use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.
the class ArrayListStoreTest method shouldAddAndGetEdgesBySeed.
@Test
public void shouldAddAndGetEdgesBySeed() throws OperationException {
final Graph graph = createGraph();
addElementsToGraph(graph);
//set up the operation to fetch the edges
final OperationChain<CloseableIterable<SimpleEdgeDataObject>> opChain = new OperationChain.Builder().first(new GetEdges.Builder().addSeed(new EdgeSeed(2, 1, false)).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Edge, SimpleEdgeDataObject>().generator(new SimpleEdgeGenerator()).build()).build();
//now do the hop
final CloseableIterable<SimpleEdgeDataObject> results = graph.execute(opChain, new User());
//check the results by converting our edges back into SimpleDataObjects
if (!results.iterator().hasNext()) {
fail("No results returned");
} else {
for (final SimpleEdgeDataObject obj : results) {
LOGGER.info(obj.toString());
}
final List<SimpleEdgeDataObject> resultList = Lists.newArrayList(results);
assertEquals(1, resultList.size());
int index = 0;
SimpleEdgeDataObject obj = resultList.get(index);
assertEquals(1, obj.getLeft());
assertEquals(2, obj.getRight());
assertEquals(1, obj.getVisibility());
assertEquals("121", obj.getProperties());
}
results.close();
}
Aggregations