Search in sources :

Example 1 with AccumulationTag

use of org.apache.apex.malhar.lib.window.accumulation.CompositeAccumulation.AccumulationTag in project apex-malhar by apache.

the class CompositeAccumulationTest method testIncremental.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testIncremental() {
    CompositeAccumulation<Long> accumulations = new CompositeAccumulation<>();
    AccumulationTag sumTag = accumulations.addAccumulation((Accumulation) new SumAccumulation());
    AccumulationTag countTag = accumulations.addAccumulation((Accumulation) new Count());
    AccumulationTag maxTag = accumulations.addAccumulation(new Max());
    AccumulationTag minTag = accumulations.addAccumulation(new Min());
    List values = accumulations.defaultAccumulatedValue();
    for (long i = 1; i <= 10; i++) {
        values = accumulations.accumulate(values, i);
    }
    List outputValues = accumulations.getOutput(values);
    Assert.assertTrue((Long) accumulations.getSubOutput(sumTag, outputValues) == 55L);
    Assert.assertTrue((Long) accumulations.getSubOutput(countTag, outputValues) == 10L);
    Assert.assertTrue((Long) accumulations.getSubOutput(maxTag, outputValues) == 10L);
    Assert.assertTrue((Long) accumulations.getSubOutput(minTag, outputValues) == 1L);
}
Also used : AccumulationTag(org.apache.apex.malhar.lib.window.accumulation.CompositeAccumulation.AccumulationTag) SumAccumulation(org.apache.apex.malhar.lib.window.SumAccumulation) List(java.util.List) Test(org.junit.Test)

Example 2 with AccumulationTag

use of org.apache.apex.malhar.lib.window.accumulation.CompositeAccumulation.AccumulationTag in project apex-malhar by apache.

the class CompositeAccumulationTest method testAverage.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testAverage() {
    CompositeAccumulation<Double> accumulations = new CompositeAccumulation<>();
    AccumulationTag averageTag = accumulations.addAccumulation((Accumulation) new Average());
    List values = accumulations.defaultAccumulatedValue();
    for (int i = 1; i <= 10; i++) {
        values = accumulations.accumulate(values, i * 1.0);
    }
    List outputValues = accumulations.getOutput(values);
    Assert.assertTrue((Double) accumulations.getSubOutput(averageTag, outputValues) == 5.5);
}
Also used : AccumulationTag(org.apache.apex.malhar.lib.window.accumulation.CompositeAccumulation.AccumulationTag) List(java.util.List) Test(org.junit.Test)

Aggregations

List (java.util.List)2 AccumulationTag (org.apache.apex.malhar.lib.window.accumulation.CompositeAccumulation.AccumulationTag)2 Test (org.junit.Test)2 SumAccumulation (org.apache.apex.malhar.lib.window.SumAccumulation)1