I implemented a custom function that throws up a runtime exception.

You can extend from simpler MapFunction or more complicated 
RichParallelSourceFunction depending on your use case.
You can add logic to throw a runtime exception on a certain condition in the 
map or run method.               .
You can use a count or timer to trigger the exception.

Sharing a quick handwritten example.

DataStream<String> stream = .....
DataStream<String> mappedStream = stream.map(new MapFunction<String, String>>() 
{
          @Override
          public String map(String value) throws Exception {
            if (SOME_CONDITION) {
              throw new RuntimeException("Lets test checkpointing");
            }
                return value;
          }
});

~ Abhinav Bajaj


From: Eleanore Jin <eleanore....@gmail.com>
Date: Wednesday, March 4, 2020 at 4:40 PM
To: user <u...@flink.apache.org>, user-zh <user-zh@flink.apache.org>
Subject: How to test flink job recover from checkpoint

Hi,

I have a flink application and checkpoint is enabled, I am running locally 
using miniCluster.

I just wonder if there is a way to simulate the failure, and verify that flink 
job restarts from checkpoint?

Thanks a lot!
Eleanore

回复