提交 b675d415 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved test case.

上级 fb267a8c
......@@ -99,8 +99,6 @@ public class FilePathCache extends FilePathWrapper {
}
}
dst.put(buff.array(), off, len);
; // add test to TestFileSystem
// return len;
return len == 0 ? -1 : len;
}
......
......@@ -380,6 +380,7 @@ public class TestFileSystem extends TestBase {
}
private void testFileSystem(String fsBase) throws Exception {
testPositionedReadWrite(fsBase);
testSetReadOnly(fsBase);
testParentEventuallyReturnsNull(fsBase);
testSimple(fsBase);
......@@ -589,6 +590,42 @@ public class TestFileSystem extends TestBase {
}
}
}
private void testPositionedReadWrite(String fsBase) throws IOException {
FileUtils.deleteRecursive(fsBase + "/testFile", false);
FileUtils.delete(fsBase + "/testFile");
FileUtils.createDirectories(fsBase);
assertTrue(FileUtils.createFile(fsBase + "/testFile"));
FileChannel fc = FilePath.get(fsBase + "/testFile").open("rw");
ByteBuffer buff = ByteBuffer.allocate(4000);
for (int i = 0; i < 4000; i++) {
buff.put((byte) i);
}
buff.flip();
fc.write(buff, 96);
assertEquals(0, fc.position());
assertEquals(4096, fc.size());
buff = ByteBuffer.allocate(4000);
assertEquals(4000, fc.read(buff, 96));
assertEquals(0, fc.position());
buff.flip();
for (int i = 0; i < 4000; i++) {
assertEquals((byte) i, buff.get());
}
buff = ByteBuffer.allocate(0);
assertTrue(fc.read(buff, 8000) <= 0);
assertEquals(0, fc.position());
assertTrue(fc.read(buff, 4000) <= 0);
assertEquals(0, fc.position());
assertTrue(fc.read(buff, 2000) <= 0);
assertEquals(0, fc.position());
buff = ByteBuffer.allocate(1);
assertEquals(-1, fc.read(buff, 8000));
assertEquals(1, fc.read(buff, 4000));
buff.flip();
assertEquals(1, fc.read(buff, 2000));
fc.close();
}
private void testRandomAccess(String fsBase) throws Exception {
testRandomAccess(fsBase, 1);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论