use of uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample 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.GenerateSplitPointsFromSample in project Gaffer by gchq.
the class AbstractGenerateSplitPointsFromSampleHandlerTest method shouldReturnEmptyCollectionIfNumSplitsIsLessThan1.
@Test
public void shouldReturnEmptyCollectionIfNumSplitsIsLessThan1() throws OperationException {
// Given
final List<String> sample = createSampleOfSize(100);
final AbstractGenerateSplitPointsFromSampleHandler<?, S> handler = createHandler();
final GenerateSplitPointsFromSample operation = new GenerateSplitPointsFromSample.Builder<>().input(sample).numSplits(0).build();
// When
final List<?> splits = handler.doOperation(operation, new Context(), createStore());
// Then
assertThat(splits).isEmpty();
}
use of uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample in project Gaffer by gchq.
the class GenerateSplitPointsFromSampleHanderTest method shouldUseTheNumberOfTabletServersToCalculateNumSplits.
@Test
public void shouldUseTheNumberOfTabletServersToCalculateNumSplits() throws OperationException {
// Given
final Integer numSplits = null;
final List<String> sample = createSampleOfSize(100);
final GenerateSplitPointsFromSample<String> operation = new GenerateSplitPointsFromSample.Builder<String>().input(sample).numSplits(numSplits).build();
// When
final List<String> splits = createHandler().doOperation(operation, new Context(), store);
// Then
final int expectedNumSplits = NUM_TABLET_SERVERS - 1;
assertEquals(expectedNumSplits, splits.size());
}
use of uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample 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.GenerateSplitPointsFromSample 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());
}
Aggregations