|
@@ -30,6 +30,7 @@ import java.util.List;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.CreateFlag;
|
|
import org.apache.hadoop.fs.CreateFlag;
|
|
|
|
+import org.apache.hadoop.fs.FSDataInputStream;
|
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
@@ -549,4 +550,40 @@ public class TestFileAppend2 {
|
|
public void testComplexAppend2() throws IOException {
|
|
public void testComplexAppend2() throws IOException {
|
|
testComplexAppend(true);
|
|
testComplexAppend(true);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Make sure when the block length after appending is less than 512 bytes, the
|
|
|
|
+ * checksum re-calculation and overwrite are performed correctly.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testAppendLessThanChecksumChunk() throws Exception {
|
|
|
|
+ final byte[] buf = new byte[1024];
|
|
|
|
+ final MiniDFSCluster cluster = new MiniDFSCluster
|
|
|
|
+ .Builder(new HdfsConfiguration()).numDataNodes(1).build();
|
|
|
|
+ cluster.waitActive();
|
|
|
|
+
|
|
|
|
+ try (DistributedFileSystem fs = cluster.getFileSystem()) {
|
|
|
|
+ final int len1 = 200;
|
|
|
|
+ final int len2 = 300;
|
|
|
|
+ final Path p = new Path("/foo");
|
|
|
|
+
|
|
|
|
+ FSDataOutputStream out = fs.create(p);
|
|
|
|
+ out.write(buf, 0, len1);
|
|
|
|
+ out.close();
|
|
|
|
+
|
|
|
|
+ out = fs.append(p);
|
|
|
|
+ out.write(buf, 0, len2);
|
|
|
|
+ // flush but leave open
|
|
|
|
+ out.hflush();
|
|
|
|
+
|
|
|
|
+ // read data to verify the replica's content and checksum are correct
|
|
|
|
+ FSDataInputStream in = fs.open(p);
|
|
|
|
+ final int length = in.read(0, buf, 0, len1 + len2);
|
|
|
|
+ assertTrue(length > 0);
|
|
|
|
+ in.close();
|
|
|
|
+ out.close();
|
|
|
|
+ } finally {
|
|
|
|
+ cluster.shutdown();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|