Search in sources :

Example 11 with AggregateFunction

use of uk.gov.gchq.gaffer.function.AggregateFunction in project Gaffer by gchq.

the class ElementAggregatorTest method shouldCloneAggregator.

@Test
public void shouldCloneAggregator() {
    // Given
    final String reference1 = "reference1";
    final ElementAggregator aggregator = new ElementAggregator();
    final PassThroughFunctionContext<String, AggregateFunction> functionContext1 = mock(PassThroughFunctionContext.class);
    final AggregateFunction function = mock(AggregateFunction.class);
    final AggregateFunction clonedFunction = mock(AggregateFunction.class);
    given(functionContext1.getFunction()).willReturn(function);
    given(functionContext1.getSelection()).willReturn(Collections.singletonList(reference1));
    given(function.statelessClone()).willReturn(clonedFunction);
    aggregator.addFunction(functionContext1);
    // When
    final ElementAggregator clone = aggregator.clone();
    // Then
    assertNotSame(aggregator, clone);
    assertEquals(1, clone.getFunctions().size());
    final PassThroughFunctionContext<String, AggregateFunction> resultClonedFunction = clone.getFunctions().get(0);
    assertEquals(1, resultClonedFunction.getSelection().size());
    assertEquals(reference1, resultClonedFunction.getSelection().get(0));
    assertNotSame(functionContext1, resultClonedFunction);
    assertNotSame(function, resultClonedFunction.getFunction());
    assertSame(clonedFunction, resultClonedFunction.getFunction());
}
Also used : AggregateFunction(uk.gov.gchq.gaffer.function.AggregateFunction) Test(org.junit.Test)

Example 12 with AggregateFunction

use of uk.gov.gchq.gaffer.function.AggregateFunction in project Gaffer by gchq.

the class AggregatorTest method shouldAddAndInitAggregateFunction.

@Test
public void shouldAddAndInitAggregateFunction() {
    // Given
    final Aggregator<String> aggregator = new Aggregator<>();
    final PassThroughFunctionContext<String, AggregateFunction> functionContext1 = mock(PassThroughFunctionContext.class);
    final AggregateFunction function1 = mock(AggregateFunction.class);
    given(functionContext1.getFunction()).willReturn(function1);
    // When
    aggregator.addFunction(functionContext1);
    aggregator.initFunctions();
    // Then
    verify(functionContext1).getFunction();
    verify(function1).init();
}
Also used : AggregateFunction(uk.gov.gchq.gaffer.function.AggregateFunction) Test(org.junit.Test)

Example 13 with AggregateFunction

use of uk.gov.gchq.gaffer.function.AggregateFunction in project Gaffer by gchq.

the class AggregatorTest method shouldBuildAggregator.

@Test
public void shouldBuildAggregator() {
    // Given
    final String reference1 = "reference 1";
    final String reference2 = "reference 2";
    final String reference3a = "reference 3a";
    final String reference3b = "reference 3b";
    final String reference5 = "reference 5";
    final AggregateFunction func1 = mock(AggregateFunction.class);
    final AggregateFunction func3 = mock(AggregateFunction.class);
    final AggregateFunction func4 = mock(AggregateFunction.class);
    final AggregateFunction func5 = mock(AggregateFunction.class);
    // When - check you can build the selection/function in any order,
    // although normally it will be done - select then aggregate.
    final Aggregator<String> aggregator = new Aggregator.Builder<String>().select(reference1).execute(func1).select(reference2).select(reference3a, reference3b).execute(func3).execute(func4).execute(func5).select(reference5).build();
    // Then
    int i = 0;
    PassThroughFunctionContext<String, AggregateFunction> context = aggregator.getFunctions().get(i++);
    assertEquals(1, context.getSelection().size());
    assertEquals(reference1, context.getSelection().get(0));
    assertSame(func1, context.getFunction());
    context = aggregator.getFunctions().get(i++);
    assertEquals(1, context.getSelection().size());
    assertEquals(reference2, context.getSelection().get(0));
    context = aggregator.getFunctions().get(i++);
    assertEquals(2, context.getSelection().size());
    assertEquals(reference3a, context.getSelection().get(0));
    assertEquals(reference3b, context.getSelection().get(1));
    assertSame(func3, context.getFunction());
    context = aggregator.getFunctions().get(i++);
    assertSame(func4, context.getFunction());
    context = aggregator.getFunctions().get(i++);
    assertSame(func5, context.getFunction());
    assertEquals(1, context.getSelection().size());
    assertEquals(reference5, context.getSelection().get(0));
    assertEquals(i, aggregator.getFunctions().size());
}
Also used : AggregateFunction(uk.gov.gchq.gaffer.function.AggregateFunction) Test(org.junit.Test)

Aggregations

AggregateFunction (uk.gov.gchq.gaffer.function.AggregateFunction)13 Test (org.junit.Test)11 PropertiesTuple (uk.gov.gchq.gaffer.data.element.PropertiesTuple)4 PassThroughFunctionContext (uk.gov.gchq.gaffer.function.context.PassThroughFunctionContext)4 ArrayList (java.util.ArrayList)3 IdentifierType (uk.gov.gchq.gaffer.data.element.IdentifierType)3 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)3 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)3 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 Properties (uk.gov.gchq.gaffer.data.element.Properties)2 HashSet (java.util.HashSet)1 ExampleAggregateFunction (uk.gov.gchq.gaffer.function.ExampleAggregateFunction)1 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)1 FilterFunction (uk.gov.gchq.gaffer.function.FilterFunction)1 IsA (uk.gov.gchq.gaffer.function.IsA)1 ConsumerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext)1