HDFS-10293. StripedFileTestUtil#readAll flaky. Contributed by Mingliang Liu.
This commit is contained in:
parent
89a838769f
commit
55e19b7f0c
|
@ -34,6 +34,7 @@ import org.apache.hadoop.hdfs.protocol.LocatedStripedBlock;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.ErasureCodingPolicyManager;
|
import org.apache.hadoop.hdfs.server.namenode.ErasureCodingPolicyManager;
|
||||||
import org.apache.hadoop.hdfs.util.StripedBlockUtil;
|
import org.apache.hadoop.hdfs.util.StripedBlockUtil;
|
||||||
import org.apache.hadoop.hdfs.web.WebHdfsFileSystem.WebHdfsInputStream;
|
import org.apache.hadoop.hdfs.web.WebHdfsFileSystem.WebHdfsInputStream;
|
||||||
|
import org.apache.hadoop.io.IOUtils;
|
||||||
import org.apache.hadoop.io.erasurecode.CodecUtil;
|
import org.apache.hadoop.io.erasurecode.CodecUtil;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureEncoder;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureEncoder;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -85,16 +86,6 @@ public class StripedFileTestUtil {
|
||||||
return (byte) (pos % mod + 1);
|
return (byte) (pos % mod + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int readAll(FSDataInputStream in, byte[] buf) throws IOException {
|
|
||||||
int readLen = 0;
|
|
||||||
int ret;
|
|
||||||
while ((ret = in.read(buf, readLen, buf.length - readLen)) >= 0 &&
|
|
||||||
readLen <= buf.length) {
|
|
||||||
readLen += ret;
|
|
||||||
}
|
|
||||||
return readLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void verifyLength(FileSystem fs, Path srcPath, int fileLength)
|
static void verifyLength(FileSystem fs, Path srcPath, int fileLength)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
FileStatus status = fs.getFileStatus(srcPath);
|
FileStatus status = fs.getFileStatus(srcPath);
|
||||||
|
@ -214,11 +205,11 @@ public class StripedFileTestUtil {
|
||||||
static void assertSeekAndRead(FSDataInputStream fsdis, int pos,
|
static void assertSeekAndRead(FSDataInputStream fsdis, int pos,
|
||||||
int writeBytes) throws IOException {
|
int writeBytes) throws IOException {
|
||||||
fsdis.seek(pos);
|
fsdis.seek(pos);
|
||||||
byte[] buf = new byte[writeBytes];
|
byte[] buf = new byte[writeBytes - pos];
|
||||||
int readLen = StripedFileTestUtil.readAll(fsdis, buf);
|
IOUtils.readFully(fsdis, buf, 0, buf.length);
|
||||||
assertEquals(readLen, writeBytes - pos);
|
for (int i = 0; i < buf.length; i++) {
|
||||||
for (int i = 0; i < readLen; i++) {
|
assertEquals("Byte at " + i + " should be the same",
|
||||||
assertEquals("Byte at " + i + " should be the same", StripedFileTestUtil.getByte(pos + i), buf[i]);
|
StripedFileTestUtil.getByte(pos + i), buf[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue