You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by gu...@apache.org on 2025/02/17 03:50:18 UTC

(flink) branch release-2.0 updated: [FLINK-37194][tests] Fix NPE issue in WatermarkITCase

This is an automated email from the ASF dual-hosted git repository.

guoweijie pushed a commit to branch release-2.0
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/release-2.0 by this push:
     new dd4bd43423a [FLINK-37194][tests] Fix NPE issue in WatermarkITCase
dd4bd43423a is described below

commit dd4bd43423a22bf649de94826f8d9d45b546343f
Author: Luke Chen <sh...@gmail.com>
AuthorDate: Wed Jan 22 15:19:51 2025 +0800

    [FLINK-37194][tests] Fix NPE issue in WatermarkITCase
    
    (cherry picked from commit 20d5eb0a8cc9be84a3375e2968564b1301c5e7b2)
---
 .../streaming/api/datastream/WatermarkITCase.java  | 105 ++++++---------------
 1 file changed, 27 insertions(+), 78 deletions(-)

diff --git a/flink-tests/src/test/java/org/apache/flink/test/streaming/api/datastream/WatermarkITCase.java b/flink-tests/src/test/java/org/apache/flink/test/streaming/api/datastream/WatermarkITCase.java
index e4a4db55991..9d77d87c89b 100644
--- a/flink-tests/src/test/java/org/apache/flink/test/streaming/api/datastream/WatermarkITCase.java
+++ b/flink-tests/src/test/java/org/apache/flink/test/streaming/api/datastream/WatermarkITCase.java
@@ -135,6 +135,27 @@ class WatermarkITCase {
         }
     }
 
