use of uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints in project Gaffer by gchq.
the class SampleElementsForSplitPointsHandlerTest method shouldCalculateRequiredNumberOfSplitsFromEdges.
@Test
public void shouldCalculateRequiredNumberOfSplitsFromEdges() throws OperationException {
// Given
final int numSplits = 3;
final List<Element> elements = IntStream.range(0, numSplits * 10).mapToObj(i -> new Edge(TestGroups.EDGE, "source_" + i, "dest_" + i, true)).collect(Collectors.toList());
final AbstractSampleElementsForSplitPointsHandler<String, AccumuloStore> handler = createHandler();
final SampleElementsForSplitPoints<String> operation = new SampleElementsForSplitPoints.Builder<String>().input(elements).numSplits(numSplits).build();
// When
createHandler().doOperation(operation, new Context(), store);
// Then
final ArgumentCaptor<GenerateSplitPointsFromSample> generateSplitPointsFromSampleCaptor = ArgumentCaptor.forClass(GenerateSplitPointsFromSample.class);
verify(store).execute(generateSplitPointsFromSampleCaptor.capture(), any(Context.class));
final int expectedElementCount = elements.size() * 2;
assertExpectedNumberOfSplitPointsAndSampleSize(generateSplitPointsFromSampleCaptor, numSplits, expectedElementCount);
}
use of uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints in project Gaffer by gchq.
the class AbstractSampleElementsForSplitPointsHandlerTest method shouldUseFullSampleOfAllElementsByDefault.
@Test
public void shouldUseFullSampleOfAllElementsByDefault() throws OperationException {
// Given
final int numSplits = 3;
final List<Element> elements = IntStream.range(0, numSplits).mapToObj(i -> new Entity(TestGroups.ENTITY, "vertex_" + i)).collect(Collectors.toList());
final AbstractSampleElementsForSplitPointsHandler<?, S> handler = createHandler();
final SampleElementsForSplitPoints operation = new SampleElementsForSplitPoints.Builder<>().input(elements).numSplits(numSplits).build();
final S store = createStore();
// When
handler.doOperation(operation, new Context(), store);
// Then
final ArgumentCaptor<GenerateSplitPointsFromSample> generateSplitPointsFromSampleCaptor = ArgumentCaptor.forClass(GenerateSplitPointsFromSample.class);
verify(store).execute(generateSplitPointsFromSampleCaptor.capture(), any(Context.class));
assertExpectedNumberOfSplitPointsAndSampleSize(generateSplitPointsFromSampleCaptor, numSplits, elements.size());
}
use of uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints in project Gaffer by gchq.
the class AbstractSampleElementsForSplitPointsHandlerTest method shouldThrowExceptionForNullInput.
@Test
public void shouldThrowExceptionForNullInput() throws OperationException {
// Given
final AbstractSampleElementsForSplitPointsHandler<?, S> handler = createHandler();
final SampleElementsForSplitPoints operation = new SampleElementsForSplitPoints.Builder<>().numSplits(1).build();
// When / Then
assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(operation, new Context(), createStore())).withMessageContaining("input is required");
}
use of uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints in project Gaffer by gchq.
the class AbstractSampleElementsForSplitPointsHandlerTest method shouldFilterOutNulls.
@Test
public void shouldFilterOutNulls() throws OperationException {
// Given
final int numSplits = 3;
final List<Element> elements = IntStream.range(0, numSplits).mapToObj(i -> new Entity(TestGroups.ENTITY, "vertex_" + i)).collect(Collectors.toList());
final List<Element> elementsWithNulls = new ArrayList<>();
elementsWithNulls.add(null);
elementsWithNulls.addAll(elements);
elementsWithNulls.add(null);
final AbstractSampleElementsForSplitPointsHandler<?, S> handler = createHandler();
final SampleElementsForSplitPoints operation = new SampleElementsForSplitPoints.Builder<>().input(elementsWithNulls).numSplits(numSplits).build();
final S store = createStore();
// When
handler.doOperation(operation, new Context(), store);
// Then
final ArgumentCaptor<GenerateSplitPointsFromSample> generateSplitPointsFromSampleCaptor = ArgumentCaptor.forClass(GenerateSplitPointsFromSample.class);
verify(store).execute(generateSplitPointsFromSampleCaptor.capture(), any(Context.class));
assertExpectedNumberOfSplitPointsAndSampleSize(generateSplitPointsFromSampleCaptor, numSplits, elements.size());
}
use of uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints in project Gaffer by gchq.
the class AbstractSampleElementsForSplitPointsHandlerTest method shouldNotThrowExceptionIfNumberOfSampledElementsIsLessThanMaxAllowed.
@Test
public void shouldNotThrowExceptionIfNumberOfSampledElementsIsLessThanMaxAllowed() throws OperationException {
// Given
int maxSampledElements = 5;
final AbstractSampleElementsForSplitPointsHandler<?, ?> handler = createHandler();
handler.setMaxSampledElements(maxSampledElements);
final List<Element> elements = IntStream.range(0, 5).mapToObj(i -> new Entity(TestGroups.ENTITY, "vertex_" + i)).collect(Collectors.toList());
elements.add(null);
final SampleElementsForSplitPoints operation = new SampleElementsForSplitPoints.Builder<>().input(elements).numSplits(3).build();
// When
handler.doOperation(operation, new Context(), createStore());
// Then - no exception
}
Aggregations