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

Fix test cases

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