提交 16679fbf authored 作者: Thomas Mueller's avatar Thomas Mueller

Test

上级 ab51dbf6
......@@ -204,6 +204,7 @@ public class TestFileSystem extends TestBase {
}
private void testRandomAccess(String fsBase) throws Exception {
StringBuilder buff = new StringBuilder();
FileSystem fs = FileSystem.getInstance(fsBase);
String s = fs.createTempFile(fsBase + "/tmp", ".tmp", false, false);
File file = new File(TestBase.BASE_TEST_DIR + "/tmp");
......@@ -221,12 +222,14 @@ public class TestFileSystem extends TestBase {
f.sync();
Random random = new Random(1);
int size = getSize(100, 500);
try {
for (int i = 0; i < size; i++) {
int pos = random.nextInt(10000);
switch(random.nextInt(7)) {
case 0: {
pos = (int) Math.min(pos, ra.length());
trace("seek " + pos);
buff.append("seek " + pos + "\n");
f.seek(pos);
ra.seek(pos);
break;
......@@ -235,6 +238,7 @@ public class TestFileSystem extends TestBase {
byte[] buffer = new byte[random.nextInt(1000)];
random.nextBytes(buffer);
trace("write " + buffer.length);
buff.append("write " + buffer.length + "\n");
f.write(buffer, 0, buffer.length);
ra.write(buffer, 0, buffer.length);
break;
......@@ -247,6 +251,7 @@ public class TestFileSystem extends TestBase {
ra.seek(0);
}
trace("setLength " + pos);
buff.append("setLength " + pos + "\n");
break;
}
case 3: {
......@@ -257,21 +262,25 @@ public class TestFileSystem extends TestBase {
ra.readFully(b1, 0, len);
f.readFully(b2, 0, len);
trace("readFully " + len);
buff.append("readFully " + len + "\n");
assertEquals(b1, b2);
break;
}
case 4: {
trace("getFilePointer");
buff.append("getFilePointer\n");
assertEquals(ra.getFilePointer(), f.getFilePointer());
break;
}
case 5: {
trace("length " + ra.length());
buff.append("length " + ra.length() + "\n");
assertEquals(ra.length(), f.length());
break;
}
case 6: {
trace("reopen");
buff.append("reopen\n");
f.close();
ra.close();
ra = new RandomAccessFile(file, "rw");
......@@ -282,6 +291,9 @@ public class TestFileSystem extends TestBase {
default:
}
}
} catch (Exception e) {
fail("Exception: " + e + "\n"+ buff.toString());
}
f.close();
ra.close();
file.delete();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论