wangyang0918 commented on code in PR #20673:
URL: https://github.com/apache/flink/pull/20673#discussion_r955901418


##########
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/highavailability/KubernetesStateHandleStoreTest.java:
##########
@@ -1119,4 +1166,34 @@ private TestingLongStateHandleHelper.LongStateHandle 
addDeletingEntry(
         configMap.getData().put(key, deleting);
         return state;
     }
+
+    private static CompletableFuture<Boolean> retryWithFirstFailedK8sOperation(
+            Function<KubernetesConfigMap, Optional<KubernetesConfigMap>> 
function,
+            KubernetesConfigMap leaderConfigMap) {
+        final AtomicInteger callbackInvocationCount = new AtomicInteger(0);
+        final CompletableFuture<Boolean> result =
+                FutureUtils.retry(
+                        () ->
+                                CompletableFuture.supplyAsync(
+                                        () -> {
+                                            
callbackInvocationCount.incrementAndGet();
+                                            function.apply(leaderConfigMap);
+                                            if (callbackInvocationCount.get() 
== 1) {
+                                                throw new 
KubernetesClientException(
+                                                        "Expected exception to 
simulate unstable "
+                                                                + "kubernetes 
client operation");
+                                            }
+                                            return true;
+                                        },
+                                        Executors.newDirectExecutorService()),
+                        
KubernetesConfigOptions.KUBERNETES_TRANSACTIONAL_OPERATION_MAX_RETRIES
+                                .defaultValue(),
+                        t ->
+                                ExceptionUtils.findThrowable(t, 
KubernetesClientException.class)
+                                        .isPresent(),
+                        Executors.newDirectExecutorService());
+        assertThat(callbackInvocationCount.get(), is(2));
+        assertThat(result.isDone(), is(true));

Review Comment:
   It seems that I find something.
   
   ```
       /**
        * Returns {@code true} if this task completed.
        *
        * Completion may be due to normal termination, an exception, or
        * cancellation -- in all of these cases, this method will return
        * {@code true}.
        *
        * @return {@code true} if this task completed
        */
       boolean isDone();
   ```



##########
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/highavailability/KubernetesStateHandleStoreTest.java:
##########
@@ -1119,4 +1166,34 @@ private TestingLongStateHandleHelper.LongStateHandle 
addDeletingEntry(
         configMap.getData().put(key, deleting);
         return state;
     }
+
+    private static CompletableFuture<Boolean> retryWithFirstFailedK8sOperation(
+            Function<KubernetesConfigMap, Optional<KubernetesConfigMap>> 
function,
+            KubernetesConfigMap leaderConfigMap) {
+        final AtomicInteger callbackInvocationCount = new AtomicInteger(0);
+        final CompletableFuture<Boolean> result =
+                FutureUtils.retry(
+                        () ->
+                                CompletableFuture.supplyAsync(
+                                        () -> {
+                                            
callbackInvocationCount.incrementAndGet();
+                                            function.apply(leaderConfigMap);
+                                            if (callbackInvocationCount.get() 
== 1) {
+                                                throw new 
KubernetesClientException(
+                                                        "Expected exception to 
simulate unstable "
+                                                                + "kubernetes 
client operation");
+                                            }
+                                            return true;
+                                        },
+                                        Executors.newDirectExecutorService()),
+                        
KubernetesConfigOptions.KUBERNETES_TRANSACTIONAL_OPERATION_MAX_RETRIES
+                                .defaultValue(),
+                        t ->
+                                ExceptionUtils.findThrowable(t, 
KubernetesClientException.class)
+                                        .isPresent(),
+                        Executors.newDirectExecutorService());
+        assertThat(callbackInvocationCount.get(), is(2));
+        assertThat(result.isDone(), is(true));

Review Comment:
   Given that the exception of the `result` will be eventually thrown in the 
`addAndLock`, I do not think it is really necessary to check exception here. 
But it should be harmless.
   
   ```
           try {
               assertThat(result.get(), is(true));
           } catch (Exception ex) {
               fail("Exception should not be thrown.");
           }
   ```



##########
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/highavailability/KubernetesStateHandleStoreTest.java:
##########
@@ -1119,4 +1166,34 @@ private TestingLongStateHandleHelper.LongStateHandle 
addDeletingEntry(
         configMap.getData().put(key, deleting);
         return state;
     }
+
+    private static CompletableFuture<Boolean> retryWithFirstFailedK8sOperation(
+            Function<KubernetesConfigMap, Optional<KubernetesConfigMap>> 
function,
+            KubernetesConfigMap leaderConfigMap) {
+        final AtomicInteger callbackInvocationCount = new AtomicInteger(0);
+        final CompletableFuture<Boolean> result =
+                FutureUtils.retry(
+                        () ->
+                                CompletableFuture.supplyAsync(
+                                        () -> {
+                                            
callbackInvocationCount.incrementAndGet();
+                                            function.apply(leaderConfigMap);
+                                            if (callbackInvocationCount.get() 
== 1) {
+                                                throw new 
KubernetesClientException(
+                                                        "Expected exception to 
simulate unstable "
+                                                                + "kubernetes 
client operation");
+                                            }
+                                            return true;
+                                        },
+                                        Executors.newDirectExecutorService()),
+                        
KubernetesConfigOptions.KUBERNETES_TRANSACTIONAL_OPERATION_MAX_RETRIES
+                                .defaultValue(),
+                        t ->
+                                ExceptionUtils.findThrowable(t, 
KubernetesClientException.class)
+                                        .isPresent(),
+                        Executors.newDirectExecutorService());
+        assertThat(callbackInvocationCount.get(), is(2));
+        assertThat(result.isDone(), is(true));

Review Comment:
   The above codes may hide the exception of future. Maybe I need to throw the 
exception directly in `retryWithFirstFailedK8sOperation`.



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