use of uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample in project Gaffer by gchq.
the class AbstractSampleElementsForSplitPointsHandlerTest method shouldSampleApproximatelyHalfOfElements.
@Test
public void shouldSampleApproximatelyHalfOfElements() throws OperationException {
// Given
final int numSplits = 3;
final List<Element> elements = IntStream.range(0, 1000 * 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).proportionToSample(0.5f).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));
final int maximumExpectedSampleSize = (int) ((elements.size() / 2) * 1.1);
assertExpectedNumberOfSplitPointsAndSampleSizeOfNoMoreThan(generateSplitPointsFromSampleCaptor, numSplits, maximumExpectedSampleSize);
}
use of uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample in project Gaffer by gchq.
the class AbstractGenerateSplitPointsFromSampleHandlerTest method shouldThrowExceptionForNullInput.
@Test
public void shouldThrowExceptionForNullInput() throws OperationException {
// Given
final AbstractGenerateSplitPointsFromSampleHandler<?, S> handler = createHandler();
final GenerateSplitPointsFromSample operation = new GenerateSplitPointsFromSample.Builder<>().numSplits(1).build();
assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(operation, new Context(), createStore())).withMessageContaining("input is required");
}
use of uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample in project Gaffer by gchq.
the class AbstractGenerateSplitPointsFromSampleHandlerTest method verifySplits.
protected void verifySplits(final List<Integer> indexes, final List<String> sample, final List<?> splits, final AbstractGenerateSplitPointsFromSampleHandler<?, S> handler) throws OperationException {
final GenerateSplitPointsFromSample operatation = new GenerateSplitPointsFromSample.Builder<>().input(sample).numSplits(Integer.MAX_VALUE).build();
final List<?> allElementsAsSplits = handler.doOperation(operatation, new Context(), createStore());
final List<Object> expectedSplits = new ArrayList<>(indexes.size());
for (final Integer index : indexes) {
expectedSplits.add(allElementsAsSplits.get(index));
}
assertEquals(expectedSplits, splits);
}
use of uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample in project Gaffer by gchq.
the class AbstractGenerateSplitPointsFromSampleHandlerTest method shouldCalculateRequiredNumberOfSplits.
@Test
public void shouldCalculateRequiredNumberOfSplits() throws OperationException {
// Given
final int numSplits = 3;
final List<String> sample = createSampleOfSize(numSplits * 10);
final AbstractGenerateSplitPointsFromSampleHandler<?, S> handler = createHandler();
final GenerateSplitPointsFromSample operation = new GenerateSplitPointsFromSample.Builder<>().input(sample).numSplits(numSplits).build();
// When
final List<?> splits = handler.doOperation(operation, new Context(), createStore());
// Then
verifySplits(Arrays.asList(6, 14, 21), sample, splits, handler);
}
use of uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample in project Gaffer by gchq.
the class AbstractGenerateSplitPointsFromSampleHandlerTest method shouldDeduplicateElements.
@Test
public void shouldDeduplicateElements() throws OperationException {
// Given
final int numSplits = 3;
final List<String> sample = Collections.nCopies(numSplits * 10, "key1");
final AbstractGenerateSplitPointsFromSampleHandler<?, S> handler = createHandler();
final GenerateSplitPointsFromSample operation = new GenerateSplitPointsFromSample.Builder<>().input(sample).numSplits(numSplits).build();
final S store = createStore();
// When
final List<?> splits = handler.doOperation(operation, new Context(), createStore());
// Then
assertThat(splits).hasSize(1);
verifySplits(Collections.singletonList(0), sample, splits, handler);
}
Aggregations