1996fanrui commented on code in PR #21999:
URL: https://github.com/apache/flink/pull/21999#discussion_r1117858061
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -362,30 +358,35 @@ private void testSyncSavepointWithEndInput(
"savepointResult");
harness.processAll();
- Assert.assertEquals(expectEndInput,
TestBoundedOneInputStreamOperator.isInputEnded());
+
assertThat(TestBoundedOneInputStreamOperator.isInputEnded()).isEqualTo(expectEndInput);
}
@Test
- public void testCleanUpExceptionSuppressing() throws Exception {
+ void testCleanUpExceptionSuppressing() throws Exception {
try (StreamTaskMailboxTestHarness<String> testHarness =
new
StreamTaskMailboxTestHarnessBuilder<>(OneInputStreamTask::new, STRING_TYPE_INFO)
.addInput(STRING_TYPE_INFO)
.setupOutputForSingletonOperatorChain(new
FailingTwiceOperator())
.build()) {
- try {
- testHarness.processElement(new StreamRecord<>("Doesn't
matter", 0));
- throw new RuntimeException("Expected an exception but ran
successfully");
- } catch (Exception ex) {
- ExceptionUtils.assertThrowable(ex,
ExpectedTestException.class);
- }
+ assertThatThrownBy(
+ () ->
+ testHarness.processElement(
+ new StreamRecord<>("Doesn't
matter", 0)))
+ .satisfies(
+ (Consumer<Throwable>)
+ throwable ->
+ ExceptionUtils.assertThrowable(
+ throwable,
ExpectedTestException.class));
- try {
- testHarness.finishProcessing();
- } catch (Exception ex) {
- // todo: checking for suppression if there are more exceptions
during cleanup
- ExceptionUtils.assertThrowable(ex,
FailingTwiceOperator.CloseException.class);
- }
+ // todo: checking for suppression if there are more exceptions
during cleanup
+ assertThatThrownBy(testHarness::finishProcessing)
+ .satisfies(
+ (ThrowingConsumer<Throwable>)
+ throwable ->
+ ExceptionUtils.assertThrowable(
+ throwable,
+
FailingTwiceOperator.CloseException.class));
Review Comment:
```suggestion
.satisfies(anyCauseMatches(FailingTwiceOperator.CloseException.class));
```
Hi @RocMarshal , thanks for your clarification, I got it.
Hi @reswqa , I found `FlinkAssertions.anyCauseMatches` is similar with
`ExceptionUtils.assertThrowable`, and it can find the throwable from more
deeper level, it's simpler than `ExceptionUtils.assertThrowable`.
What do you think? And please take a look these comments[1][2], they are
similar with this comment.
[1] https://github.com/apache/flink/pull/21999#discussion_r1117222444
[2] https://github.com/apache/flink/pull/21999#discussion_r1117225403
--
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]