reswqa commented on code in PR #22140:
URL: https://github.com/apache/flink/pull/22140#discussion_r1131374096


##########
flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/core/testutils/FlinkAssertionsTest.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.core.testutils;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Test suite for {@link FlinkAssertions}. */
+public class FlinkAssertionsTest {

Review Comment:
   ```suggestion
   class FlinkAssertionsTest {
   ```
   Public test class are no longer recommended in Junit5 unless there are other 
reasons.



##########
flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/FlinkAssertions.java:
##########
@@ -139,4 +143,29 @@ public static Stream<Throwable> chainOfCauses(Throwable 
throwable) {
         }
         return Stream.concat(Stream.of(throwable), 
chainOfCauses(throwable.getCause()));
     }
+
+    /**
+     * Create assertion for {@link java.util.concurrent.CompletableFuture}.
+     *
+     * @param actual the actual value.
+     * @param <T> the type of the value contained in the {@link
+     *     java.util.concurrent.CompletableFuture}.
+     * @return the created assertion object.
+     */
+    public static <T> FlinkCompletableFutureAssert<T> assertThatFuture(
+            CompletableFuture<T> actual) {
+        return new FlinkCompletableFutureAssert<>(actual);
+    }
+
+    /**
+     * Create assertion for {@link java.util.concurrent.CompletableFuture}.

Review Comment:
   ```suggestion
        * Create assertion for {@link java.util.concurrent.CompletionStage}.
   ```



##########
flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/FlinkAssertions.java:
##########
@@ -25,11 +25,11 @@
 import org.assertj.core.api.ListAssert;
 import org.assertj.core.api.ThrowingConsumer;
 
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
 import java.util.function.Function;
 import java.util.stream.Stream;
 
-import static org.assertj.core.api.Assertions.assertThat;

Review Comment:
   Why we need remove this static import.



##########
flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/FlinkCompletableFutureAssert.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.core.testutils;
+
+import org.assertj.core.api.AbstractCompletableFutureAssert;
+import org.assertj.core.api.AssertionInfo;
+import org.assertj.core.api.ObjectAssert;
+import org.assertj.core.api.ThrowableAssertAlternative;
+import org.assertj.core.error.BasicErrorMessageFactory;
+import org.assertj.core.internal.Failures;
+import org.assertj.core.internal.Objects;
+
+import java.time.Duration;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+/**
+ * Enhanced version of {@link org.assertj.core.api.CompletableFutureAssert}, 
that allows asserting
+ * futures without relying on timeouts.
+ *
+ * @param <T> type of the value contained in the {@link CompletableFuture}.
+ */
+public class FlinkCompletableFutureAssert<T>
+        extends 
AbstractCompletableFutureAssert<FlinkCompletableFutureAssert<T>, T> {
+
+    private static final String SHOULD_HAVE_SUCCEEDED = "%nExpecting%n  
<%s>%nto have succeeded.%n";
+
+    private static final String SHOULD_HAVE_FAILED = "%nExpecting%n  <%s>%nto 
have failed.%n";
+
+    FlinkCompletableFutureAssert(CompletableFuture<T> actual) {
+        super(actual, FlinkCompletableFutureAssert.class);
+    }
+
+    FlinkCompletableFutureAssert(CompletionStage<T> actual) {
+        super(actual.toCompletableFuture(), 
FlinkCompletableFutureAssert.class);
+    }
+
+    /**
+     * An equivalent of {@link #succeedsWithin(Duration)}, that doesn't rely 
on timeouts.
+     *
+     * @return a new assertion object on the future's result
+     */
+    public ObjectAssert<T> eventuallySucceeds() {
+        final T object = assertEventuallySucceeds(info, actual);
+        return new ObjectAssert<>(object);
+    }
+
+    /**
+     * An equivalent of {@link #failsWithin(Duration)}, that doesn't rely on 
timeouts.
+     *
+     * @param exceptionClass type of the exception we expect the future to 
complete with
+     * @return a new assertion instance on the future's exception.
+     * @param <E> type of the exception we expect the future to complete with
+     */
+    public <E extends Throwable> ThrowableAssertAlternative<E> 
eventuallyFailsWith(

Review Comment:
   Do we also need an overload method that only assert this future eventually 
fails but not validate the exception class.



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