wolfboys commented on code in PR #2243:
URL: 
https://github.com/apache/incubator-streampark/pull/2243#discussion_r1066861534


##########
streampark-console/streampark-console-service/src/test/java/org/apache/org/apache/streampark/common/util/CompletableFutureUtilsTest.java:
##########
@@ -143,4 +150,73 @@ private String runStart(int sec) {
     }
     return "start successful";
   }
+
+  @Test
+  public void thenSupplyNormally() throws Exception {
+    String successResult = "success";
+    String exceptionResult = "error";
+
+    String resp =
+        CompletableFutureUtils.supplyTimeout(
+                CompletableFuture.supplyAsync(() -> successResult),
+                1,
+                TimeUnit.SECONDS,
+                success -> success,
+                e -> exceptionResult)
+            .thenApply(r -> r)
+            .get();
+
+    Assertions.assertEquals(resp, successResult);
+  }
+
+  @Test
+  public void thenSupplyTimeout() throws Exception {
+    String successResult = "success";
+    String exceptionResult = "error";
+    CompletableFuture<String> future =
+        CompletableFuture.supplyAsync(
+            () -> {
+              try {
+                Thread.sleep(5000);
+              } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+              }
+              return successResult;
+            });
+    String resp =
+        CompletableFutureUtils.supplyTimeout(
+                future, 1, TimeUnit.SECONDS, success -> success, e -> 
exceptionResult)
+            .thenApply(r -> r)
+            .get();
+    Assertions.assertEquals(resp, exceptionResult);
+  }
+
+  @Test
+  public void thenSupplyException() {
+    String expectedExceptionMessage = "Exception in exceptionally handler";
+    int processTime = 5000;
+    int timeOut = 1000;
+    CompletableFuture<String> future =
+        CompletableFutureUtils.supplyTimeout(
+            CompletableFuture.supplyAsync(
+                () -> {
+                  try {
+                    Thread.sleep(processTime);
+                  } catch (InterruptedException e) {
+                    throw new RuntimeException(e);
+                  }
+                  return "success";
+                }),
+            timeOut,
+            TimeUnit.MILLISECONDS,
+            success -> success,
+            e -> {
+              throw new RuntimeException(expectedExceptionMessage);
+            });
+
+    assertThatThrownBy(future::get)
+        .hasMessageContaining(expectedExceptionMessage)
+        .hasCauseInstanceOf(RuntimeException.class)
+        .isInstanceOf(ExecutionException.class);

Review Comment:
   done



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