RocMarshal commented on code in PR #21368:
URL: https://github.com/apache/flink/pull/21368#discussion_r1031512222
##########
flink-runtime/src/test/java/org/apache/flink/runtime/checkpoint/channel/ChannelStateChunkReaderTest.java:
##########
@@ -34,61 +34,67 @@
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();
+ assertThat(handler.requestedBuffers)
+
.allMatch(TestChannelStateByteBuffer::isRecycled);
Review Comment:
```suggestion
assertThat(handler.requestedBuffers).isNotEmpty()
.allMatch(TestChannelStateByteBuffer::isRecycled);
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/checkpoint/channel/RecordingChannelStateWriter.java:
##########
@@ -32,8 +32,9 @@
public class RecordingChannelStateWriter extends MockChannelStateWriter {
private long lastStartedCheckpointId = -1;
private long lastFinishedCheckpointId = -1;
Review Comment:
Could this line be removed ?
##########
flink-runtime/src/test/java/org/apache/flink/runtime/checkpoint/channel/InputChannelRecoveredStateHandlerTest.java:
##########
@@ -27,23 +27,23 @@
import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate;
import
org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.util.HashSet;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test of different implementation of {@link
InputChannelRecoveredStateHandler}. */
-public class InputChannelRecoveredStateHandlerTest extends
RecoveredChannelStateHandlerTest {
+class InputChannelRecoveredStateHandlerTest extends
RecoveredChannelStateHandlerTest {
private static final int preAllocatedSegments = 3;
private NetworkBufferPool networkBufferPool;
private SingleInputGate inputGate;
private InputChannelRecoveredStateHandler icsHander;
Review Comment:
```suggestion
private InputChannelRecoveredStateHandler icsHandler;
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/checkpoint/channel/ChannelStateChunkReaderTest.java:
##########
@@ -34,61 +34,67 @@
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();
+ assertThat(handler.requestedBuffers)
+
.allMatch(TestChannelStateByteBuffer::isRecycled);
+ }
+ })
+ .isInstanceOf(TestException.class);
}
@Test
- public void testBufferRecycledOnSuccess() throws IOException,
InterruptedException {
+ void testBufferRecycledOnSuccess() throws IOException,
InterruptedException {
ChannelStateSerializer serializer = new ChannelStateSerializerImpl();
TestRecoveredChannelStateHandler handler = new
TestRecoveredChannelStateHandler();
try (FSDataInputStream stream = getStream(serializer, 10)) {
new ChannelStateChunkReader(serializer)
.readChunk(stream, serializer.getHeaderLength(), handler,
"channelInfo", 0);
} finally {
- checkState(!handler.requestedBuffers.isEmpty());
- assertTrue(
- handler.requestedBuffers.stream()
- .allMatch(TestChannelStateByteBuffer::isRecycled));
+ assertThat(handler.requestedBuffers).isNotEmpty();
+
assertThat(handler.requestedBuffers).allMatch(TestChannelStateByteBuffer::isRecycled);
Review Comment:
```suggestion
assertThat(handler.requestedBuffers)
.isNotEmpty()
.allMatch(TestChannelStateByteBuffer::isRecycled);
```
--
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]