Search in sources :

Example 1 with TimerException

use of org.apache.flink.streaming.runtime.tasks.TimerException in project flink by apache.

the class StreamTaskTimerITCase method testTwoInputOperatorWithoutChaining.

@Test
public void testTwoInputOperatorWithoutChaining() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setStreamTimeCharacteristic(timeCharacteristic);
    env.setParallelism(1);
    DataStream<String> source = env.addSource(new InfiniteTestSource());
    source.connect(source).transform("Custom Operator", BasicTypeInfo.STRING_TYPE_INFO, new TwoInputTimerOperator(ChainingStrategy.NEVER));
    boolean testSuccess = false;
    try {
        env.execute("Timer test");
    } catch (JobExecutionException e) {
        if (e.getCause() instanceof TimerException) {
            TimerException te = (TimerException) e.getCause();
            if (te.getCause() instanceof RuntimeException) {
                RuntimeException re = (RuntimeException) te.getCause();
                if (re.getMessage().equals("TEST SUCCESS")) {
                    testSuccess = true;
                } else {
                    throw e;
                }
            } else {
                throw e;
            }
        } else {
            throw e;
        }
    }
    Assert.assertTrue(testSuccess);
}
Also used : TimerException(org.apache.flink.streaming.runtime.tasks.TimerException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Example 2 with TimerException

use of org.apache.flink.streaming.runtime.tasks.TimerException in project flink by apache.

the class StreamTaskTimerITCase method testOneInputOperatorWithoutChaining.

/**
	 * Note: this test fails if we don't check for exceptions in the source contexts and do not
	 * synchronize in the source contexts.
	 */
@Test
public void testOneInputOperatorWithoutChaining() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setStreamTimeCharacteristic(timeCharacteristic);
    env.setParallelism(1);
    DataStream<String> source = env.addSource(new InfiniteTestSource());
    source.transform("Custom Operator", BasicTypeInfo.STRING_TYPE_INFO, new TimerOperator(ChainingStrategy.NEVER));
    boolean testSuccess = false;
    try {
        env.execute("Timer test");
    } catch (JobExecutionException e) {
        if (e.getCause() instanceof TimerException) {
            TimerException te = (TimerException) e.getCause();
            if (te.getCause() instanceof RuntimeException) {
                RuntimeException re = (RuntimeException) te.getCause();
                if (re.getMessage().equals("TEST SUCCESS")) {
                    testSuccess = true;
                } else {
                    throw e;
                }
            } else {
                throw e;
            }
        } else {
            throw e;
        }
    }
    Assert.assertTrue(testSuccess);
}
Also used : TimerException(org.apache.flink.streaming.runtime.tasks.TimerException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Example 3 with TimerException

use of org.apache.flink.streaming.runtime.tasks.TimerException in project flink by apache.

the class StreamTaskTimerITCase method testOperatorChainedToSource.

/**
	 * Note: this test fails if we don't check for exceptions in the source contexts and do not
	 * synchronize in the source contexts.
	 */
@Test
public void testOperatorChainedToSource() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setStreamTimeCharacteristic(timeCharacteristic);
    env.setParallelism(1);
    DataStream<String> source = env.addSource(new InfiniteTestSource());
    source.transform("Custom Operator", BasicTypeInfo.STRING_TYPE_INFO, new TimerOperator(ChainingStrategy.ALWAYS));
    boolean testSuccess = false;
    try {
        env.execute("Timer test");
    } catch (JobExecutionException e) {
        if (e.getCause() instanceof TimerException) {
            TimerException te = (TimerException) e.getCause();
            if (te.getCause() instanceof RuntimeException) {
                RuntimeException re = (RuntimeException) te.getCause();
                if (re.getMessage().equals("TEST SUCCESS")) {
                    testSuccess = true;
                } else {
                    throw e;
                }
            } else {
                throw e;
            }
        } else {
            throw e;
        }
    }
    Assert.assertTrue(testSuccess);
}
Also used : TimerException(org.apache.flink.streaming.runtime.tasks.TimerException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Aggregations

JobExecutionException (org.apache.flink.runtime.client.JobExecutionException)3 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)3 TimerException (org.apache.flink.streaming.runtime.tasks.TimerException)3 Test (org.junit.Test)3