1996fanrui commented on code in PR #2243:
URL: 
https://github.com/apache/incubator-streampark/pull/2243#discussion_r1065338938


##########
streampark-console/streampark-console-service/src/test/java/org/apache/org/apache/streampark/common/util/CompletableFutureUtilsTest.java:
##########
@@ -143,4 +147,77 @@ 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),
+                3,
+                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 resp;
+    String exResult = "exception";
+    try {
+      resp = exceptionally();

Review Comment:
   ```suggestion
         resp = exceptionally();
         fail("It should be called.");
   ```



##########
streampark-console/streampark-console-service/src/test/java/org/apache/org/apache/streampark/common/util/CompletableFutureUtilsTest.java:
##########
@@ -143,4 +147,77 @@ 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),
+                3,
+                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 resp;
+    String exResult = "exception";
+    try {
+      resp = exceptionally();
+    } catch (Exception e) {
+      resp = exResult;

Review Comment:
   We should check the exception type here instead of check the `exResult`.



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