Search in sources :

Example 1 with Builder

use of uk.gov.gchq.gaffer.operation.OperationChain.Builder in project Gaffer by gchq.

the class CountGroupsIT method shouldCountGroupsOfElementsWhenMoreElementsThanLimit.

@Test
public void shouldCountGroupsOfElementsWhenMoreElementsThanLimit() throws OperationException, InterruptedException {
    // Given
    final User user = new User();
    final int limit = 5;
    final Entity entity = new Entity(TestGroups.ENTITY_2, VERTEX);
    entity.putProperty(TestPropertyNames.INT, 100);
    // When
    final GroupCounts counts = graph.execute(new Builder().first(new GetAllElements<>()).then(new CountGroups(limit)).build(), user);
    // Then
    int totalCount = (null != counts.getEntityGroups().get(TestGroups.ENTITY) ? counts.getEntityGroups().get(TestGroups.ENTITY) : 0);
    totalCount += (null != counts.getEdgeGroups().get(TestGroups.EDGE) ? counts.getEdgeGroups().get(TestGroups.EDGE) : 0);
    assertEquals(limit, totalCount);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Example 2 with Builder

use of uk.gov.gchq.gaffer.operation.OperationChain.Builder in project Gaffer by gchq.

the class ExportIT method shouldExportResultsInSet.

@Test
public void shouldExportResultsInSet() throws OperationException, IOException {
    // Given
    final OperationChain<CloseableIterable<?>> exportOpChain = new Builder().first(new GetEdges.Builder<>().addSeed(new EntitySeed(SOURCE_DIR_0)).build()).then(new ExportToSet()).then(new GenerateObjects.Builder<Edge, EntitySeed>().generator(new EntitySeedExtractor()).build()).then(new GetEdges<>()).then(new ExportToSet()).then(new GetSetExport()).build();
    // When
    final CloseableIterable<?> export = graph.execute(exportOpChain, getUser());
    // Then
    assertEquals(2, Lists.newArrayList(export).size());
}
Also used : ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetSetExport(uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 3 with Builder

use of uk.gov.gchq.gaffer.operation.OperationChain.Builder 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 4 with Builder

use of uk.gov.gchq.gaffer.operation.OperationChain.Builder in project Gaffer by gchq.

the class OperationChainTest method shouldSerialiseAndDeserialiseOperationChain.

@Test
public void shouldSerialiseAndDeserialiseOperationChain() throws SerialisationException {
    // Given
    final OperationChain<Object> opChain = new Builder().first(new OperationImpl<>()).then(new OperationImpl<>()).build();
    // When
    byte[] json = serialiser.serialise(opChain, true);
    final OperationChain deserialisedOp = serialiser.deserialise(json, OperationChain.class);
    // Then
    assertNotNull(deserialisedOp);
    assertEquals(2, deserialisedOp.getOperations().size());
    assertEquals(OperationImpl.class, deserialisedOp.getOperations().get(0).getClass());
    assertEquals(OperationImpl.class, deserialisedOp.getOperations().get(1).getClass());
}
Also used : OperationImpl(uk.gov.gchq.gaffer.operation.impl.OperationImpl) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) Test(org.junit.Test)

Example 5 with Builder

use of uk.gov.gchq.gaffer.operation.OperationChain.Builder 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)

Aggregations

Test (org.junit.Test)7 Builder (uk.gov.gchq.gaffer.operation.OperationChain.Builder)7 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)3 GroupCounts (uk.gov.gchq.gaffer.data.GroupCounts)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)3 CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)3 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)3 User (uk.gov.gchq.gaffer.user.User)3 Element (uk.gov.gchq.gaffer.data.element.Element)2 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)2 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)2 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 EntitySeedExtractor (uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor)1 OperationImpl (uk.gov.gchq.gaffer.operation.impl.OperationImpl)1 ExportToSet (uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet)1 GetSetExport (uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport)1 GenerateObjects (uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects)1 GetAdjacentEntitySeeds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds)1 GetEdges (uk.gov.gchq.gaffer.operation.impl.get.GetEdges)1