rkhachatryan commented on code in PR #22140: URL: https://github.com/apache/flink/pull/22140#discussion_r1131368401
########## 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: Should we also test for incomplete futures? Something like ``` @Test @Timeout(1L) void testEventuallySucceedsTimesOut() { assertThatFuture(new CompletableFuture()).eventuallySucceeds(); } ``` ########## 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 { + + @Test + void testEventuallySucceedsWithCompletedFuture() { + final CompletableFuture<String> completedFuture = + CompletableFuture.completedFuture("Apache Flink"); + assertThatFuture(completedFuture).eventuallySucceeds().isEqualTo("Apache Flink"); + } + + @Test + void testEventuallySucceedsWithFailedFuture() { + final CompletableFuture<String> failedFuture = new CompletableFuture<>(); + failedFuture.completeExceptionally(new IllegalStateException()); + assertThatThrownBy(() -> assertThatFuture(failedFuture).eventuallySucceeds()) + .hasMessageContaining("to have succeeded"); Review Comment: What do you think about testing the error message for containing some string - specified in the test? That would not depend less on the internals of the `FlinkCompletableFutureAssert`. ```suggestion failedFuture.completeExceptionally(new IllegalStateException("abcd")); assertThatThrownBy(() -> assertThatFuture(failedFuture).eventuallySucceeds()) .hasMessageContaining("abcd"); ``` (ditto: `"to have failed"`) ########## 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 { + + @Test + void testEventuallySucceedsWithCompletedFuture() { + final CompletableFuture<String> completedFuture = + CompletableFuture.completedFuture("Apache Flink"); + assertThatFuture(completedFuture).eventuallySucceeds().isEqualTo("Apache Flink"); + } + + @Test + void testEventuallySucceedsWithFailedFuture() { + final CompletableFuture<String> failedFuture = new CompletableFuture<>(); + failedFuture.completeExceptionally(new IllegalStateException()); + assertThatThrownBy(() -> assertThatFuture(failedFuture).eventuallySucceeds()) + .hasMessageContaining("to have succeeded"); + } + + @Test + void testEventuallyFailsWithCompletedFuture() { + final CompletableFuture<String> completedFuture = + CompletableFuture.completedFuture("Apache Flink"); + assertThatThrownBy( + () -> + assertThatFuture(completedFuture) + .eventuallyFailsWith(IllegalStateException.class)) + .hasMessageContaining("to have failed"); Review Comment: Does it make sense to verify that an `AssertionError` is thrown? A usual (non-error) exception might be handled by Flink `catch` blocks.. -- 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-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org