Search in sources :

Example 1 with SampleElementsForSplitPoints

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);
}
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 SampleElementsForSplitPoints

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());
}
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 3 with SampleElementsForSplitPoints

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

Example 4 with SampleElementsForSplitPoints

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());
}
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)

Example 5 with SampleElementsForSplitPoints

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
}
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) Element(uk.gov.gchq.gaffer.data.element.Element) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)10 SampleElementsForSplitPoints (uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints)10 Context (uk.gov.gchq.gaffer.store.Context)10 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 IntStream (java.util.stream.IntStream)9 ArgumentCaptor (org.mockito.ArgumentCaptor)9 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)9 Mockito.verify (org.mockito.Mockito.verify)9 TestGroups (uk.gov.gchq.gaffer.commonutil.TestGroups)9 Element (uk.gov.gchq.gaffer.data.element.Element)9 OperationException (uk.gov.gchq.gaffer.operation.OperationException)9 GenerateSplitPointsFromSample (uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample)9 ArrayList (java.util.ArrayList)5 StreamSupport (java.util.stream.StreamSupport)5 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 Assertions.fail (org.junit.jupiter.api.Assertions.fail)5 LimitExceededException (uk.gov.gchq.gaffer.commonutil.exception.LimitExceededException)5