dmvk commented on a change in pull request #16464:
URL: https://github.com/apache/flink/pull/16464#discussion_r668673695



##########
File path: 
flink-clients/src/test/java/org/apache/flink/client/deployment/application/ApplicationDispatcherBootstrapTest.java
##########
@@ -650,6 +657,105 @@ public void 
testClusterDoesNOTShutdownWhenApplicationStatusUknown() throws Excep
         assertEquals(exception.getStatus(), ApplicationStatus.UNKNOWN);
     }
 
+    @Test
+    public void testDuplicateJobSubmissionWithTerminatedJobId() throws 
Throwable {
+        final JobID testJobID = new JobID(0, 2);
+        final Configuration configurationUnderTest = getConfiguration();
+        configurationUnderTest.set(
+                PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID, 
testJobID.toHexString());
+        configurationUnderTest.set(
+                HighAvailabilityOptions.HA_MODE, 
HighAvailabilityMode.ZOOKEEPER.name());
+        final TestingDispatcherGateway.Builder dispatcherBuilder =
+                new TestingDispatcherGateway.Builder()
+                        .setSubmitFunction(
+                                jobGraph -> {
+                                    final CompletableFuture<Acknowledge> 
submit =
+                                            new CompletableFuture<>();
+                                    submit.completeExceptionally(
+                                            
DuplicateJobSubmissionException.ofGloballyTerminated(
+                                                    testJobID));
+                                    return submit;
+                                })
+                        .setRequestJobStatusFunction(
+                                jobId -> 
CompletableFuture.completedFuture(JobStatus.FINISHED))
+                        .setRequestJobResultFunction(
+                                jobId ->
+                                        CompletableFuture.completedFuture(
+                                                
createSuccessfulJobResult(jobId)));
+        final CompletableFuture<Void> applicationFuture =
+                runApplication(dispatcherBuilder, configurationUnderTest, 1);
+        applicationFuture.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+    }
+
+    /**
+     * In this scenario, job result is no longer present in the {@link
+     * org.apache.flink.runtime.dispatcher.Dispatcher dispatcher} (job has 
terminated and job
+     * manager failed over), but we know that job has already terminated from 
{@link
+     * org.apache.flink.runtime.highavailability.RunningJobsRegistry running 
jobs registry}.
+     */
+    @Test
+    public void 
testDuplicateJobSubmissionWithTerminatedJobIdWithUnknownResult() throws 
Throwable {
+        final JobID testJobID = new JobID(0, 2);
+        final Configuration configurationUnderTest = getConfiguration();
+        configurationUnderTest.set(
+                PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID, 
testJobID.toHexString());
+        configurationUnderTest.set(
+                HighAvailabilityOptions.HA_MODE, 
HighAvailabilityMode.ZOOKEEPER.name());
+        final TestingDispatcherGateway.Builder dispatcherBuilder =
+                new TestingDispatcherGateway.Builder()
+                        .setSubmitFunction(
+                                jobGraph -> {
+                                    final CompletableFuture<Acknowledge> 
submit =
+                                            new CompletableFuture<>();
+                                    submit.completeExceptionally(
+                                            
DuplicateJobSubmissionException.ofGloballyTerminated(
+                                                    testJobID));
+                                    return submit;
+                                })
+                        .setRequestJobStatusFunction(
+                                jobId ->
+                                        FutureUtils.completedExceptionally(
+                                                new 
FlinkJobNotFoundException(jobId)))
+                        .setRequestJobResultFunction(
+                                jobId ->
+                                        FutureUtils.completedExceptionally(
+                                                new 
FlinkJobNotFoundException(jobId)));
+        final CompletableFuture<Void> applicationFuture =
+                runApplication(dispatcherBuilder, configurationUnderTest, 1);
+        applicationFuture.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+    }
+
+    @Test
+    public void testDuplicateJobSubmissionWithRunningJobId() throws Throwable {
+        final JobID testJobID = new JobID(0, 2);
+        final Configuration configurationUnderTest = getConfiguration();
+        configurationUnderTest.set(
+                PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID, 
testJobID.toHexString());
+        configurationUnderTest.set(
+                HighAvailabilityOptions.HA_MODE, 
HighAvailabilityMode.ZOOKEEPER.name());
+        final TestingDispatcherGateway.Builder dispatcherBuilder =
+                new TestingDispatcherGateway.Builder()
+                        .setSubmitFunction(
+                                jobGraph -> {
+                                    final CompletableFuture<Acknowledge> 
submit =
+                                            new CompletableFuture<>();
+                                    submit.completeExceptionally(
+                                            
DuplicateJobSubmissionException.of(testJobID));
+                                    return submit;

Review comment:
       👍 




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to