HDFS-4156. Seeking to a negative position should throw an IOE. Contributed by Eli Reisman
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1410812 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0f0caede29
commit
ecbb41923c
@ -608,6 +608,9 @@ Release 2.0.3-alpha - Unreleased
|
|||||||
HDFS-3507. DFS#isInSafeMode needs to execute only on Active NameNode.
|
HDFS-3507. DFS#isInSafeMode needs to execute only on Active NameNode.
|
||||||
(Vinay via atm)
|
(Vinay via atm)
|
||||||
|
|
||||||
|
HDFS-4156. Seeking to a negative position should throw an IOE.
|
||||||
|
(Eli Reisman via eli)
|
||||||
|
|
||||||
Release 2.0.2-alpha - 2012-09-07
|
Release 2.0.2-alpha - 2012-09-07
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
@ -1076,6 +1076,9 @@ public class DFSInputStream extends FSInputStream implements ByteBufferReadable
|
|||||||
if (targetPos > getFileLength()) {
|
if (targetPos > getFileLength()) {
|
||||||
throw new IOException("Cannot seek after EOF");
|
throw new IOException("Cannot seek after EOF");
|
||||||
}
|
}
|
||||||
|
if (targetPos < 0) {
|
||||||
|
throw new IOException("Cannot seek to negative offset");
|
||||||
|
}
|
||||||
if (closed) {
|
if (closed) {
|
||||||
throw new IOException("Stream is closed!");
|
throw new IOException("Stream is closed!");
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,68 @@ public class TestSeekBug {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test (expected to throw IOE) for negative
|
||||||
|
* <code>FSDataInpuStream#seek</code> argument
|
||||||
|
*/
|
||||||
|
@Test (expected=IOException.class)
|
||||||
|
public void testNegativeSeek() throws IOException {
|
||||||
|
Configuration conf = new HdfsConfiguration();
|
||||||
|
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
|
||||||
|
FileSystem fs = cluster.getFileSystem();
|
||||||
|
try {
|
||||||
|
Path seekFile = new Path("seekboundaries.dat");
|
||||||
|
DFSTestUtil.createFile(
|
||||||
|
fs,
|
||||||
|
seekFile,
|
||||||
|
ONEMB,
|
||||||
|
ONEMB,
|
||||||
|
fs.getDefaultBlockSize(seekFile),
|
||||||
|
fs.getDefaultReplication(seekFile),
|
||||||
|
seed);
|
||||||
|
FSDataInputStream stream = fs.open(seekFile);
|
||||||
|
// Perform "safe seek" (expected to pass)
|
||||||
|
stream.seek(65536);
|
||||||
|
assertEquals(65536, stream.getPos());
|
||||||
|
// expect IOE for this call
|
||||||
|
stream.seek(-73);
|
||||||
|
} finally {
|
||||||
|
fs.close();
|
||||||
|
cluster.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test (expected to throw IOE) for <code>FSDataInpuStream#seek</code>
|
||||||
|
* when the position argument is larger than the file size.
|
||||||
|
*/
|
||||||
|
@Test (expected=IOException.class)
|
||||||
|
public void testSeekPastFileSize() throws IOException {
|
||||||
|
Configuration conf = new HdfsConfiguration();
|
||||||
|
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
|
||||||
|
FileSystem fs = cluster.getFileSystem();
|
||||||
|
try {
|
||||||
|
Path seekFile = new Path("seekboundaries.dat");
|
||||||
|
DFSTestUtil.createFile(
|
||||||
|
fs,
|
||||||
|
seekFile,
|
||||||
|
ONEMB,
|
||||||
|
ONEMB,
|
||||||
|
fs.getDefaultBlockSize(seekFile),
|
||||||
|
fs.getDefaultReplication(seekFile),
|
||||||
|
seed);
|
||||||
|
FSDataInputStream stream = fs.open(seekFile);
|
||||||
|
// Perform "safe seek" (expected to pass)
|
||||||
|
stream.seek(65536);
|
||||||
|
assertEquals(65536, stream.getPos());
|
||||||
|
// expect IOE for this call
|
||||||
|
stream.seek(ONEMB + ONEMB + ONEMB);
|
||||||
|
} finally {
|
||||||
|
fs.close();
|
||||||
|
cluster.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests if the seek bug exists in FSDataInputStream in LocalFS.
|
* Tests if the seek bug exists in FSDataInputStream in LocalFS.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user