Search in sources :

Example 1 with InfiniteInputIterator

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

the class DataSinkTaskTest method testCancelSortingDataSinkTask.

@Test
@SuppressWarnings("unchecked")
public void testCancelSortingDataSinkTask() {
    double memoryFraction = 1.0;
    super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
    super.addInput(new InfiniteInputIterator(), 0);
    final DataSinkTask<Record> testTask = new DataSinkTask<>();
    Configuration stubParams = new Configuration();
    super.getTaskConfig().setStubParameters(stubParams);
    // set sorting
    super.getTaskConfig().setInputLocalStrategy(0, LocalStrategy.SORT);
    super.getTaskConfig().setInputComparator(new RecordComparatorFactory(new int[] { 1 }, (new Class[] { IntValue.class })), 0);
    super.getTaskConfig().setRelativeMemoryInput(0, memoryFraction);
    super.getTaskConfig().setFilehandlesInput(0, 8);
    super.getTaskConfig().setSpillingThresholdInput(0, 0.8f);
    super.registerFileOutputTask(testTask, MockOutputFormat.class, new File(tempTestPath).toURI().toString());
    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(2, taskRunner, testTask);
    tct.start();
    try {
        tct.join();
        taskRunner.join();
    } catch (InterruptedException ie) {
        Assert.fail("Joining threads failed");
    }
}
Also used : RecordComparatorFactory(org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory) Configuration(org.apache.flink.configuration.Configuration) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Record(org.apache.flink.types.Record) InfiniteInputIterator(org.apache.flink.runtime.operators.testutils.InfiniteInputIterator) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Example 2 with InfiniteInputIterator

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

the class DataSinkTaskTest method testCancelDataSinkTask.

@Test
public void testCancelDataSinkTask() throws Exception {
    super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
    super.addInput(new InfiniteInputIterator(), 0);
    final DataSinkTask<Record> testTask = new DataSinkTask<>();
    Configuration stubParams = new Configuration();
    super.getTaskConfig().setStubParameters(stubParams);
    super.registerFileOutputTask(testTask, MockOutputFormat.class, new File(tempTestPath).toURI().toString());
    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();
    File tempTestFile = new File(this.tempTestPath);
    // wait until the task created the file
    long deadline = System.currentTimeMillis() + 60000;
    while (!tempTestFile.exists() && System.currentTimeMillis() < deadline) {
        Thread.sleep(10);
    }
    assertTrue("Task did not create file within 60 seconds", tempTestFile.exists());
    // cancel the task
    Thread.sleep(500);
    testTask.cancel();
    taskRunner.interrupt();
    // wait for the canceling to complete
    taskRunner.join();
    // assert that temp file was created
    assertFalse("Temp output file has not been removed", tempTestFile.exists());
}
Also used : Configuration(org.apache.flink.configuration.Configuration) Record(org.apache.flink.types.Record) InfiniteInputIterator(org.apache.flink.runtime.operators.testutils.InfiniteInputIterator) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Example 3 with InfiniteInputIterator

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

Aggregations

InfiniteInputIterator (org.apache.flink.runtime.operators.testutils.InfiniteInputIterator)3 TaskCancelThread (org.apache.flink.runtime.operators.testutils.TaskCancelThread)3 Record (org.apache.flink.types.Record)3 Test (org.junit.Test)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Configuration (org.apache.flink.configuration.Configuration)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ExpectedTestException (org.apache.flink.runtime.operators.testutils.ExpectedTestException)1 RecordComparatorFactory (org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory)1