HADOOP-7817. RawLocalFileSystem.append() should give FSDataOutputStream with accurate .getPos() (Contributed by kanaka kumar avvaru)
(cherry picked from commit48ca23def1
) (cherry picked from commitd21bc811d8
) Conflicts: hadoop-common-project/hadoop-common/CHANGES.txt hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java
This commit is contained in:
parent
dd701c9800
commit
62da8f6fa6
|
@ -918,6 +918,9 @@ Release 2.6.5 - UNRELEASED
|
|||
HADOOP-12589. Fix intermittent test failure of TestCopyPreserveFlag
|
||||
(iwasakims)
|
||||
|
||||
HADOOP-7817. RawLocalFileSystem.append() should give FSDataOutputStream
|
||||
with accurate .getPos() (kanaka kumar avvaru via vinayakumarb)
|
||||
|
||||
Release 2.6.4 - 2016-02-11
|
||||
|
||||
INCOMPATIBLE CHANGES
|
||||
|
|
|
@ -265,11 +265,13 @@ public class RawLocalFileSystem extends FileSystem {
|
|||
if (!exists(f)) {
|
||||
throw new FileNotFoundException("File " + f + " not found");
|
||||
}
|
||||
if (getFileStatus(f).isDirectory()) {
|
||||
FileStatus status = getFileStatus(f);
|
||||
if (status.isDirectory()) {
|
||||
throw new IOException("Cannot append to a diretory (=" + f + " )");
|
||||
}
|
||||
return new FSDataOutputStream(new BufferedOutputStream(
|
||||
createOutputStreamWithMode(f, true, null), bufferSize), statistics);
|
||||
createOutputStreamWithMode(f, true, null), bufferSize), statistics,
|
||||
status.getLen());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -560,6 +560,40 @@ public class TestLocalFileSystem {
|
|||
resolved);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppendSetsPosCorrectly() throws Exception {
|
||||
FileSystem fs = fileSys.getRawFileSystem();
|
||||
Path file = new Path(TEST_ROOT_DIR, "test-append");
|
||||
|
||||
fs.delete(file, true);
|
||||
FSDataOutputStream out = fs.create(file);
|
||||
|
||||
try {
|
||||
out.write("text1".getBytes());
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
|
||||
// Verify the position
|
||||
out = fs.append(file);
|
||||
try {
|
||||
assertEquals(5, out.getPos());
|
||||
out.write("text2".getBytes());
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
|
||||
// Verify the content
|
||||
FSDataInputStream in = fs.open(file);
|
||||
try {
|
||||
byte[] buf = new byte[in.available()];
|
||||
in.readFully(buf);
|
||||
assertEquals("text1text2", new String(buf));
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileStatusPipeFile() throws Exception {
|
||||
RawLocalFileSystem origFs = new RawLocalFileSystem();
|
||||
|
|
Loading…
Reference in New Issue