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());
}
}
Aggregations