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


##########
flink-runtime/src/test/java/org/apache/flink/runtime/checkpoint/channel/ChannelStateChunkReaderTest.java:
##########
@@ -34,61 +34,68 @@
 import java.util.List;
 
 import static org.apache.flink.util.Preconditions.checkArgument;
-import static org.apache.flink.util.Preconditions.checkState;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
 
 /** {@link ChannelStateChunkReader} test. */
-public class ChannelStateChunkReaderTest {
+class ChannelStateChunkReaderTest {
 
-    @Test(expected = TestException.class)
-    public void testBufferRecycledOnFailure() throws IOException, 
InterruptedException {
+    @Test
+    void testBufferRecycledOnFailure() {
         FailingChannelStateSerializer serializer = new 
FailingChannelStateSerializer();
         TestRecoveredChannelStateHandler handler = new 
TestRecoveredChannelStateHandler();
 
-        try (FSDataInputStream stream = getStream(serializer, 10)) {
-            new ChannelStateChunkReader(serializer)
-                    .readChunk(stream, serializer.getHeaderLength(), handler, 
"channelInfo", 0);
-        } finally {
-            checkState(serializer.failed);
-            checkState(!handler.requestedBuffers.isEmpty());
-            assertTrue(
-                    handler.requestedBuffers.stream()
-                            .allMatch(TestChannelStateByteBuffer::isRecycled));
-        }
+        assertThatThrownBy(
+                        () -> {
+                            try (FSDataInputStream stream = 
getStream(serializer, 10)) {
+                                new ChannelStateChunkReader(serializer)
+                                        .readChunk(
+                                                stream,
+                                                serializer.getHeaderLength(),
+                                                handler,
+                                                "channelInfo",
+                                                0);
+                            } finally {
+                                assertThat(serializer.failed).isTrue();
+                                assertThat(handler.requestedBuffers)
+                                        .isNotEmpty()
+                                        
.allMatch(TestChannelStateByteBuffer::isRecycled);
+                            }
+                        })
+                .isInstanceOf(TestException.class);

Review Comment:
   I like the idea that the assert's callback should be as small as possible to 
avoid asserting other code locations by accident. Thanks @XComp for pointing 
this out, big +1 for this!



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

Reply via email to