use of uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints 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.SampleElementsForSplitPoints in project Gaffer by gchq.
the class AbstractSampleElementsForSplitPointsHandlerTest method shouldThrowExceptionIfNumberOfSampledElementsIsMoreThanMaxAllowed.
@Test
public void shouldThrowExceptionIfNumberOfSampledElementsIsMoreThanMaxAllowed() throws OperationException {
// Given
int maxSampledElements = 5;
final AbstractSampleElementsForSplitPointsHandler<?, ?> handler = createHandler();
handler.setMaxSampledElements(maxSampledElements);
final List<Element> elements = IntStream.range(0, 6).mapToObj(i -> new Entity(TestGroups.ENTITY, "vertex_" + i)).collect(Collectors.toList());
final SampleElementsForSplitPoints operation = new SampleElementsForSplitPoints.Builder<>().input(elements).numSplits(3).build();
// When / Then
try {
handler.doOperation(operation, new Context(), createStore());
fail("Exception expected");
} catch (final LimitExceededException e) {
assertTrue(e.getMessage().equals("Limit of " + maxSampledElements + " exceeded."), e.getMessage());
}
}
use of uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints in project Gaffer by gchq.
the class SampleElementsForSplitPointsHandlerTest method shouldUseTheNumberOfTabletServersToCalculateNumSplits.
@Test
public void shouldUseTheNumberOfTabletServersToCalculateNumSplits() throws OperationException {
// Given
final Integer numSplits = null;
final List<Element> elements = IntStream.range(0, 30).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 expectedNumOfSplits = NUM_TABLET_SERVERS - 1;
final int expectedElementCount = elements.size() * 2;
assertExpectedNumberOfSplitPointsAndSampleSize(generateSplitPointsFromSampleCaptor, expectedNumOfSplits, expectedElementCount);
}
use of uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints in project Gaffer by gchq.
the class SampleElementsForSplitPointsHandlerTest method shouldUseTheNumberOfRegionsToCalculateNumSplits.
@Test
public void shouldUseTheNumberOfRegionsToCalculateNumSplits() throws OperationException {
// Given
final Integer numSplits = null;
final List<Element> elements = IntStream.range(0, 30).mapToObj(i -> new Edge(TestGroups.EDGE, "source_" + i, "dest_" + i, true)).collect(Collectors.toList());
final AbstractSampleElementsForSplitPointsHandler<String, HBaseStore> 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 expectedNumOfSplits = NUM_TABLE_REGIONS - 1;
final int expectedElementCount = elements.size() * 2;
assertExpectedNumberOfSplitPointsAndSampleSize(generateSplitPointsFromSampleCaptor, expectedNumOfSplits, expectedElementCount);
}
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, HBaseStore> handler = createHandler();
final SampleElementsForSplitPoints<String> operation = new SampleElementsForSplitPoints.Builder<String>().input(elements).numSplits(numSplits).build();
// When
createHandler().doOperation(operation, new Context(), createStore());
// 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);
}
Aggregations