Search in sources :

Example 11 with TaskCancelThread

use of org.apache.flink.runtime.operators.testutils.TaskCancelThread 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 12 with TaskCancelThread

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

the class ReduceTaskTest method testCancelReduceTaskWhileReducing.

@Test
public void testCancelReduceTaskWhileReducing() {
    final int keyCnt = 1000;
    final int valCnt = 2;
    addInput(new UniformRecordGenerator(keyCnt, valCnt, true));
    addDriverComparator(this.comparator);
    setOutput(new NirvanaOutputList());
    getTaskConfig().setDriverStrategy(DriverStrategy.SORTED_GROUP_REDUCE);
    final GroupReduceDriver<Record, Record> testTask = new GroupReduceDriver<>();
    final AtomicBoolean success = new AtomicBoolean(false);
    Thread taskRunner = new Thread() {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockDelayingReduceStub.class);
                success.set(true);
            } catch (Exception ie) {
                ie.printStackTrace();
            }
        }
    };
    taskRunner.start();
    TaskCancelThread tct = new TaskCancelThread(2, taskRunner, this);
    tct.start();
    try {
        tct.join();
        taskRunner.join();
    } catch (InterruptedException ie) {
        Assert.fail("Joining threads failed");
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Record(org.apache.flink.types.Record) 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 13 with TaskCancelThread

use of org.apache.flink.runtime.operators.testutils.TaskCancelThread 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 14 with TaskCancelThread

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

the class CrossTaskTest method testCancelStreamCrossTaskCrossing.

@Test
public void testCancelStreamCrossTaskCrossing() {
    int keyCnt = 10;
    int valCnt = 1;
    setOutput(this.output);
    addInput(new UniformRecordGenerator(keyCnt, valCnt, false));
    addInput(new DelayingInfinitiveInputIterator(100));
    getTaskConfig().setDriverStrategy(DriverStrategy.NESTEDLOOP_STREAMED_OUTER_SECOND);
    getTaskConfig().setRelativeMemoryDriver(cross_frac);
    final CrossDriver<Record, Record, Record> testTask = new CrossDriver<>();
    final AtomicBoolean success = new AtomicBoolean(false);
    Thread taskRunner = new Thread() {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockCrossStub.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("Exception was thrown despite proper canceling.", 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 15 with TaskCancelThread

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

the class CrossTaskTest method testCancelStreamCrossTaskInit.

@Test
public void testCancelStreamCrossTaskInit() {
    int keyCnt = 10;
    int valCnt = 1;
    setOutput(this.output);
    addInput(new UniformRecordGenerator(keyCnt, valCnt, false));
    addInput(new DelayingInfinitiveInputIterator(100));
    getTaskConfig().setDriverStrategy(DriverStrategy.NESTEDLOOP_STREAMED_OUTER_FIRST);
    getTaskConfig().setRelativeMemoryDriver(cross_frac);
    final CrossDriver<Record, Record, Record> testTask = new CrossDriver<>();
    final AtomicBoolean success = new AtomicBoolean(false);
    Thread taskRunner = new Thread() {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockCrossStub.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("Exception was thrown despite proper canceling.", 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)

Aggregations

TaskCancelThread (org.apache.flink.runtime.operators.testutils.TaskCancelThread)18 Record (org.apache.flink.types.Record)18 Test (org.junit.Test)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 ExpectedTestException (org.apache.flink.runtime.operators.testutils.ExpectedTestException)16 UniformRecordGenerator (org.apache.flink.runtime.operators.testutils.UniformRecordGenerator)15 DelayingInfinitiveInputIterator (org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator)9 NirvanaOutputList (org.apache.flink.runtime.operators.testutils.NirvanaOutputList)9 File (java.io.File)2 IOException (java.io.IOException)2 InfiniteInputIterator (org.apache.flink.runtime.operators.testutils.InfiniteInputIterator)2 FileNotFoundException (java.io.FileNotFoundException)1 Configuration (org.apache.flink.configuration.Configuration)1 RecordComparatorFactory (org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory)1