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

Test

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