Search in sources :

Example 1 with Context

use of org.apache.beam.sdk.transforms.CombineWithContext.Context in project beam by apache.

the class CombineFnUtilTest method testToFnWithContext.

@Test
public void testToFnWithContext() throws Exception {
    CombineFnWithContext<Integer, int[], Integer> fnWithContext = CombineFnUtil.toFnWithContext(Sum.ofIntegers());
    List<Integer> inputs = ImmutableList.of(1, 2, 3, 4);
    Context nullContext = CombineContextFactory.nullContext();
    int[] accum = fnWithContext.createAccumulator(nullContext);
    for (Integer i : inputs) {
        accum = fnWithContext.addInput(accum, i, nullContext);
    }
    assertEquals(10, fnWithContext.extractOutput(accum, nullContext).intValue());
}
Also used : CombineFnWithContext(org.apache.beam.sdk.transforms.CombineWithContext.CombineFnWithContext) Context(org.apache.beam.sdk.transforms.CombineWithContext.Context) Test(org.junit.Test)

Aggregations

CombineFnWithContext (org.apache.beam.sdk.transforms.CombineWithContext.CombineFnWithContext)1 Context (org.apache.beam.sdk.transforms.CombineWithContext.Context)1 Test (org.junit.Test)1