Search in sources :

Example 11 with NirvanaOutputList

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

the class DataSourceTaskTest method testCancelDataSourceTask.

@Test
public void testCancelDataSourceTask() throws IOException {
    int keyCnt = 20;
    int valCnt = 4;
    super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
    super.addOutput(new NirvanaOutputList());
    File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
    InputFilePreparator.prepareInputFile(new UniformRecordGenerator(keyCnt, valCnt, false), tempTestFile, false);
    final DataSourceTask<Record> testTask = new DataSourceTask<>(this.mockEnv);
    super.registerFileInputTask(testTask, MockDelayingInputFormat.class, tempTestFile.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
    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) 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 12 with NirvanaOutputList

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

the class JoinTaskTest method testFailingMatchTask.

@Test
public void testFailingMatchTask() {
    int keyCnt1 = 20;
    int valCnt1 = 20;
    int keyCnt2 = 20;
    int valCnt2 = 20;
    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<>();
    addInput(new UniformRecordGenerator(keyCnt1, valCnt1, true));
    addInput(new UniformRecordGenerator(keyCnt2, valCnt2, true));
    try {
        testDriver(testTask, MockFailingMatchStub.class);
        Assert.fail("Driver did not forward Exception.");
    } catch (ExpectedTestException e) {
    // good!
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("The test caused an exception.");
    }
}
Also used : ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) 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) Test(org.junit.Test)

Example 13 with NirvanaOutputList

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

the class JoinTaskTest method testCancelMatchTaskWhileMatching.

@Test
public void testCancelMatchTaskWhileMatching() {
    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<>();
        addInput(new UniformRecordGenerator(keyCnt, valCnt, true));
        addInput(new UniformRecordGenerator(keyCnt, valCnt, true));
        final AtomicReference<Throwable> error = new AtomicReference<>();
        Thread taskRunner = new Thread("Task runner for testCancelMatchTaskWhileMatching()") {

            @Override
            public void run() {
                try {
                    testDriver(testTask, MockDelayingMatchStub.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 : 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 14 with NirvanaOutputList

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

Example 15 with NirvanaOutputList

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

NirvanaOutputList (org.apache.flink.runtime.operators.testutils.NirvanaOutputList)20 Record (org.apache.flink.types.Record)20 Test (org.junit.Test)20 UniformRecordGenerator (org.apache.flink.runtime.operators.testutils.UniformRecordGenerator)19 ExpectedTestException (org.apache.flink.runtime.operators.testutils.ExpectedTestException)18 TaskCancelThread (org.apache.flink.runtime.operators.testutils.TaskCancelThread)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 DelayingInfinitiveInputIterator (org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator)7 IOException (java.io.IOException)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 File (java.io.File)2