[GitHub] [flink] reswqa commented on a diff in pull request #21999: [FLINK-29816][streaming] Fix the bug that StreamTask doesn't handle exception during restoring

2023-02-25 Thread via GitHub


reswqa commented on code in PR #21999:
URL: https://github.com/apache/flink/pull/21999#discussion_r1117930702


##
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 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 ->
+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 ->
+ExceptionUtils.assertThrowable(
+throwable,
+
FailingTwiceOperator.CloseException.class));

Review Comment:
   Good suggestion @1996fanrui, Make sense to me.



-- 
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



[GitHub] [flink] reswqa commented on a diff in pull request #21999: [FLINK-29816][streaming] Fix the bug that StreamTask doesn't handle exception during restoring

2023-02-23 Thread via GitHub


reswqa commented on code in PR #21999:
URL: https://github.com/apache/flink/pull/21999#discussion_r1116565034


##
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 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:
   We don't need to go back to the original implementation. You can see my last 
comment.



-- 
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



[GitHub] [flink] reswqa commented on a diff in pull request #21999: [FLINK-29816][streaming] Fix the bug that StreamTask doesn't handle exception during restoring

2023-02-23 Thread via GitHub


reswqa commented on code in PR #21999:
URL: https://github.com/apache/flink/pull/21999#discussion_r1116563643


##
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##
@@ -368,17 +368,19 @@ void testCleanUpExceptionSuppressing() throws Exception {
 .setupOutputForSingletonOperatorChain(new 
FailingTwiceOperator())
 .build()) {
 
-assertThatThrownBy(
-() -> {
-testHarness.processElement(new 
StreamRecord<>("Doesn't matter", 0));
-throw new RuntimeException(
-"Expected an exception but ran 
successfully");
-})
-.isInstanceOf(ExpectedTestException.class);
+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);
+}

Review Comment:
   ```suggestion
   Assertions.assertThatThrownBy(
   () ->
   testHarness.processElement(
   new StreamRecord<>("Doesn't 
matter", 0)))
   .satisfies(
   throwable ->
   ExceptionUtils.assertThrowable(
   throwable, 
ExpectedTestException.class));
   ```
   



-- 
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



[GitHub] [flink] reswqa commented on a diff in pull request #21999: [FLINK-29816][streaming] Fix the bug that StreamTask doesn't handle exception during restoring

2023-02-23 Thread via GitHub


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 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> consu
 StreamTaskMailboxTestHarness 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 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

[GitHub] [flink] reswqa commented on a diff in pull request #21999: [FLINK-29816][streaming] Fix the bug that StreamTask doesn't handle exception during restoring

2023-02-23 Thread via GitHub


reswqa commented on code in PR #21999:
URL: https://github.com/apache/flink/pull/21999#discussion_r1115766066


##
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##
@@ -410,6 +410,42 @@ public CloseException() {
 }
 }
 
+@Test
+public void testAsyncExceptionCanBeHandledDuringRestoring() throws 
Exception {

Review Comment:
   This is just my personal preference, and the current name is also acceptable.



-- 
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



[GitHub] [flink] reswqa commented on a diff in pull request #21999: [FLINK-29816][streaming] Fix the bug that StreamTask doesn't handle exception during restoring

2023-02-23 Thread via GitHub


reswqa commented on code in PR #21999:
URL: https://github.com/apache/flink/pull/21999#discussion_r1115754252


##
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##
@@ -410,6 +410,42 @@ public CloseException() {
 }
 }
 
+@Test
+public void testAsyncExceptionCanBeHandledDuringRestoring() throws 
Exception {

Review Comment:
   ```suggestion
   public void testHandleAsyncExceptionDuringRestoring() throws Exception {
   ```



##
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##
@@ -410,6 +410,42 @@ public CloseException() {
 }
 }
 
+@Test
+public void testAsyncExceptionCanBeHandledDuringRestoring() throws 
Exception {
+MockEnvironment mockEnvironment = MockEnvironment.builder().build();
+RuntimeException expectedException = new RuntimeException("RUNTIME 
EXCEPTION");
+
+
mockEnvironment.setExpectedExternalFailureCause(AsynchronousException.class);
+final String expectedErrorMessage = "EXPECTED_ERROR MESSAGE";
+
+StreamTaskITCase.NoOpStreamTask noOpStreamTask =

Review Comment:
   This is indeed not no-op, maybe should call it `initThrowExceptionTask` or 
other more appropriate name



##
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##
@@ -410,6 +410,42 @@ public CloseException() {
 }
 }
 
+@Test
+public void testAsyncExceptionCanBeHandledDuringRestoring() throws 
Exception {
+MockEnvironment mockEnvironment = MockEnvironment.builder().build();
+RuntimeException expectedException = new RuntimeException("RUNTIME 
EXCEPTION");

Review Comment:
   ```suggestion
   Throwable expectedException = new RuntimeException("RUNTIME 
EXCEPTION");
   ```



-- 
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