You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "dmvk (via GitHub)" <gi...@apache.org> on 2023/03/10 12:27:48 UTC

[GitHub] [flink] dmvk commented on a diff in pull request #22140: [FLINK-31385] Introduce extended Assertj matchers for completable fut…

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


##########
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:
   We don't need it, be it would certainly be nice to have :) Added.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org