dmvk commented on a change in pull request #17967:
URL: https://github.com/apache/flink/pull/17967#discussion_r761879430
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/DefaultJobMasterServiceProcessTest.java
##########
@@ -63,11 +64,100 @@ public void
testInitializationFailureCompletesResultFuture() {
final RuntimeException originalCause = new RuntimeException("Init
error");
jobMasterServiceFuture.completeExceptionally(originalCause);
-
assertTrue(serviceProcess.getResultFuture().join().isInitializationFailure());
- final Throwable initializationFailure =
-
serviceProcess.getResultFuture().join().getInitializationFailure();
- assertThat(initializationFailure,
containsCause(JobInitializationException.class));
- assertThat(initializationFailure, containsCause(originalCause));
+ final JobManagerRunnerResult actualJobManagerResult =
+ serviceProcess.getResultFuture().join();
+ assertThat(actualJobManagerResult.isInitializationFailure()).isTrue();
+ final Throwable initializationFailure =
actualJobManagerResult.getInitializationFailure();
+
+ assertThat(initializationFailure)
+ .satisfies(
+ t ->
+ assertThat(
+ ExceptionUtils.findThrowable(
+ t,
JobInitializationException.class)
+ .isPresent())
+ .isTrue());
+ FlinkAsserts.assertThat(initializationFailure)
+ .containsCause(JobInitializationException.class);
+
FlinkAsserts.assertThat(initializationFailure).containsCause(originalCause);
Review comment:
```suggestion
assertThat(actualJobManagerResult.getInitializationFailure())
.isInstanceOf(JobInitializationException.class)
.hasCause(originalCause);
```
##########
File path:
flink-core/src/test/java/org/apache/flink/testutils/assertj/FlinkAsserts.java
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.testutils.assertj;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * {@code FlinkAsserts} collect {@code assertThat} factory methods for any
custom {@link
+ * org.assertj.core.api.AbstractAssert} implementation.
+ */
+public class FlinkAsserts {
+
+ public static CauseTreeContainsAssert assertThat(Throwable
actualThrowable) {
+ return new CauseTreeContainsAssert(actualThrowable);
+ }
+
+ public static <T> FlinkCompletableFutureAssert<T>
assertThat(CompletableFuture<T> actual) {
+ return new FlinkCompletableFutureAssert<>(actual);
+ }
Review comment:
```suggestion
private static final InstanceOfAssertFactory<Throwable,
CauseTreeContainsAssert> CAUSE_TREE_FACTORY =
new InstanceOfAssertFactory<>(
Throwable.class,
CauseTreeContainsAssert::new);
public static InstanceOfAssertFactory<Throwable,
CauseTreeContainsAssert> exceptionHierarchy() {
return CAUSE_TREE_FACTORY;
}
```
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/DefaultJobMasterServiceProcessTest.java
##########
@@ -188,15 +275,17 @@ public void testSuccessOnTerminalState() throws Exception
{
serviceProcess.jobReachedGloballyTerminalState(
new ExecutionGraphInfo(archivedExecutionGraph));
- assertThat(serviceProcess.getResultFuture().get().isSuccess(),
is(true));
- assertThat(
- serviceProcess
- .getResultFuture()
- .get()
- .getExecutionGraphInfo()
- .getArchivedExecutionGraph()
- .getState(),
- is(JobStatus.FINISHED));
+ FlinkAsserts.assertThat(serviceProcess.getResultFuture())
+ .succeedsImmediately()
+ .extracting(JobManagerRunnerResult::isSuccess)
+ .isEqualTo(true);
+
+ FlinkAsserts.assertThat(serviceProcess.getResultFuture())
+ .succeedsImmediately()
+ .extracting(JobManagerRunnerResult::getExecutionGraphInfo)
+ .extracting(ExecutionGraphInfo::getArchivedExecutionGraph)
+ .extracting(ArchivedExecutionGraph::getState)
+ .isEqualTo(JobStatus.FINISHED);
Review comment:
```suggestion
assertThat(serviceProcess.getResultFuture())
.isCompletedWithValueMatching(
v ->
v.getExecutionGraphInfo().getArchivedExecutionGraph().getState()
== JobStatus.FINISHED);
```
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/DefaultJobMasterServiceProcessTest.java
##########
@@ -91,10 +181,10 @@ public void testCloseAfterInitializationSuccess() throws
Exception {
jobMasterServiceFuture.complete(testingJobMasterService);
serviceProcess.closeAsync().get();
- assertThat(testingJobMasterService.isClosed(), is(true));
- assertThat(
- serviceProcess.getResultFuture(),
- futureWillCompleteExceptionally(JobNotFinishedException.class,
TIMEOUT));
+ assertThat(testingJobMasterService.isClosed()).isTrue();
+ FlinkAsserts.assertThat(serviceProcess.getResultFuture())
+ .failsWithThrowable(TIMEOUT)
+ .containsCause(JobNotFinishedException.class);
Review comment:
```suggestion
assertThat(serviceProcess.getResultFuture())
.failsWithin(TIMEOUT)
.withThrowableOfType(ExecutionException.class)
.withCauseInstanceOf(JobNotFinishedException.class);
```
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/DefaultJobMasterServiceProcessTest.java
##########
@@ -110,17 +200,14 @@ public void testJobMasterTerminationIsHandled() {
RuntimeException testException = new RuntimeException("Fake exception
from JobMaster");
jobMasterTerminationFuture.completeExceptionally(testException);
- try {
- serviceProcess.getResultFuture().get();
- fail("Expect failure");
- } catch (Throwable t) {
- assertThat(t, containsCause(RuntimeException.class));
- assertThat(t, containsMessage(testException.getMessage()));
- }
+ FlinkAsserts.assertThat(serviceProcess.getResultFuture())
+ .failsImmediately()
+ .containsCause(RuntimeException.class)
+ .containsCauseWithMessage(testException.getMessage());
Review comment:
```suggestion
assertThat(serviceProcess.getResultFuture())
.failsWithin(TIMEOUT)
.withThrowableOfType(ExecutionException.class)
.asInstanceOf(FlinkAsserts.exceptionHierarchy())
.containsCause(testException);
```
--
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]