|
@@ -18,17 +18,21 @@
|
|
|
package org.apache.hadoop.hdfs;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
import java.util.Random;
|
|
|
|
|
|
-import junit.framework.TestCase;
|
|
|
import junit.framework.Assert;
|
|
|
+import junit.framework.TestCase;
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
-import org.apache.hadoop.fs.*;
|
|
|
+import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
|
+import org.apache.hadoop.fs.FSDataInputStream;
|
|
|
+import org.apache.hadoop.fs.FSDataOutputStream;
|
|
|
+import org.apache.hadoop.fs.FileStatus;
|
|
|
+import org.apache.hadoop.fs.FileSystem;
|
|
|
+import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
|
|
|
/** Utilities for append-related tests */
|
|
@@ -176,4 +180,23 @@ public class AppendTestUtil {
|
|
|
actual[idx] = 0;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static void testAppend(FileSystem fs, Path p) throws IOException {
|
|
|
+ final byte[] bytes = new byte[1000];
|
|
|
+
|
|
|
+ { //create file
|
|
|
+ final FSDataOutputStream out = fs.create(p, (short)1);
|
|
|
+ out.write(bytes);
|
|
|
+ out.close();
|
|
|
+ Assert.assertEquals(bytes.length, fs.getFileStatus(p).getLen());
|
|
|
+ }
|
|
|
+
|
|
|
+ for(int i = 2; i < 500; i++) {
|
|
|
+ //append
|
|
|
+ final FSDataOutputStream out = fs.append(p);
|
|
|
+ out.write(bytes);
|
|
|
+ out.close();
|
|
|
+ Assert.assertEquals(i*bytes.length, fs.getFileStatus(p).getLen());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|