提交 0faa5db5 authored 作者: Thomas Mueller's avatar Thomas Mueller

Fix test cases

上级 c9404560
......@@ -40,29 +40,31 @@ public class TestKillProcessWhileWriting extends TestBase {
test("unstable:memFS:killProcess.h3");
if (config.big) {
try {
fs.setPartialWrites(true);
test("unstable:memFS:killProcess.h3");
} finally {
fs.setPartialWrites(false);
}
}
}
private void test(String fileName) throws Exception {
for (seed = 0; seed < 10; seed++) {
this.fileName = fileName;
fs.setSeed(seed);
FileUtils.delete(fileName);
test(Integer.MAX_VALUE);
test(Integer.MAX_VALUE, seed);
int max = Integer.MAX_VALUE - fs.getDiskFullCount() + 10;
assertTrue("" + (max - 10), max > 0);
for (int i = 0; i < max; i++) {
fs.setSeed(seed);
test(i);
test(i, seed);
}
}
}
private void test(int x) throws Exception {
private void test(int x, int seed) throws Exception {
FileUtils.delete(fileName);
fs.setDiskFullCount(x);
fs.setDiskFullCount(x, seed);
try {
write();
verify();
......@@ -70,7 +72,7 @@ public class TestKillProcessWhileWriting extends TestBase {
if (x == Integer.MAX_VALUE) {
throw e;
}
fs.setDiskFullCount(0);
fs.setDiskFullCount(0, seed);
verify();
}
}
......
......@@ -33,16 +33,21 @@ public class TestDiskFull extends TestBase {
@Override
public void test() throws Exception {
fs = FilePathUnstable.register();
fs.setPartialWrites(true);
try {
test(Integer.MAX_VALUE);
int max = Integer.MAX_VALUE - fs.getDiskFullCount() + 10;
for (int i = 0; i < max; i++) {
test(i);
}
} finally {
fs.setPartialWrites(false);
}
}
private boolean test(int x) throws SQLException {
deleteDb("memFS:", null);
fs.setDiskFullCount(x);
fs.setDiskFullCount(x, 0);
String url = "jdbc:h2:unstable:memFS:diskFull" + x +
";FILE_LOCK=NO;TRACE_LEVEL_FILE=0;WRITE_DELAY=10;" +
"LOCK_TIMEOUT=100;CACHE_SIZE=4096";
......@@ -74,7 +79,7 @@ public class TestDiskFull extends TestBase {
}
if (stat != null) {
try {
fs.setDiskFullCount(0);
fs.setDiskFullCount(0, 0);
stat.execute("create table if not exists test(id int primary key, name varchar)");
stat.execute("insert into test values(4, space(10000))");
stat.execute("update test set name='Hallo' where id=3");
......@@ -102,7 +107,7 @@ public class TestDiskFull extends TestBase {
}
}
}
fs.setDiskFullCount(0);
fs.setDiskFullCount(0, 0);
try {
conn = null;
conn = DriverManager.getConnection(url);
......@@ -115,6 +120,7 @@ public class TestDiskFull extends TestBase {
stat = conn.createStatement();
stat.execute("script to 'memFS:test.sql'");
conn.close();
return false;
}
......
......@@ -45,6 +45,23 @@ public class FilePathUnstable extends FilePathWrapper {
return INSTANCE;
}
/**
* Set the number of write operations before the disk is full, and the
* random seed (for partial writes).
*
* @param count the number of write operations (0 to never fail,
* Integer.MAX_VALUE to count the operations)
* @param seed the new seed
*/
public void setDiskFullCount(int count, int seed) {
diskFullOffCount = count;
random.setSeed(seed);
}
public int getDiskFullCount() {
return diskFullOffCount;
}
/**
* Whether partial writes are possible (writing only part of the data).
*
......@@ -58,15 +75,6 @@ public class FilePathUnstable extends FilePathWrapper {
return partialWrites;
}
/**
* Set the random seed.
*
* @param seed the new seed
*/
public void setSeed(long seed) {
random.setSeed(seed);
}
/**
* Get a buffer with a subset (the head) of the data of the source buffer.
*
......@@ -196,14 +204,6 @@ public class FilePathUnstable extends FilePathWrapper {
return super.createTempFile(suffix, deleteOnExit, inTempDir);
}
public void setDiskFullCount(int count) {
diskFullOffCount = count;
}
public int getDiskFullCount() {
return diskFullOffCount;
}
@Override
public String getScheme() {
return "unstable";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论