1996fanrui commented on code in PR #21999:
URL: https://github.com/apache/flink/pull/21999#discussion_r1116676401
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -1103,35 +1143,41 @@ 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();
+
+ harness.streamTask.triggerCheckpointOnBarrier(
+ new CheckpointMetaData(1, 0),
+
CheckpointOptions.forCheckpointWithDefaultLocation(),
+ new CheckpointMetricsBuilder());
+ })
+ .satisfies(
+ (Consumer<Throwable>)
+ throwable ->
+
ExceptionUtils.assertThrowableWithMessage(
+ throwable,
+ "OperatorChain and Task
should never be closed at this point"));
Review Comment:
```suggestion
.hasMessage("OperatorChain and Task should never be
closed at this point");
```
I'm not sure, please correct me if it doesn't work.
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -1182,13 +1228,13 @@ public void testThreadInvariants() throws Throwable {
});
runningTask.invocationFuture.get();
- assertThat(
- runningTask.streamTask.getTaskClassLoader(),
is(sameInstance(taskClassLoader)));
+
assertThat(runningTask.streamTask.getTaskClassLoader()).isSameAs(taskClassLoader);
+
assertThat(runningTask.streamTask.getTaskClassLoader()).isSameAs(taskClassLoader);
Review Comment:
```suggestion
assertThat(runningTask.streamTask.getTaskClassLoader()).isSameAs(taskClassLoader);
```
Is it repeated?
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -1103,35 +1143,41 @@ 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:
Could these lines be moved outside of `assertThatThrownBy`?
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -1562,12 +1604,12 @@ public void testSkipRepeatCheckpointComplete() throws
Exception {
CheckpointCompleteRecordOperator operator =
(CheckpointCompleteRecordOperator)
(AbstractStreamOperator<?>)
testHarness.streamTask.getMainOperator();
- assertEquals(Arrays.asList(3L, 8L),
operator.getNotifiedCheckpoint());
+ assertThat(Arrays.asList(3L,
8L)).isEqualTo(operator.getNotifiedCheckpoint());
Review Comment:
```suggestion
assertThat(operator.getNotifiedCheckpoint()).isEqualTo(Arrays.asList(3L, 8L));
```
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -945,12 +982,15 @@ public void
testAsyncCheckpointingConcurrentCloseBeforeAcknowledge() throws Exce
// make sure that all state handles have been discarded
discardFuture.get();
- try {
- mockEnvironment.getAcknowledgeCheckpointFuture().get(10L,
TimeUnit.MILLISECONDS);
- fail("The checkpoint should not get acknowledged.");
- } catch (TimeoutException expected) {
- // future should not be completed
- }
+ assertThatThrownBy(
+ () -> {
+ // future should not be completed
+ mockEnvironment
+ .getAcknowledgeCheckpointFuture()
+ .get(10L, TimeUnit.MILLISECONDS);
+ fail("The checkpoint should not get
acknowledged.");
Review Comment:
```suggestion
```
Can this line be removed? I remember if it doesn't throw expected
exception, `assertThatThrownBy` will fail, right?
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -1587,12 +1629,12 @@ public void testIgnoreCompleteCheckpointBeforeStartup()
throws Exception {
CheckpointCompleteRecordOperator operator =
(CheckpointCompleteRecordOperator)
(AbstractStreamOperator<?>)
testHarness.streamTask.getMainOperator();
- assertEquals(Arrays.asList(5L, 6L),
operator.getNotifiedCheckpoint());
+ assertThat(Arrays.asList(5L,
6L)).isEqualTo(operator.getNotifiedCheckpoint());
Review Comment:
```suggestion
assertThat(operator.getNotifiedCheckpoint()).isEqualTo(Arrays.asList(5L, 6L));
```
--
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]