zhangshuyan0 commented on code in PR #6368:
URL: https://github.com/apache/hadoop/pull/6368#discussion_r1458246249


##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java:
##########
@@ -184,6 +186,40 @@ public void testPreventOverflow() throws IOException, 
NoSuchFieldException,
     runAdjustChunkBoundary(configuredWritePacketSize, finalWritePacketSize);
   }
 
+  @Test(timeout=60000)
+  public void testFirstPacketSizeInNewBlocks() throws IOException {
+    final long blockSize = 1L * 1024 * 1024;
+    final int numDataNodes = 3;
+    final Configuration dfsConf = new Configuration();
+    dfsConf.setLong(DFS_BLOCK_SIZE_KEY, blockSize);
+    MiniDFSCluster dfsCluster = null;
+    dfsCluster = new 
MiniDFSCluster.Builder(dfsConf).numDataNodes(numDataNodes).build();
+    dfsCluster.waitActive();
+
+    DistributedFileSystem fs = dfsCluster.getFileSystem();
+    Path fileName = new Path("/testfile.dat");
+    FSDataOutputStream fos = fs.create(fileName);
+    DataChecksum crc32c = 
DataChecksum.newDataChecksum(DataChecksum.Type.CRC32C, 512);
+
+    long loop = 0;
+    Random r = new Random();
+    byte[] buf = new byte[1 * 1024 * 1024];
+    r.nextBytes(buf);
+    fos.write(buf);
+    fos.hflush();
+
+    while (loop < 20) {
+      r.nextBytes(buf);
+      fos.write(buf);
+      fos.hflush();
+      loop++;
+      Assert.assertNotEquals(crc32c.getBytesPerChecksum() + 
crc32c.getChecksumSize(),

Review Comment:
   It is more appropriate to precisely specify the expected `packetSize` here.
   Outside the `while loop`:
   ```
   int chunkSize = crc32c.getBytesPerChecksum() + crc32c.getChecksumSize();
   int packetContentSize = (dfsConf.getInt(DFS_CLIENT_WRITE_PACKET_SIZE_KEY, 
DFS_CLIENT_WRITE_PACKET_SIZE_DEFAULT) - 
PacketHeader.PKT_MAX_HEADER_LEN)/chunkSize*chunkSize;
   ```
   And here:
   ```
   Assert.assertEquals(((DFSOutputStream) fos.getWrappedStream()).packetSize, 
packetContentSize);
   ```



##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java:
##########
@@ -184,6 +186,40 @@ public void testPreventOverflow() throws IOException, 
NoSuchFieldException,
     runAdjustChunkBoundary(configuredWritePacketSize, finalWritePacketSize);
   }
 
+  @Test(timeout=60000)
+  public void testFirstPacketSizeInNewBlocks() throws IOException {
+    final long blockSize = 1L * 1024 * 1024;
+    final int numDataNodes = 3;
+    final Configuration dfsConf = new Configuration();
+    dfsConf.setLong(DFS_BLOCK_SIZE_KEY, blockSize);
+    MiniDFSCluster dfsCluster = null;
+    dfsCluster = new 
MiniDFSCluster.Builder(dfsConf).numDataNodes(numDataNodes).build();
+    dfsCluster.waitActive();
+
+    DistributedFileSystem fs = dfsCluster.getFileSystem();
+    Path fileName = new Path("/testfile.dat");
+    FSDataOutputStream fos = fs.create(fileName);
+    DataChecksum crc32c = 
DataChecksum.newDataChecksum(DataChecksum.Type.CRC32C, 512);
+
+    long loop = 0;
+    Random r = new Random();
+    byte[] buf = new byte[1 * 1024 * 1024];

Review Comment:
   `byte[] buf = new byte[(int) blockSize];`



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to