Search in sources :

Example 16 with CloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.

the class OperationChainTest method shouldBuildOperationChain.

@Test
public void shouldBuildOperationChain() {
    // Given
    final AddElements addElements = mock(AddElements.class);
    final GetElements getAdj1 = mock(GetElements.class);
    final GetElements getAdj2 = mock(GetElements.class);
    final GetElements<EntitySeed, Element> getRelElements = mock(GetElements.class);
    // When
    final OperationChain<CloseableIterable<Element>> opChain = new Builder().first(addElements).then(getAdj1).then(getAdj2).then(getRelElements).build();
    // Then
    assertArrayEquals(new Operation[] { addElements, getAdj1, getAdj2, getRelElements }, opChain.getOperationArray());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.Test)

Example 17 with CloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.

the class OperationChainTest method shouldReturnReadableStringForToString.

@Test
public void shouldReturnReadableStringForToString() {
    // Given
    final AddElements addElements = new AddElements();
    final GetAdjacentEntitySeeds getAdj1 = new GetAdjacentEntitySeeds();
    final GetAdjacentEntitySeeds getAdj2 = new GetAdjacentEntitySeeds();
    final GetElements<EntitySeed, Element> getRelElements = new GetElements<>();
    final OperationChain<CloseableIterable<Element>> opChain = new Builder().first(addElements).then(getAdj1).then(getAdj2).then(getRelElements).build();
    // When
    final String toString = opChain.toString();
    // Then
    final String expectedToString = "OperationChain[AddElements->GetAdjacentEntitySeeds->GetAdjacentEntitySeeds->GetElements]";
    assertEquals(expectedToString, toString);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.Test)

Example 18 with CloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable 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();
}
Also used : SimpleEntityGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEntityGenerator) User(uk.gov.gchq.gaffer.user.User) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) SimpleEntityDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject) Test(org.junit.Test)

Example 19 with CloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable 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();
}
Also used : User(uk.gov.gchq.gaffer.user.User) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) SimpleEdgeGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEdgeGenerator) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) SimpleEdgeDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject) Test(org.junit.Test)

Example 20 with CloseableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable in project Gaffer by gchq.

the class StoreTest method shouldHandleMultiStepOperations.

@Test
public void shouldHandleMultiStepOperations() throws Exception {
    // Given
    final Schema schema = createSchemaMock();
    final StoreProperties properties = mock(StoreProperties.class);
    final StoreImpl store = new StoreImpl();
    final CloseableIterable<Element> getElementsResult = mock(CloseableIterable.class);
    final AddElements addElements1 = new AddElements();
    final GetElements<ElementSeed, Element> getElements = new GetElements<>();
    final OperationChain<CloseableIterable<Element>> opChain = new OperationChain.Builder().first(addElements1).then(getElements).build();
    given(addElementsHandler.doOperation(addElements1, context, store)).willReturn(null);
    given(getElementsHandler.doOperation(getElements, context, store)).willReturn(getElementsResult);
    store.initialise(schema, properties);
    // When
    final CloseableIterable<Element> result = store.execute(opChain, user);
    // Then
    assertSame(getElementsResult, result);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Test(org.junit.Test)

Aggregations

CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)21 Test (org.junit.Test)16 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)11 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)11 User (uk.gov.gchq.gaffer.user.User)11 Graph (uk.gov.gchq.gaffer.graph.Graph)10 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)6 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)6 Element (uk.gov.gchq.gaffer.data.element.Element)5 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)5 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)5 GetEdges (uk.gov.gchq.gaffer.operation.impl.get.GetEdges)4 SimpleEntityDataObject (uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject)3 SimpleEntityGenerator (uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEntityGenerator)3 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)3 Builder (uk.gov.gchq.gaffer.operation.OperationChain.Builder)3 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)3 SimpleEdgeDataObject (uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject)2 SimpleEdgeGenerator (uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEdgeGenerator)2 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)2