Search in sources :

Example 1 with InfiniteIntTupleIterator

use of org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator 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)

Example 2 with InfiniteIntTupleIterator

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

the class RightOuterJoinTaskTest method testCancelRightOuterJoinTaskWhileBuilding.

@Test
public void testCancelRightOuterJoinTaskWhileBuilding() throws Exception {
    setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
    addDriverComparator(this.comparator1);
    addDriverComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(new RuntimePairComparatorFactory());
    getTaskConfig().setDriverStrategy(DriverStrategy.RIGHT_HYBRIDHASH_BUILD_FIRST);
    getTaskConfig().setRelativeMemoryDriver(this.hash_frac);
    final AbstractOuterJoinDriver<Tuple2<Integer, Integer>, Tuple2<Integer, Integer>, Tuple2<Integer, Integer>> testTask = getOuterJoinDriver();
    addInput(new DelayingIterator<>(new InfiniteIntTupleIterator(), 100), this.serializer);
    addInput(new UniformIntTupleGenerator(100, 100, true), this.serializer);
    final AtomicReference<Throwable> error = new AtomicReference<>();
    final Thread taskRunner = new Thread("Task runner for testCancelOuterJoinTaskWhileSort1()") {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockJoinStub.class);
            } catch (Throwable t) {
                error.set(t);
            }
        }
    };
    taskRunner.start();
    Thread.sleep(1000);
    cancel();
    taskRunner.join(60000);
    assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
    final Throwable taskError = error.get();
    if (taskError != null) {
        fail("Error in task while canceling:\n" + Throwables.getStackTraceAsString(taskError));
    }
}
Also used : RuntimePairComparatorFactory(org.apache.flink.api.java.typeutils.runtime.RuntimePairComparatorFactory) UniformIntTupleGenerator(org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator) Tuple2(org.apache.flink.api.java.tuple.Tuple2) AtomicReference(java.util.concurrent.atomic.AtomicReference) InfiniteIntTupleIterator(org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator) Test(org.junit.Test)

Example 3 with InfiniteIntTupleIterator

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

the class LeftOuterJoinTaskTest method testCancelLeftOuterJoinTaskWhileProbing.

@Test
public void testCancelLeftOuterJoinTaskWhileProbing() throws Exception {
    setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
    addDriverComparator(this.comparator1);
    addDriverComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(new RuntimePairComparatorFactory());
    getTaskConfig().setDriverStrategy(DriverStrategy.LEFT_HYBRIDHASH_BUILD_SECOND);
    getTaskConfig().setRelativeMemoryDriver(this.hash_frac);
    final AbstractOuterJoinDriver<Tuple2<Integer, Integer>, Tuple2<Integer, Integer>, Tuple2<Integer, Integer>> testTask = getOuterJoinDriver();
    addInput(new DelayingIterator<>(new InfiniteIntTupleIterator(), 100), this.serializer);
    addInput(new UniformIntTupleGenerator(1, 1, true), this.serializer);
    final AtomicReference<Throwable> error = new AtomicReference<>();
    final Thread taskRunner = new Thread("Task runner for testCancelOuterJoinTaskWhileSort1()") {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockJoinStub.class);
            } catch (Throwable t) {
                error.set(t);
            }
        }
    };
    taskRunner.start();
    Thread.sleep(1000);
    cancel();
    taskRunner.join(60000);
    assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
    final Throwable taskError = error.get();
    if (taskError != null) {
        fail("Error in task while canceling:\n" + Throwables.getStackTraceAsString(taskError));
    }
}
Also used : RuntimePairComparatorFactory(org.apache.flink.api.java.typeutils.runtime.RuntimePairComparatorFactory) UniformIntTupleGenerator(org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator) Tuple2(org.apache.flink.api.java.tuple.Tuple2) AtomicReference(java.util.concurrent.atomic.AtomicReference) InfiniteIntTupleIterator(org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator) Test(org.junit.Test)

Example 4 with InfiniteIntTupleIterator

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

the class AbstractOuterJoinTaskTest method testCancelOuterJoinTaskWhileRunning.

