reswqa commented on code in PR #21999:
URL: https://github.com/apache/flink/pull/21999#discussion_r1116492529
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -362,30 +357,28 @@ 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));
+ throw new RuntimeException(
Review Comment:
Why throw exception here?
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -1085,27 +1081,27 @@ public void testNotifyCheckpointOnClosedOperator()
throws Throwable {
harness.streamTask.notifyCheckpointCompleteAsync(1);
harness.streamTask.runMailboxStep();
- assertEquals(1, ClosingOperator.notified.get());
- assertFalse(ClosingOperator.closed.get());
+ assertThat(ClosingOperator.notified.get()).isOne();
Review Comment:
IIRC, AssertJ does have specific assertions for `AtomicXXX`, please avoid
using `get`.
It is also necessary to check the similar problems of the whole test class.
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -1121,13 +1117,14 @@ private void
testFailToConfirmCheckpointMessage(Consumer<StreamTask<?, ?>> consu
StreamTaskMailboxTestHarness<Integer> harness =
builder.setupOutputForSingletonOperatorChain(streamMap).build();
- try {
- consumer.accept(harness.streamTask);
- harness.streamTask.runMailboxLoop();
- fail();
- } catch (ExpectedTestException expected) {
- // expected exceptionestProcessWithUnAvailableInput
- }
+ // expected exceptionestProcessWithUnAvailableInput
+ assertThatThrownBy(
+ () -> {
+ consumer.accept(harness.streamTask);
+ harness.streamTask.runMailboxLoop();
+ fail(null);
Review Comment:
Why we need `fail`?
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -362,30 +357,28 @@ 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));
+ throw new RuntimeException(
+ "Expected an exception but ran
successfully");
+ })
+ .isInstanceOf(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)
+ .isInstanceOf(FailingTwiceOperator.CloseException.class);
Review Comment:
Maybe we should check weather `ExceptionUtils.assertThrowable` will find
throwable into more deeper level, but `isInstanceOf` indeed only check the
throwable in the first level.
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -1139,35 +1136,38 @@ private void
testFailToConfirmCheckpointMessage(Consumer<StreamTask<?, ?>> consu
* finished.
*/
@Test
- public void testCheckpointFailueOnClosedOperator() throws Throwable {
+ void testCheckpointFailueOnClosedOperator() throws Exception {
ClosingOperator<Integer> operator = new ClosingOperator<>();
StreamTaskMailboxTestHarnessBuilder<Integer> builder =
new StreamTaskMailboxTestHarnessBuilder<>(
OneInputStreamTask::new,
BasicTypeInfo.INT_TYPE_INFO)
.addInput(BasicTypeInfo.INT_TYPE_INFO);
try (StreamTaskMailboxTestHarness<Integer> harness =
builder.setupOutputForSingletonOperatorChain(operator).build()) {
- // keeps the mailbox from suspending
- harness.setAutoProcess(false);
- harness.processElement(new StreamRecord<>(1));
-
- harness.streamTask.operatorChain.finishOperators(
- harness.streamTask.getActionExecutor(), StopMode.DRAIN);
- harness.streamTask.operatorChain.closeAllOperators();
- assertTrue(ClosingOperator.closed.get());
-
- harness.streamTask.triggerCheckpointOnBarrier(
- new CheckpointMetaData(1, 0),
- CheckpointOptions.forCheckpointWithDefaultLocation(),
- new CheckpointMetricsBuilder());
- } catch (Exception ex) {
- ExceptionUtils.assertThrowableWithMessage(
- ex, "OperatorChain and Task should never be closed at this
point");
+ assertThatThrownBy(
+ () -> {
+ // keeps the mailbox from suspending
+ harness.setAutoProcess(false);
+ harness.processElement(new StreamRecord<>(1));
+
+
harness.streamTask.operatorChain.finishOperators(
+
harness.streamTask.getActionExecutor(), StopMode.DRAIN);
+
harness.streamTask.operatorChain.closeAllOperators();
+
assertThat(ClosingOperator.closed.get()).isTrue();
Review Comment:
ditto.
--
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]