Search in sources :

Example 1 with ReduceCombineDriver

use of org.apache.flink.runtime.operators.ReduceCombineDriver in project flink by apache.

the class ReduceCombineDriverTest method testImmutableEmpty.

@Test
public void testImmutableEmpty() {
    try {
        TestTaskContext<ReduceFunction<Tuple2<String, Integer>>, Tuple2<String, Integer>> context = new TestTaskContext<ReduceFunction<Tuple2<String, Integer>>, Tuple2<String, Integer>>(1024 * 1024);
        context.getTaskConfig().setRelativeMemoryDriver(0.5);
        List<Tuple2<String, Integer>> data = DriverTestData.createReduceImmutableData();
        Collections.shuffle(data);
        TupleTypeInfo<Tuple2<String, Integer>> typeInfo = (TupleTypeInfo<Tuple2<String, Integer>>) TypeExtractor.getForObject(data.get(0));
        MutableObjectIterator<Tuple2<String, Integer>> input = EmptyMutableObjectIterator.get();
        context.setDriverStrategy(DriverStrategy.SORTED_PARTIAL_REDUCE);
        TypeComparator<Tuple2<String, Integer>> comparator = typeInfo.createComparator(new int[] { 0 }, new boolean[] { true }, 0, new ExecutionConfig());
        GatheringCollector<Tuple2<String, Integer>> result = new GatheringCollector<Tuple2<String, Integer>>(typeInfo.createSerializer(new ExecutionConfig()));
        context.setInput1(input, typeInfo.createSerializer(new ExecutionConfig()));
        context.setComparator1(comparator);
        context.setCollector(result);
        ReduceCombineDriver<Tuple2<String, Integer>> driver = new ReduceCombineDriver<Tuple2<String, Integer>>();
        driver.setup(context);
        driver.prepare();
        driver.run();
        Assert.assertEquals(0, result.getList().size());
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : RichReduceFunction(org.apache.flink.api.common.functions.RichReduceFunction) ReduceFunction(org.apache.flink.api.common.functions.ReduceFunction) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) TupleTypeInfo(org.apache.flink.api.java.typeutils.TupleTypeInfo) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ReduceCombineDriver(org.apache.flink.runtime.operators.ReduceCombineDriver) Test(org.junit.Test)

Aggregations

ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 ReduceFunction (org.apache.flink.api.common.functions.ReduceFunction)1 RichReduceFunction (org.apache.flink.api.common.functions.RichReduceFunction)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 TupleTypeInfo (org.apache.flink.api.java.typeutils.TupleTypeInfo)1 ReduceCombineDriver (org.apache.flink.runtime.operators.ReduceCombineDriver)1 Test (org.junit.Test)1