Skip to content

Commit 338aa6f

Browse files
committed
add unit test.
1 parent 9a4a6ba commit 338aa6f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSOutputStream.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.junit.BeforeClass;
6464
import org.junit.Test;
6565

66+
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_BLOCK_SIZE_KEY;
6667
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.Write.RECOVER_LEASE_ON_CLOSE_EXCEPTION_KEY;
6768
import static org.junit.Assert.assertFalse;
6869
import static org.junit.Assert.assertTrue;
@@ -184,6 +185,38 @@ public void testPreventOverflow() throws IOException, NoSuchFieldException,
184185
runAdjustChunkBoundary(configuredWritePacketSize, finalWritePacketSize);
185186
}
186187

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+
187220
/**
188221
* @configuredWritePacketSize the configured WritePacketSize.
189222
* @finalWritePacketSize the final WritePacketSize picked by

0 commit comments

Comments
 (0)