HDFS-10805. Reduce runtime for append test. Contributed by Gergely Novak.
This commit is contained in:
parent
53a12fa721
commit
2a8f55a0cf
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hdfs;
|
package org.apache.hadoop.hdfs;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@ -238,7 +239,8 @@ private static void checkData(final byte[] actual, int from,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void testAppend(FileSystem fs, Path p) throws IOException {
|
public static void testAppend(FileSystem fs, Path p) throws IOException {
|
||||||
final byte[] bytes = new byte[1000];
|
final int size = 1000;
|
||||||
|
final byte[] bytes = randomBytes(seed, size);
|
||||||
|
|
||||||
{ //create file
|
{ //create file
|
||||||
final FSDataOutputStream out = fs.create(p, (short)1);
|
final FSDataOutputStream out = fs.create(p, (short)1);
|
||||||
@ -247,12 +249,22 @@ public static void testAppend(FileSystem fs, Path p) throws IOException {
|
|||||||
assertEquals(bytes.length, fs.getFileStatus(p).getLen());
|
assertEquals(bytes.length, fs.getFileStatus(p).getLen());
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 2; i < 500; i++) {
|
final int appends = 50;
|
||||||
|
for (int i = 2; i < appends; i++) {
|
||||||
//append
|
//append
|
||||||
final FSDataOutputStream out = fs.append(p);
|
final FSDataOutputStream out = fs.append(p);
|
||||||
out.write(bytes);
|
out.write(bytes);
|
||||||
out.close();
|
out.close();
|
||||||
assertEquals(i * bytes.length, fs.getFileStatus(p).getLen());
|
assertEquals(i * bytes.length, fs.getFileStatus(p).getLen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the appended content
|
||||||
|
final FSDataInputStream in = fs.open(p);
|
||||||
|
for (int i = 0; i < appends - 1; i++) {
|
||||||
|
byte[] read = new byte[size];
|
||||||
|
in.read(i * bytes.length, read, 0, size);
|
||||||
|
assertArrayEquals(bytes, read);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user