Search in sources :

Example 6 with DelayingInfinitiveInputIterator

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

the class CoGroupTaskTest method testCancelCoGroupTaskWhileSorting2.

@Test
public void testCancelCoGroupTaskWhileSorting2() {
    int keyCnt = 10;
    int valCnt = 2;
    setOutput(this.output);
    addDriverComparator(this.comparator1);
    addDriverComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(RecordPairComparatorFactory.get());
    getTaskConfig().setDriverStrategy(DriverStrategy.CO_GROUP);
    final CoGroupDriver<Record, Record, Record> testTask = new CoGroupDriver<Record, Record, Record>();
    try {
        addInput(new UniformRecordGenerator(keyCnt, valCnt, true));
        addInputSorted(new DelayingInfinitiveInputIterator(1000), this.comparator2.duplicate());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("The test caused an exception.");
    }
    final AtomicBoolean success = new AtomicBoolean(false);
    Thread taskRunner = new Thread() {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockCoGroupStub.class);
                success.set(true);
            } catch (Exception ie) {
                ie.printStackTrace();
            }
        }
    };
    taskRunner.start();
    TaskCancelThread tct = new TaskCancelThread(1, taskRunner, this);
    tct.start();
    try {
        tct.join();
        taskRunner.join();
    } catch (InterruptedException ie) {
        Assert.fail("Joining threads failed");
    }
    Assert.assertTrue("Test threw an exception even though it was properly canceled.", success.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DelayingInfinitiveInputIterator(org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Record(org.apache.flink.types.Record) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Example 7 with DelayingInfinitiveInputIterator

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

the class CoGroupTaskTest method testCancelCoGroupTaskWhileSorting1.

@Test
public void testCancelCoGroupTaskWhileSorting1() {
    int keyCnt = 10;
    int valCnt = 2;
    setOutput(this.output);
    addDriverComparator(this.comparator1);
    addDriverComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(RecordPairComparatorFactory.get());
    getTaskConfig().setDriverStrategy(DriverStrategy.CO_GROUP);
    final CoGroupDriver<Record, Record, Record> testTask = new CoGroupDriver<Record, Record, Record>();
    try {
        addInputSorted(new DelayingInfinitiveInputIterator(1000), this.comparator1.duplicate());
        addInput(new UniformRecordGenerator(keyCnt, valCnt, true));
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("The test caused an exception.");
    }
    final AtomicBoolean success = new AtomicBoolean(false);
    Thread taskRunner = new Thread() {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockCoGroupStub.class);
                success.set(true);
            } catch (Exception ie) {
                ie.printStackTrace();
            }
        }
    };
    taskRunner.start();
    TaskCancelThread tct = new TaskCancelThread(1, taskRunner, this);
    tct.start();
    try {
        tct.join();
        taskRunner.join();
    } catch (InterruptedException ie) {
        Assert.fail("Joining threads failed");
    }
    Assert.assertTrue("Test threw an exception even though it was properly canceled.", success.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DelayingInfinitiveInputIterator(org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Record(org.apache.flink.types.Record) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Example 8 with DelayingInfinitiveInputIterator

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

the class ReduceTaskTest method testCancelReduceTaskWhileSorting.

@Test
public void testCancelReduceTaskWhileSorting() {
    addDriverComparator(this.comparator);
    setOutput(new NirvanaOutputList());
    getTaskConfig().setDriverStrategy(DriverStrategy.SORTED_GROUP_REDUCE);
    final GroupReduceDriver<Record, Record> testTask = new GroupReduceDriver<>();
    try {
        addInputSorted(new DelayingInfinitiveInputIterator(100), this.comparator.duplicate());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    }
    final AtomicBoolean success = new AtomicBoolean(false);
    Thread taskRunner = new Thread() {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockReduceStub.class);
                success.set(true);
            } catch (Exception ie) {
                ie.printStackTrace();
            }
        }
    };
    taskRunner.start();
    TaskCancelThread tct = new TaskCancelThread(1, taskRunner, this);
    tct.start();
    try {
        tct.join();
        taskRunner.join();
    } catch (InterruptedException ie) {
        Assert.fail("Joining threads failed");
    }
    Assert.assertTrue("Test threw an exception even though it was properly canceled.", success.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DelayingInfinitiveInputIterator(org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Record(org.apache.flink.types.Record) NirvanaOutputList(org.apache.flink.runtime.operators.testutils.NirvanaOutputList) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Example 9 with DelayingInfinitiveInputIterator

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

the class JoinTaskTest method testCancelMatchTaskWhileSort1.

@Test
public void testCancelMatchTaskWhileSort1() {
    final int keyCnt = 20;
    final int valCnt = 20;
    try {
        setOutput(new NirvanaOutputList());
        addDriverComparator(this.comparator1);
        addDriverComparator(this.comparator2);
        getTaskConfig().setDriverPairComparator(RecordPairComparatorFactory.get());
        getTaskConfig().setDriverStrategy(DriverStrategy.INNER_MERGE);
        getTaskConfig().setRelativeMemoryDriver(bnljn_frac);
        setNumFileHandlesForSort(4);
        final JoinDriver<Record, Record, Record> testTask = new JoinDriver<>();
        try {
            addInputSorted(new DelayingInfinitiveInputIterator(100), this.comparator1.duplicate());
            addInput(new UniformRecordGenerator(keyCnt, valCnt, true));
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail("The test caused an exception.");
        }
        final AtomicReference<Throwable> error = new AtomicReference<>();
        Thread taskRunner = new Thread("Task runner for testCancelMatchTaskWhileSort1()") {

            @Override
            public void run() {
                try {
                    testDriver(testTask, MockMatchStub.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());
        Throwable taskError = error.get();
        if (taskError != null) {
            taskError.printStackTrace();
            fail("Error in task while canceling: " + taskError.getMessage());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DelayingInfinitiveInputIterator(org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator) Record(org.apache.flink.types.Record) AtomicReference(java.util.concurrent.atomic.AtomicReference) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) NirvanaOutputList(org.apache.flink.runtime.operators.testutils.NirvanaOutputList) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Example 10 with DelayingInfinitiveInputIterator

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

the class JoinTaskTest method testCancelMatchTaskWhileSort2.

@Test
public void testCancelMatchTaskWhileSort2() {
    final int keyCnt = 20;
    final int valCnt = 20;
    try {
        setOutput(new NirvanaOutputList());
        addDriverComparator(this.comparator1);
        addDriverComparator(this.comparator2);
        getTaskConfig().setDriverPairComparator(RecordPairComparatorFactory.get());
        getTaskConfig().setDriverStrategy(DriverStrategy.INNER_MERGE);
        getTaskConfig().setRelativeMemoryDriver(bnljn_frac);
        setNumFileHandlesForSort(4);
        final JoinDriver<Record, Record, Record> testTask = new JoinDriver<>();
        try {
            addInput(new UniformRecordGenerator(keyCnt, valCnt, true));
            addInputSorted(new DelayingInfinitiveInputIterator(100), this.comparator1.duplicate());
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail("The test caused an exception.");
        }
        final AtomicReference<Throwable> error = new AtomicReference<>();
        Thread taskRunner = new Thread("Task runner for testCancelMatchTaskWhileSort2()") {

            @Override
            public void run() {
                try {
                    testDriver(testTask, MockMatchStub.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());
        Throwable taskError = error.get();
        if (taskError != null) {
            taskError.printStackTrace();
            fail("Error in task while canceling: " + taskError.getMessage());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DelayingInfinitiveInputIterator(org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator) Record(org.apache.flink.types.Record) AtomicReference(java.util.concurrent.atomic.AtomicReference) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) NirvanaOutputList(org.apache.flink.runtime.operators.testutils.NirvanaOutputList) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Aggregations

DelayingInfinitiveInputIterator (org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator)13 ExpectedTestException (org.apache.flink.runtime.operators.testutils.ExpectedTestException)13 TaskCancelThread (org.apache.flink.runtime.operators.testutils.TaskCancelThread)13 Record (org.apache.flink.types.Record)13 Test (org.junit.Test)13 UniformRecordGenerator (org.apache.flink.runtime.operators.testutils.UniformRecordGenerator)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 NirvanaOutputList (org.apache.flink.runtime.operators.testutils.NirvanaOutputList)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)2