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();
}
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();
}
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();
}
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();
}
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());
}
Aggregations