|
63 | 63 | import org.junit.BeforeClass; |
64 | 64 | import org.junit.Test; |
65 | 65 |
|
| 66 | +import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_BLOCK_SIZE_KEY; |
66 | 67 | import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.Write.RECOVER_LEASE_ON_CLOSE_EXCEPTION_KEY; |
67 | 68 | import static org.junit.Assert.assertFalse; |
68 | 69 | import static org.junit.Assert.assertTrue; |
@@ -184,6 +185,38 @@ public void testPreventOverflow() throws IOException, NoSuchFieldException, |
184 | 185 | runAdjustChunkBoundary(configuredWritePacketSize, finalWritePacketSize); |
185 | 186 | } |
186 | 187 |
|
| 188 | + @Test(timeout=60000) |
| 189 | + public void testFirstPacketSizeInNewBlocks() throws IOException { |
| 190 | + final long BLOCK_SIZE = 1L * 1024 * 1024; |
| 191 | + final int numDataNodes = 3; |
| 192 | + final Configuration dfsConf = new Configuration(); |
| 193 | + dfsConf.setLong(DFS_BLOCK_SIZE_KEY, BLOCK_SIZE); |
| 194 | + MiniDFSCluster dfsCluster = null; |
| 195 | + dfsCluster = new MiniDFSCluster.Builder(dfsConf).numDataNodes(numDataNodes).build(); |
| 196 | + dfsCluster.waitActive(); |
| 197 | + |
| 198 | + DistributedFileSystem fs = dfsCluster.getFileSystem(); |
| 199 | + Path fileName = new Path("/testfile.dat"); |
| 200 | + FSDataOutputStream fos = fs.create(fileName); |
| 201 | + |
| 202 | + long loop = 0; |
| 203 | + Random r = new Random(); |
| 204 | + byte[] buf = new byte[1 * 1024 * 1024]; |
| 205 | + r.nextBytes(buf); |
| 206 | + fos.write(buf); |
| 207 | + fos.hflush(); |
| 208 | + |
| 209 | + while (loop < 20) { |
| 210 | + r.nextBytes(buf); |
| 211 | + fos.write(buf); |
| 212 | + fos.hflush(); |
| 213 | + loop++; |
| 214 | + Assert.assertNotEquals(516, ((DFSOutputStream)fos.getWrappedStream()).packetSize); |
| 215 | + } |
| 216 | + |
| 217 | + fos.close(); |
| 218 | + } |
| 219 | + |
187 | 220 | /** |
188 | 221 | * @configuredWritePacketSize the configured WritePacketSize. |
189 | 222 | * @finalWritePacketSize the final WritePacketSize picked by |
|
0 commit comments