Search in sources :

Example 16 with CountGroups

use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.

the class CountGroupsHandlerTest method shouldReturnGroupCountsWithoutLimit.

@Test
public void shouldReturnGroupCountsWithoutLimit() throws OperationException, IOException {
    // Given
    final CountGroupsHandler handler = new CountGroupsHandler();
    final Store store = mock(Store.class);
    final CountGroups countGroups = mock(CountGroups.class);
    final CloseableIterable elements = getElements();
    final Context context = new Context();
    given(countGroups.getLimit()).willReturn(null);
    given(countGroups.getInput()).willReturn(elements);
    // When
    final GroupCounts counts = handler.doOperation(countGroups, context, store);
    // Then
    assertFalse(counts.isLimitHit());
    assertEquals(2, counts.getEntityGroups().size());
    assertEquals(3, (int) counts.getEntityGroups().get(GROUP1));
    assertEquals(1, (int) counts.getEntityGroups().get(GROUP2));
    assertEquals(2, counts.getEdgeGroups().size());
    assertEquals(1, (int) counts.getEdgeGroups().get(GROUP1));
    assertEquals(3, (int) counts.getEdgeGroups().get(GROUP2));
    verify(countGroups).close();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Store(uk.gov.gchq.gaffer.store.Store) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.jupiter.api.Test)

Example 17 with CountGroups

use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.

the class CountGroupsHandlerTest method shouldReturnAllGroupCountsWhenLessThanLimit.

@Test
public void shouldReturnAllGroupCountsWhenLessThanLimit() throws OperationException, IOException {
    // Given
    final CountGroupsHandler handler = new CountGroupsHandler();
    final Store store = mock(Store.class);
    final CountGroups countGroups = mock(CountGroups.class);
    final CloseableIterable elements = getElements();
    final Integer limit = 10;
    final Context context = new Context();
    given(countGroups.getLimit()).willReturn(limit);
    given(countGroups.getInput()).willReturn(elements);
    // When
    final GroupCounts counts = handler.doOperation(countGroups, context, store);
    // Then
    assertFalse(counts.isLimitHit());
    assertEquals(2, counts.getEntityGroups().size());
    assertEquals(3, (int) counts.getEntityGroups().get(GROUP1));
    assertEquals(1, (int) counts.getEntityGroups().get(GROUP2));
    assertEquals(2, counts.getEdgeGroups().size());
    assertEquals(1, (int) counts.getEdgeGroups().get(GROUP1));
    assertEquals(3, (int) counts.getEdgeGroups().get(GROUP2));
    verify(countGroups).close();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Store(uk.gov.gchq.gaffer.store.Store) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.jupiter.api.Test)

Example 18 with CountGroups

use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.

the class CountGroupsIT method shouldCountGroupsOfElementsWhenLessElementsThanLimit.

@Test
public void shouldCountGroupsOfElementsWhenLessElementsThanLimit() throws OperationException {
    // Given
    final User user = new User();
    final Integer limit = getEntities().size() + getEdges().size() + 1;
    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
    assertThat(counts.getEntityGroups()).hasSize(1);
    assertThat((int) counts.getEntityGroups().get(TestGroups.ENTITY)).isEqualTo(getEntities().size());
    assertThat(counts.getEdgeGroups()).hasSize(1);
    assertThat((int) counts.getEdgeGroups().get(TestGroups.EDGE)).isEqualTo(getEdges().size());
    assertThat(counts.isLimitHit()).isFalse();
}
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 19 with CountGroups

use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.

the class CountGroupsIT method shouldCountGroupsOfElements.

@Test
public void shouldCountGroupsOfElements() throws OperationException {
    // Given
    final User user = new User();
    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()).build(), user);
    // Then
    assertThat(counts.getEntityGroups()).hasSize(1);
    assertThat((int) counts.getEntityGroups().get(TestGroups.ENTITY)).isEqualTo(getEntities().size());
    assertThat(counts.getEdgeGroups()).hasSize(1);
    assertThat((int) counts.getEdgeGroups().get(TestGroups.EDGE)).isEqualTo(getEdges().size());
    assertThat(counts.isLimitHit()).isFalse();
}
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 20 with CountGroups

use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.

the class OperationChainTest method shouldBuildOperationChain.

@Test
public void shouldBuildOperationChain() {
    // Given
    final AddElements addElements1 = mock(AddElements.class);
    final AddElements addElements2 = mock(AddElements.class);
    final GetAdjacentIds getAdj1 = mock(GetAdjacentIds.class);
    final GetAdjacentIds getAdj2 = mock(GetAdjacentIds.class);
    final GetAdjacentIds getAdj3 = mock(GetAdjacentIds.class);
    final GetElements getElements1 = mock(GetElements.class);
    final GetElements getElements2 = mock(GetElements.class);
    final GetAllElements getAllElements = mock(GetAllElements.class);
    final DiscardOutput discardOutput = mock(DiscardOutput.class);
    final GetJobDetails getJobDetails = mock(GetJobDetails.class);
    final GenerateObjects<EntityId> generateEntitySeeds = mock(GenerateObjects.class);
    final Limit<Element> limit = mock(Limit.class);
    final ToSet<Element> deduplicate = mock(ToSet.class);
    final CountGroups countGroups = mock(CountGroups.class);
    final ExportToSet<GroupCounts> exportToSet = mock(ExportToSet.class);
    final ExportToGafferResultCache<CloseableIterable<? extends Element>> exportToGafferCache = mock(ExportToGafferResultCache.class);
    final If<Iterable<? extends EntityId>, Iterable<? extends EntityId>> ifOp = mock(If.class);
    // When
    final OperationChain<JobDetail> opChain = new Builder().first(addElements1).then(getAdj1).then(getAdj2).then(getElements1).then(generateEntitySeeds).then(getAdj3).then(ifOp).then(getElements2).then(deduplicate).then(limit).then(countGroups).then(exportToSet).then(discardOutput).then(getAllElements).then(exportToGafferCache).then(addElements2).then(getJobDetails).build();
    // Then
    final Operation[] expecteds = { addElements1, getAdj1, getAdj2, getElements1, generateEntitySeeds, getAdj3, ifOp, getElements2, deduplicate, limit, countGroups, exportToSet, discardOutput, getAllElements, exportToGafferCache, addElements2, getJobDetails };
    assertArrayEquals(expecteds, opChain.getOperationArray());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.jupiter.api.Test)

Aggregations

CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)21 GroupCounts (uk.gov.gchq.gaffer.data.GroupCounts)16 Context (uk.gov.gchq.gaffer.store.Context)13 Test (org.junit.jupiter.api.Test)12 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)12 Test (org.junit.Test)9 Store (uk.gov.gchq.gaffer.store.Store)8 User (uk.gov.gchq.gaffer.user.User)8 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)6 Operation (uk.gov.gchq.gaffer.operation.Operation)5 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)5 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)5 SplitStoreFromFile (uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile)5 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)5 Response (javax.ws.rs.core.Response)4 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)4 Element (uk.gov.gchq.gaffer.data.element.Element)4 Builder (uk.gov.gchq.gaffer.operation.OperationChain.Builder)4 Count (uk.gov.gchq.gaffer.operation.impl.Count)4 Validate (uk.gov.gchq.gaffer.operation.impl.Validate)4