rkhachatryan commented on a change in pull request #14968:
URL: https://github.com/apache/flink/pull/14968#discussion_r579453364
##########
File path:
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/SourceStreamTaskTest.java
##########
@@ -856,4 +887,41 @@ private void output(String record) {
output.collect(new StreamRecord<>(record));
}
}
+
+ /**
+ * This source sleeps a little bit before processing cancellation and
records whether it was
+ * interrupted by the {@link SourceStreamTask} or not.
+ */
+ private static class WasInterruptedTestingSource implements
SourceFunction<String> {
+ private static final int MAX_POST_CANCEL_ITERATIONS = 100;
+ private static final long serialVersionUID = 1L;
+ private volatile boolean running;
+
+ public static boolean wasInterrupted;
+
+ @Override
+ public void run(SourceContext<String> ctx) throws Exception {
+ wasInterrupted = false;
+ try {
+ int postCancelIterations = 0;
+ while (running || postCancelIterations <
MAX_POST_CANCEL_ITERATIONS) {
Review comment:
I think it's better to signal explicitly that this thread can exit.
Otherwise, if there is a pause between `cancel` call and (errouneous)
`interrupt` that interrupt can go unnoticed.
I reverted the fix and added 1s pause in `SourceStreamTask` - and the test
passed (with running=true)
##########
File path:
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/SourceStreamTaskTest.java
##########
@@ -856,4 +887,41 @@ private void output(String record) {
output.collect(new StreamRecord<>(record));
}
}
+
+ /**
+ * This source sleeps a little bit before processing cancellation and
records whether it was
+ * interrupted by the {@link SourceStreamTask} or not.
+ */
+ private static class WasInterruptedTestingSource implements
SourceFunction<String> {
+ private static final int MAX_POST_CANCEL_ITERATIONS = 100;
+ private static final long serialVersionUID = 1L;
+ private volatile boolean running;
Review comment:
Shouldn't this flag be set to `true` by default?
##########
File path:
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/SourceStreamTaskTest.java
##########
@@ -856,4 +887,41 @@ private void output(String record) {
output.collect(new StreamRecord<>(record));
}
}
+
+ /**
+ * This source sleeps a little bit before processing cancellation and
records whether it was
+ * interrupted by the {@link SourceStreamTask} or not.
+ */
+ private static class WasInterruptedTestingSource implements
SourceFunction<String> {
+ private static final int MAX_POST_CANCEL_ITERATIONS = 100;
+ private static final long serialVersionUID = 1L;
+ private volatile boolean running;
+
+ public static boolean wasInterrupted;
+
+ @Override
+ public void run(SourceContext<String> ctx) throws Exception {
+ wasInterrupted = false;
+ try {
+ int postCancelIterations = 0;
+ while (running || postCancelIterations <
MAX_POST_CANCEL_ITERATIONS) {
+ Thread.sleep(1);
+ if (!running) {
+ postCancelIterations++;
+ }
+ }
+ } catch (InterruptedException e) {
+ wasInterrupted = true;
Review comment:
I'm afraid there is very small probability that the thread will be
interrupted after the last sleep.
So I'd check the interrupted status explicitly (in addition to this `catch`).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]