Search in sources :

Example 1 with GenerateSplitPointsFromSample

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);
}
Also used : ByteEntityAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityAccumuloElementConverter) IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) AccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.AccumuloElementConverter) StoreException(uk.gov.gchq.gaffer.store.StoreException) AccumuloKeyPackage(uk.gov.gchq.gaffer.accumulostore.key.AccumuloKeyPackage) Element(uk.gov.gchq.gaffer.data.element.Element) AbstractSampleElementsForSplitPointsHandlerTest(uk.gov.gchq.gaffer.store.operation.handler.AbstractSampleElementsForSplitPointsHandlerTest) ArgumentCaptor(org.mockito.ArgumentCaptor) BDDMockito.given(org.mockito.BDDMockito.given) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore) Edge(uk.gov.gchq.gaffer.data.element.Edge) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) AbstractSampleElementsForSplitPointsHandler(uk.gov.gchq.gaffer.store.operation.handler.AbstractSampleElementsForSplitPointsHandler) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) Context(uk.gov.gchq.gaffer.store.Context) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Context(uk.gov.gchq.gaffer.store.Context) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) Element(uk.gov.gchq.gaffer.data.element.Element) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore) Edge(uk.gov.gchq.gaffer.data.element.Edge) AbstractSampleElementsForSplitPointsHandlerTest(uk.gov.gchq.gaffer.store.operation.handler.AbstractSampleElementsForSplitPointsHandlerTest) Test(org.junit.jupiter.api.Test)

Example 2 with GenerateSplitPointsFromSample

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();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) Test(org.junit.jupiter.api.Test)

Example 3 with GenerateSplitPointsFromSample

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());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) AbstractGenerateSplitPointsFromSampleHandlerTest(uk.gov.gchq.gaffer.store.operation.handler.AbstractGenerateSplitPointsFromSampleHandlerTest) Test(org.junit.jupiter.api.Test)

Example 4 with GenerateSplitPointsFromSample

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());
}
Also used : IntStream(java.util.stream.IntStream) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) ArgumentCaptor(org.mockito.ArgumentCaptor) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) StreamSupport(java.util.stream.StreamSupport) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) Entity(uk.gov.gchq.gaffer.data.element.Entity) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Store(uk.gov.gchq.gaffer.store.Store) List(java.util.List) Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) LimitExceededException(uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TestTypes(uk.gov.gchq.gaffer.store.TestTypes) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) Element(uk.gov.gchq.gaffer.data.element.Element) Test(org.junit.jupiter.api.Test)

Example 5 with GenerateSplitPointsFromSample

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());
}
Also used : IntStream(java.util.stream.IntStream) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) ArgumentCaptor(org.mockito.ArgumentCaptor) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) StreamSupport(java.util.stream.StreamSupport) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) Entity(uk.gov.gchq.gaffer.data.element.Entity) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Store(uk.gov.gchq.gaffer.store.Store) List(java.util.List) Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) LimitExceededException(uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TestTypes(uk.gov.gchq.gaffer.store.TestTypes) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) Test(org.junit.jupiter.api.Test)

Aggregations

GenerateSplitPointsFromSample (uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample)14 Context (uk.gov.gchq.gaffer.store.Context)14 Test (org.junit.jupiter.api.Test)13 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 IntStream (java.util.stream.IntStream)7 ArgumentCaptor (org.mockito.ArgumentCaptor)7 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)7 Mockito.verify (org.mockito.Mockito.verify)7 TestGroups (uk.gov.gchq.gaffer.commonutil.TestGroups)7 Element (uk.gov.gchq.gaffer.data.element.Element)7 OperationException (uk.gov.gchq.gaffer.operation.OperationException)7 SampleElementsForSplitPoints (uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints)7 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 BDDMockito.given (org.mockito.BDDMockito.given)4 Mockito.mock (org.mockito.Mockito.mock)4 Edge (uk.gov.gchq.gaffer.data.element.Edge)4 StoreException (uk.gov.gchq.gaffer.store.StoreException)4