Myasuka commented on code in PR #20860:
URL: https://github.com/apache/flink/pull/20860#discussion_r978298212
##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/memory/ByteStreamStateHandleTest.java:
##########
@@ -172,4 +172,15 @@ public void testBulkReadINdexOutOfBounds() throws
IOException {
// expected
}
}
+
+ @Test
+ public void testStreamWithEmptyByteArray() throws IOException {
+ final byte[] data = new byte[0];
+ final ByteStreamStateHandle handle = new ByteStreamStateHandle("name",
data);
+
+ FSDataInputStream in = handle.openInputStream();
Review Comment:
This input stream could be closed properly.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/memory/ByteStreamStateHandleTest.java:
##########
@@ -172,4 +172,15 @@ public void testBulkReadINdexOutOfBounds() throws
IOException {
// expected
}
}
+
+ @Test
+ public void testStreamWithEmptyByteArray() throws IOException {
+ final byte[] data = new byte[0];
+ final ByteStreamStateHandle handle = new ByteStreamStateHandle("name",
data);
+
+ FSDataInputStream in = handle.openInputStream();
+ in.seek(0);
Review Comment:
Why we need to seek to the 1st position?
##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/memory/ByteStreamStateHandleTest.java:
##########
@@ -172,4 +172,15 @@ public void testBulkReadINdexOutOfBounds() throws
IOException {
// expected
}
}
+
+ @Test
+ public void testStreamWithEmptyByteArray() throws IOException {
+ final byte[] data = new byte[0];
+ final ByteStreamStateHandle handle = new ByteStreamStateHandle("name",
data);
+
+ FSDataInputStream in = handle.openInputStream();
+ in.seek(0);
+ byte[] dataGot = new byte[1];
+ assertEquals(0, in.read(dataGot, 0, 0));
Review Comment:
Do we need to test `assertEquals(0, in.read());`?
##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/memory/ByteStreamStateHandle.java:
##########
@@ -148,7 +148,7 @@ public int read(byte[] b, int off, int len) throws
IOException {
index += bytesToCopy;
return bytesToCopy;
} else {
- return -1;
+ return len == 0 ? 0 : -1;
Review Comment:
Do we need to change the returning result of `#read()`?
--
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]