Search in sources :

Example 1 with DelayingIterator

use of org.apache.flink.runtime.operators.testutils.DelayingIterator in project flink by apache.

the class CombineTaskTest method testCancelCombineTaskSorting.

@Test
public void testCancelCombineTaskSorting() {
    try {
        MutableObjectIterator<Tuple2<Integer, Integer>> slowInfiniteInput = new DelayingIterator<>(new InfiniteIntTupleIterator(), 1);
        setInput(slowInfiniteInput, serializer);
        addDriverComparator(this.comparator);
        addDriverComparator(this.comparator);
        setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
        getTaskConfig().setDriverStrategy(DriverStrategy.SORTED_GROUP_COMBINE);
        getTaskConfig().setRelativeMemoryDriver(combine_frac);
        getTaskConfig().setFilehandlesDriver(2);
        final GroupReduceCombineDriver<Tuple2<Integer, Integer>, Tuple2<Integer, Integer>> testTask = new GroupReduceCombineDriver<>();
        Thread taskRunner = new Thread() {

            @Override
            public void run() {
                try {
                    testDriver(testTask, MockFailingCombiningReduceStub.class);
                } catch (Exception e) {
                // exceptions may happen during canceling
                }
            }
        };
        taskRunner.start();
        // give the task some time
        Thread.sleep(500);
        // cancel
        testTask.cancel();
        // make sure it reacts to the canceling in some time
        long deadline = System.currentTimeMillis() + 10000;
        do {
            taskRunner.interrupt();
            taskRunner.join(5000);
        } while (taskRunner.isAlive() && System.currentTimeMillis() < deadline);
        assertFalse("Task did not cancel properly within in 10 seconds.", taskRunner.isAlive());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DelayingIterator(org.apache.flink.runtime.operators.testutils.DelayingIterator) Tuple2(org.apache.flink.api.java.tuple.Tuple2) InfiniteIntTupleIterator(org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) Test(org.junit.Test)

Aggregations

Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 DelayingIterator (org.apache.flink.runtime.operators.testutils.DelayingIterator)1 ExpectedTestException (org.apache.flink.runtime.operators.testutils.ExpectedTestException)1 InfiniteIntTupleIterator (org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator)1 Test (org.junit.Test)1