+    private JobID submitJobAndWaitForOperator3Initialized(
+            StreamGraph streamGraph, boolean watermarkIsLongType)
+            throws ExecutionException, InterruptedException {
+        // block operator2's subtask 0 and subtask 1
+        Operator2ProcessFunction.blockSubTasks(0, 1);
+
+        // submit job
+        JobID jobId = flinkCluster.submitJob(streamGraph).get().getJobID();
+
+        // wait all operator3 tasks have initialized completely
+        tryWaitUntilCondition(
+                () -> Operator3ProcessFunction.receivedWatermarks.size() == DEFAULT_PARALLELISM);
+        // since all Operator2 tasks are blocked, so the Operator3 should not receive watermarks and
+        // records
+        assertOperatorReceivedWatermarkValues(
+                Operator3ProcessFunction.receivedWatermarks, watermarkIsLongType);
+        assertThat(Operator3ProcessFunction.receivedRecords).isEmpty();
+
+        return jobId;
+    }
+
     /**
      * Test aligned watermark can block upstream. In this test case, Operator2 will declare the
      * aligned watermark. We will block Operator2's subtasks first and unblock them step by step,
@@ -146,19 +167,7 @@ class WatermarkITCase {
     void testAlignedWatermarkBlockUpstream() throws Exception {
         StreamGraph streamGraph = getStreamGraphForAlignedWatermark(Map.of(0, true, 1, true));
 
-        // block operator2's subtask 0 and subtask 1
-        Operator2ProcessFunction.blockSubTasks(0, 1);
-
-        // submit job
-        JobID jobId = flinkCluster.submitJob(streamGraph).get().getJobID();
-
-        // wait all operator3 tasks have started
-        tryWaitUntilCondition(
-                () -> Operator3ProcessFunction.attemptIds.size() == DEFAULT_PARALLELISM);
-        // since all Operator2 tasks are blocked, so the Operator3 should not receive watermarks and
-        // records
-        assertOperatorReceivedWatermarkValues(Operator3ProcessFunction.receivedWatermarks, false);
-        assertThat(Operator3ProcessFunction.receivedRecords).isEmpty();
+        JobID jobId = submitJobAndWaitForOperator3Initialized(streamGraph, false);
 
         // unblock operator2's subtask 0; it will send a watermark with the value {@code true} to
         // operator3.
@@ -198,19 +207,7 @@ class WatermarkITCase {
         StreamGraph streamGraph =
                 getStreamGraphForLongWatermarkCombineFunction(true, Map.of(0, 1L, 1, 2L));
 
-        // block operator2's subtask 0 and subtask 1
-        Operator2ProcessFunction.blockSubTasks(0, 1);
-
-        // submit job
-        JobID jobId = flinkCluster.submitJob(streamGraph).get().getJobID();
-
-        // wait all operator3 tasks have started
-        tryWaitUntilCondition(
-                () -> Operator3ProcessFunction.attemptIds.size() == DEFAULT_PARALLELISM);
-        // since all Operator2 tasks are blocked, so the Operator3 should not receive watermarks and
-        // records
-        assertOperatorReceivedWatermarkValues(Operator3ProcessFunction.receivedWatermarks, true);
-        assertThat(Operator3ProcessFunction.receivedRecords).isEmpty();
+        JobID jobId = submitJobAndWaitForOperator3Initialized(streamGraph, true);
 
         // unblock Operator2's subtask 0, which will send a watermark with value {@code 1L} to
         // Operator3,
@@ -255,19 +252,7 @@ class WatermarkITCase {
         StreamGraph streamGraph =
                 getStreamGraphForLongWatermarkCombineFunction(false, Map.of(0, 1L, 1, 2L));
 
-        // block operator2's subtask 0 and subtask 1
-        Operator2ProcessFunction.blockSubTasks(0, 1);
-
-        // submit job
-        JobID jobId = flinkCluster.submitJob(streamGraph).get().getJobID();
-
-        // wait all operator3 tasks have started
-        tryWaitUntilCondition(
-                () -> Operator3ProcessFunction.attemptIds.size() == DEFAULT_PARALLELISM);
-        // since all Operator2 tasks are blocked, so the Operator3 should not receive watermarks and
-        // records
-        assertOperatorReceivedWatermarkValues(Operator3ProcessFunction.receivedWatermarks, true);
-        assertThat(Operator3ProcessFunction.receivedRecords).isEmpty();
+        JobID jobId = submitJobAndWaitForOperator3Initialized(streamGraph, true);
 
         // unblock Operator2's subtask 0, which will send a watermark with value {@code 1L} to
         // Operator3,
@@ -314,19 +299,7 @@ class WatermarkITCase {
         StreamGraph streamGraph =
                 getStreamGraphForBoolWatermarkCombineFunction(true, Map.of(0, false, 1, true));
 
-        // block operator2's subtask 0 and subtask 1
-        Operator2ProcessFunction.blockSubTasks(0, 1);
-
-        // submit job
-        JobID jobId = flinkCluster.submitJob(streamGraph).get().getJobID();
-
-        // wait all operator3 tasks have started
-        tryWaitUntilCondition(
-                () -> Operator3ProcessFunction.attemptIds.size() == DEFAULT_PARALLELISM);
-        // since all Operator2 tasks are blocked, so the Operator3 should not receive watermarks and
-        // records
-        assertOperatorReceivedWatermarkValues(Operator3ProcessFunction.receivedWatermarks, false);
-        assertThat(Operator3ProcessFunction.receivedRecords).isEmpty();
+        JobID jobId = submitJobAndWaitForOperator3Initialized(streamGraph, false);
 
         // unblock Operator2's subtask 0, which will send a watermark with value {@code false} to
         // Operator3,
@@ -373,19 +346,7 @@ class WatermarkITCase {
         StreamGraph streamGraph =
                 getStreamGraphForBoolWatermarkCombineFunction(false, Map.of(0, false, 1, true));
 
-        // block operator2's subtask 0 and subtask 1
-        Operator2ProcessFunction.blockSubTasks(0, 1);
-
-        // submit job
-        JobID jobId = flinkCluster.submitJob(streamGraph).get().getJobID();
-
-        // wait all operator3 tasks have started
-        tryWaitUntilCondition(
-                () -> Operator3ProcessFunction.attemptIds.size() == DEFAULT_PARALLELISM);
-        // since all Operator2 tasks are blocked, so the Operator3 should not receive watermarks and
-        // records
-        assertOperatorReceivedWatermarkValues(Operator3ProcessFunction.receivedWatermarks, false);
-        assertThat(Operator3ProcessFunction.receivedRecords).isEmpty();
+        JobID jobId = submitJobAndWaitForOperator3Initialized(streamGraph, false);
 
         // unblock Operator2's subtask 0, which will send a watermark with value {@code false} to
         // Operator3,
@@ -433,19 +394,7 @@ class WatermarkITCase {
             throws ReflectiveOperationException, ExecutionException, InterruptedException {
         StreamGraph streamGraph = getStreamGraphForCombineWaitForAllChannels(Map.of(0, 1L, 1, 2L));
 
-        // block operator2's subtask 0 and subtask 1
-        Operator2ProcessFunction.blockSubTasks(0, 1);
-
-        // submit job
-        JobID jobId = flinkCluster.submitJob(streamGraph).get().getJobID();
-
-        // wait all operator3 tasks have started
-        tryWaitUntilCondition(
-                () -> Operator3ProcessFunction.attemptIds.size() == DEFAULT_PARALLELISM);
-        // since all Operator2 tasks are blocked, so the Operator3 should not receive watermarks and
-        // records
-        assertOperatorReceivedWatermarkValues(Operator3ProcessFunction.receivedWatermarks, true);
-        assertThat(Operator3ProcessFunction.receivedRecords).isEmpty();
+        JobID jobId = submitJobAndWaitForOperator3Initialized(streamGraph, true);
 
         // unblock Operator2's subtask 0, which will send a watermark with value {@code 1L} to
         // Operator3,