Search in sources :

Example 16 with TaskCancelThread

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

the class DataSourceTaskTest method testCancelDataSourceTask.

@Test
public void testCancelDataSourceTask() {
    int keyCnt = 20;
    int valCnt = 4;
    super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
    super.addOutput(new NirvanaOutputList());
    try {
        InputFilePreparator.prepareInputFile(new UniformRecordGenerator(keyCnt, valCnt, false), this.tempTestPath, false);
    } catch (IOException e1) {
        Assert.fail("Unable to set-up test input file");
    }
    final DataSourceTask<Record> testTask = new DataSourceTask<>();
    super.registerFileInputTask(testTask, MockDelayingInputFormat.class, new File(tempTestPath).toURI().toString(), "\n");
    Thread taskRunner = new Thread() {

        @Override
        public void run() {
            try {
                testTask.invoke();
            } catch (Exception ie) {
                ie.printStackTrace();
                Assert.fail("Task threw exception although it was properly canceled");
            }
        }
    };
    taskRunner.start();
    TaskCancelThread tct = new TaskCancelThread(1, taskRunner, testTask);
    tct.start();
    try {
        tct.join();
        taskRunner.join();
    } catch (InterruptedException ie) {
        Assert.fail("Joining threads failed");
    }
    // assert that temp file was created
    File tempTestFile = new File(this.tempTestPath);
    Assert.assertTrue("Temp output file does not exist", tempTestFile.exists());
}
Also used : TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Record(org.apache.flink.types.Record) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) IOException(java.io.IOException) NirvanaOutputList(org.apache.flink.runtime.operators.testutils.NirvanaOutputList) File(java.io.File) IOException(java.io.IOException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Example 17 with TaskCancelThread

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

the class FlatMapTaskTest method testCancelMapTask.

@Test
public void testCancelMapTask() {
    addInput(new InfiniteInputIterator());
    setOutput(new DiscardingOutputCollector<Record>());
    final FlatMapDriver<Record, Record> testTask = new FlatMapDriver<>();
    final AtomicBoolean success = new AtomicBoolean(false);
    final Thread taskRunner = new Thread() {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockMapStub.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) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Record(org.apache.flink.types.Record) InfiniteInputIterator(org.apache.flink.runtime.operators.testutils.InfiniteInputIterator) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Example 18 with TaskCancelThread

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

the class JoinTaskTest method testHashSecondCancelMatchTaskWhileMatching.

@Test
public void testHashSecondCancelMatchTaskWhileMatching() {
    int keyCnt = 20;
    int valCnt = 20;
    addInput(new UniformRecordGenerator(keyCnt, valCnt, false));
    addInput(new UniformRecordGenerator(keyCnt, valCnt, false));
    addDriverComparator(this.comparator1);
    addDriverComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(RecordPairComparatorFactory.get());
    setOutput(new NirvanaOutputList());
    getTaskConfig().setDriverStrategy(DriverStrategy.HYBRIDHASH_BUILD_SECOND);
    getTaskConfig().setRelativeMemoryDriver(hash_frac);
    final JoinDriver<Record, Record, Record> testTask = new JoinDriver<>();
    final AtomicBoolean success = new AtomicBoolean(false);
    Thread taskRunner = new Thread() {

        @Override
        public void run() {
            try {
                testDriver(testTask, MockMatchStub.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) 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)

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