@Test
public void testCancelOuterJoinTaskWhileRunning() throws Exception {
    setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
    addDriverComparator(this.comparator1);
    addDriverComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(new RuntimePairComparatorFactory());
    getTaskConfig().setDriverStrategy(this.getSortDriverStrategy());
    getTaskConfig().setRelativeMemoryDriver(bnljn_frac);
    setNumFileHandlesForSort(4);
    final AbstractOuterJoinDriver<Tuple2<Integer, Integer>, Tuple2<Integer, Integer>, Tuple2<Integer, Integer>> testTask = getOuterJoinDriver();
    addInput(new DelayingIterator<>(new InfiniteIntTupleIterator(), 100), this.serializer);
    addInput(new DelayingIterator<>(new InfiniteIntTupleIterator(), 100), this.serializer);
    final AtomicReference<Throwable> error = new AtomicReference<>();
    final Thread taskRunner = new Thread("Task runner for testCancelOuterJoinTaskWhileRunning()") {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockJoinStub.class);
            } catch (Throwable t) {
                error.set(t);
            }
        }
    };
    taskRunner.start();
    Thread.sleep(1000);
    cancel();
    taskRunner.interrupt();
    taskRunner.join(60000);
    assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
    final Throwable taskError = error.get();
    if (taskError != null) {
        fail("Error in task while canceling:\n" + Throwables.getStackTraceAsString(taskError));
    }
}
Also used : RuntimePairComparatorFactory(org.apache.flink.api.java.typeutils.runtime.RuntimePairComparatorFactory) Tuple2(org.apache.flink.api.java.tuple.Tuple2) AtomicReference(java.util.concurrent.atomic.AtomicReference) InfiniteIntTupleIterator(org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator) Test(org.junit.Test)

Example 5 with InfiniteIntTupleIterator

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

the class AbstractOuterJoinTaskTest method testCancelOuterJoinTaskWhileSort1.

@Test
public void testCancelOuterJoinTaskWhileSort1() throws Exception {
    setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
    addDriverComparator(this.comparator1);
    addDriverComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(new RuntimePairComparatorFactory());
    getTaskConfig().setDriverStrategy(this.getSortDriverStrategy());
    getTaskConfig().setRelativeMemoryDriver(this.bnljn_frac);
    setNumFileHandlesForSort(4);
    final AbstractOuterJoinDriver<Tuple2<Integer, Integer>, Tuple2<Integer, Integer>, Tuple2<Integer, Integer>> testTask = getOuterJoinDriver();
    addInputSorted(new DelayingIterator<>(new InfiniteIntTupleIterator(), 100), this.serializer, this.comparator1.duplicate());
    addInput(new DelayingIterator<>(new InfiniteIntTupleIterator(), 100), this.serializer);
    final AtomicReference<Throwable> error = new AtomicReference<>();
    final Thread taskRunner = new Thread("Task runner for testCancelOuterJoinTaskWhileSort1()") {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockJoinStub.class);
            } catch (Throwable t) {
                error.set(t);
            }
        }
    };
    taskRunner.start();
    Thread.sleep(1000);
    cancel();
    taskRunner.interrupt();
    taskRunner.join(60000);
    assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
    final Throwable taskError = error.get();
    if (taskError != null) {
        fail("Error in task while canceling:\n" + Throwables.getStackTraceAsString(taskError));
    }
}
Also used : RuntimePairComparatorFactory(org.apache.flink.api.java.typeutils.runtime.RuntimePairComparatorFactory) Tuple2(org.apache.flink.api.java.tuple.Tuple2) AtomicReference(java.util.concurrent.atomic.AtomicReference) InfiniteIntTupleIterator(org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator) Test(org.junit.Test)

Aggregations

Tuple2 (org.apache.flink.api.java.tuple.Tuple2)8 InfiniteIntTupleIterator (org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator)8 Test (org.junit.Test)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 RuntimePairComparatorFactory (org.apache.flink.api.java.typeutils.runtime.RuntimePairComparatorFactory)7 UniformIntTupleGenerator (org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator)4 DelayingIterator (org.apache.flink.runtime.operators.testutils.DelayingIterator)1 ExpectedTestException (org.apache.flink.runtime.operators.testutils.ExpectedTestException)1