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


##########
flink-core/src/test/java/org/apache/flink/api/common/io/BinaryInputFormatTest.java:
##########
@@ -73,13 +76,21 @@ public void testCreateInputSplitsWithOneFile() throws 
IOException {
 
         FileInputSplit[] inputSplits = 
inputFormat.createInputSplits(numBlocks);
 
-        Assert.assertEquals("Returns requested numbers of splits.", numBlocks, 
inputSplits.length);
-        Assert.assertEquals(
-                "1. split has block size length.", blockSize, 
inputSplits[0].getLength());
-        Assert.assertEquals(
-                "2. split has block size length.", blockSize, 
inputSplits[1].getLength());
-        Assert.assertEquals(
-                "3. split has block size length.", blockSize, 
inputSplits[2].getLength());
+        assertThat(inputSplits.length)

Review Comment:
   ```suggestion
          assertThat(inputSplits)
                   .as("Returns requested numbers of splits.")
                   .hasSize(numBlocks);
   ```



##########
flink-core/src/test/java/org/apache/flink/api/common/io/BinaryInputFormatTest.java:
##########
@@ -154,17 +170,60 @@ public void testGetStatisticsMultiplePaths() throws 
IOException {
         inputFormat.setBlockSize(blockSize);
 
         BaseStatistics stats = inputFormat.getStatistics(null);
-        Assert.assertEquals(
-                "The file size statistics is wrong",
-                blockSize * (numBlocks1 + numBlocks2),
-                stats.getTotalInputSize());
+
+        assertThat(stats.getTotalInputSize())
+                .as("The file size statistics is wrong")
+                .isEqualTo(blockSize * (numBlocks1 + numBlocks2));
+    }
+
+    @Test
+    public void testCreateInputSplitsWithEmptySplit() throws IOException {
+        final int blockInfoSize = new BlockInfo().getInfoSize();
+        final int blockSize = blockInfoSize + 8;
+        final int numBlocks = 3;
+        final int minNumSplits = 5;
+
+        // create temporary file with 3 blocks
+        final File tempFile =
+                createBinaryInputFile(
+                        "test_create_input_splits_with_empty_split", 
blockSize, numBlocks);
+
+        final Configuration config = new Configuration();
+        config.setLong("input.block_size", blockSize + 10);
+
+        final BinaryInputFormat<Record> inputFormat = new 
MyBinaryInputFormat();
+        inputFormat.setFilePath(tempFile.toURI().toString());
+        inputFormat.setBlockSize(blockSize);
+
+        inputFormat.configure(config);
+
+        FileInputSplit[] inputSplits = 
inputFormat.createInputSplits(minNumSplits);
+
+        assertThat(inputSplits.length)
+                .as("Returns requested numbers of splits.")
+                .isEqualTo(minNumSplits);
+
+        assertThat(inputSplits[0].getLength())
+                .as("1. split has block size length.")
+                .isEqualTo(blockSize);
+
+        assertThat(inputSplits[1].getLength())
+                .as("2. split has block size length.")
+                .isEqualTo(blockSize);
+
+        assertThat(inputSplits[2].getLength())
+                .as("3. split has block size length.")
+                .isEqualTo(blockSize);
+
+        assertThat(inputSplits[3].getLength()).as("4. split has block size 
length.").isEqualTo(0);
+
+        assertThat(inputSplits[4].getLength()).as("5. split has block size 
length.").isEqualTo(0);

Review Comment:
   ```suggestion
           assertThat(inputSplits[4].getLength()).as("5. split should be an 
empty split.").isZero();
   ```



##########
flink-core/src/test/java/org/apache/flink/api/common/io/BinaryInputFormatTest.java:
##########
@@ -154,17 +170,60 @@ public void testGetStatisticsMultiplePaths() throws 
IOException {
         inputFormat.setBlockSize(blockSize);
 
         BaseStatistics stats = inputFormat.getStatistics(null);
-        Assert.assertEquals(
-                "The file size statistics is wrong",
-                blockSize * (numBlocks1 + numBlocks2),
-                stats.getTotalInputSize());
+
+        assertThat(stats.getTotalInputSize())
+                .as("The file size statistics is wrong")
+                .isEqualTo(blockSize * (numBlocks1 + numBlocks2));
+    }
+
+    @Test
+    public void testCreateInputSplitsWithEmptySplit() throws IOException {
+        final int blockInfoSize = new BlockInfo().getInfoSize();
+        final int blockSize = blockInfoSize + 8;
+        final int numBlocks = 3;
+        final int minNumSplits = 5;
+
+        // create temporary file with 3 blocks
+        final File tempFile =
+                createBinaryInputFile(
+                        "test_create_input_splits_with_empty_split", 
blockSize, numBlocks);
+
+        final Configuration config = new Configuration();
+        config.setLong("input.block_size", blockSize + 10);
+
+        final BinaryInputFormat<Record> inputFormat = new 
MyBinaryInputFormat();
+        inputFormat.setFilePath(tempFile.toURI().toString());
+        inputFormat.setBlockSize(blockSize);
+
+        inputFormat.configure(config);
+
+        FileInputSplit[] inputSplits = 
inputFormat.createInputSplits(minNumSplits);
+
+        assertThat(inputSplits.length)
+                .as("Returns requested numbers of splits.")
+                .isEqualTo(minNumSplits);
+
+        assertThat(inputSplits[0].getLength())
+                .as("1. split has block size length.")

Review Comment:
   IMO, `as` is used to add description when this assert is not pass.
   The error message will be displayed in the following form:
   org.opentest4j.AssertionFailedError: [description in as()] 
   So I think the `as` description in these tests should be more accurate, such 
as
   "1. split should/must has block size length."



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

Reply via email to