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

MVStore: error codes; fix MVRTreeMap iterators

上级 9097e2ee
......@@ -51,6 +51,7 @@ public class TestMVRTree extends TestMVStore {
testMany();
testSimple();
testRandom();
testRandomFind();
}
private void testExample() {
......@@ -273,6 +274,51 @@ public class TestMVRTree extends TestMVStore {
testRandom(false);
}
private void testRandomFind() {
MVStore s = openStore(null);
MVRTreeMap<Integer> m = s.openMap("data",
new MVRTreeMap.Builder<Integer>());
int max = 100;
for (int x = 0; x < max; x++) {
for (int y = 0; y < max; y++) {
int id = x * max + y;
SpatialKey k = new SpatialKey(id, x, x, y, y);
m.put(k, id);
}
}
Random rand = new Random(1);
int operationCount = 1000;
for (int i = 0; i < operationCount; i++) {
int x1 = rand.nextInt(max), y1 = rand.nextInt(10);
int x2 = rand.nextInt(10), y2 = rand.nextInt(10);
int intersecting = Math.max(0, x2 - x1 + 1) * Math.max(0, y2 - y1 + 1);
int contained = Math.max(0, x2 - x1 - 1) * Math.max(0, y2 - y1 - 1);
SpatialKey k = new SpatialKey(0, x1, x2, y1, y2);
Iterator<SpatialKey> it = m.findContainedKeys(k);
int count = 0;
while (it.hasNext()) {
SpatialKey t = it.next();
assertTrue(t.min(0) > x1);
assertTrue(t.min(1) > y1);
assertTrue(t.max(0) < x2);
assertTrue(t.max(1) < y2);
count++;
}
assertEquals(contained, count);
it = m.findIntersectingKeys(k);
count = 0;
while (it.hasNext()) {
SpatialKey t = it.next();
assertTrue(t.min(0) >= x1);
assertTrue(t.min(1) >= y1);
assertTrue(t.max(0) <= x2);
assertTrue(t.max(1) <= y2);
count++;
}
assertEquals(intersecting, count);
}
}
private void testRandom(boolean quadraticSplit) {
String fileName = getBaseDir() + "/testRandom.h3";
FileUtils.delete(fileName);
......@@ -284,8 +330,8 @@ public class TestMVRTree extends TestMVStore {
m.setQuadraticSplit(quadraticSplit);
HashMap<SpatialKey, String> map = new HashMap<SpatialKey, String>();
Random rand = new Random(1);
int operationCount = 1000;
int maxValue = 30;
int operationCount = 10000;
int maxValue = 300;
for (int i = 0; i < operationCount; i++) {
int key = rand.nextInt(maxValue);
Random rk = new Random(key);
......@@ -293,7 +339,8 @@ public class TestMVRTree extends TestMVStore {
float p = (float) (rk.nextFloat() * 0.000001);
SpatialKey k = new SpatialKey(key, x - p, x + p, y - p, y + p);
String v = "" + rand.nextInt();
switch (rand.nextInt(3)) {
Iterator<SpatialKey> it;
switch (rand.nextInt(5)) {
case 0:
log(i + ": put " + k + " = " + v + " " + m.size());
m.put(k, v);
......@@ -304,6 +351,28 @@ public class TestMVRTree extends TestMVStore {
m.remove(k);
map.remove(k);
break;
case 2: {
p = (float) (rk.nextFloat() * 0.01);
k = new SpatialKey(key, x - p, x + p, y - p, y + p);
it = m.findIntersectingKeys(k);
while (it.hasNext()) {
SpatialKey n = it.next();
String a = map.get(n);
assertFalse(a == null);
}
break;
}
case 3: {
p = (float) (rk.nextFloat() * 0.01);
k = new SpatialKey(key, x - p, x + p, y - p, y + p);
it = m.findContainedKeys(k);
while (it.hasNext()) {
SpatialKey n = it.next();
String a = map.get(n);
assertFalse(a == null);
}
break;
}
default:
String a = map.get(k);
String b = m.get(k);
......
......@@ -14,6 +14,7 @@ import java.util.Random;
import java.util.TreeMap;
import org.h2.mvstore.Cursor;
import org.h2.mvstore.DataUtils;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;
import org.h2.mvstore.type.DataType;
......@@ -265,7 +266,8 @@ public class TestMVStore extends TestBase {
encryptionKey(passwordChars).open();
fail();
} catch (IllegalStateException e) {
assertTrue(e.getCause() != null);
assertEquals(DataUtils.ERROR_FILE_CORRUPT,
DataUtils.getErrorCode(e.getMessage()));
}
assertEquals(0, passwordChars[0]);
assertEquals(0, passwordChars[1]);
......@@ -303,7 +305,8 @@ public class TestMVStore extends TestBase {
openStore(fileName).close();
fail();
} catch (IllegalStateException e) {
assertTrue(e.getCause() != null);
assertEquals(DataUtils.ERROR_UNSUPPORTED_FORMAT,
DataUtils.getErrorCode(e.getMessage()));
}
FileUtils.delete(fileName);
}
......
......@@ -27,6 +27,7 @@ import org.h2.tools.DeleteDbFiles;
import org.h2.tools.Recover;
import org.h2.tools.Restore;
import org.h2.util.JdbcUtils;
import org.h2.util.Profiler;
import org.h2.util.Task;
/**
......@@ -72,13 +73,13 @@ public class TestMVTableEngine extends TestBase {
// dbName += ";LOG=0";
testSpeed(dbName);
int test;
//Profiler prof = new Profiler().startCollecting();
Profiler prof = new Profiler().startCollecting();
dbName = "mvstore" +
";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine";
";MV_STORE=TRUE";
dbName += ";LOCK_MODE=0";
dbName += ";LOG=0";
testSpeed(dbName);
//System.out.println(prof.getTop(10));
System.out.println(prof.getTop(10));
}
FileUtils.deleteRecursive(getBaseDir(), true);
}
......@@ -122,7 +123,7 @@ int test;
FileUtils.deleteRecursive(getBaseDir(), true);
Connection conn;
Statement stat;
String url = "mvstore;default_table_engine=org.h2.mvstore.db.MVTableEngine";
String url = "mvstore;MV_STORE=TRUE";
url = getURL(url, true);
conn = getConnection(url);
stat = conn.createStatement();
......@@ -152,7 +153,7 @@ int test;
FileUtils.deleteRecursive(getBaseDir(), true);
Connection conn;
Statement stat;
String url = "mvstore;default_table_engine=org.h2.mvstore.db.MVTableEngine";
String url = "mvstore;MV_STORE=TRUE";
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table test(id identity)");
......@@ -168,7 +169,7 @@ int test;
Connection conn;
Statement stat;
String url = "mvstore;default_table_engine=org.h2.mvstore.db.MVTableEngine";
String url = "mvstore;MV_STORE=TRUE";
conn = getConnection(url);
stat = conn.createStatement();
......@@ -194,8 +195,8 @@ int test;
Connection conn;
Statement stat;
String url = "mvstore;default_table_engine=org.h2.mvstore.db.MVTableEngine";
String url2 = "mvstore2;default_table_engine=org.h2.mvstore.db.MVTableEngine";
String url = "mvstore;MV_STORE=TRUE";
String url2 = "mvstore2;MV_STORE=TRUE";
conn = getConnection(url);
stat = conn.createStatement();
......@@ -252,7 +253,7 @@ int test;
Connection conn;
Statement stat;
conn = getConnection("mvstore;default_table_engine=org.h2.mvstore.db.MVTableEngine");
conn = getConnection("mvstore;MV_STORE=TRUE");
stat = conn.createStatement();
stat.execute("create table test(id int, parent int " +
......@@ -394,7 +395,7 @@ int test;
private void testBlob() throws SQLException, IOException {
FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" +
";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine";
";MV_STORE=TRUE";
Connection conn;
Statement stat;
conn = getConnection(dbName);
......@@ -422,7 +423,7 @@ int test;
private void testEncryption() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" +
";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine";
";MV_STORE=TRUE";
Connection conn;
Statement stat;
String url = getURL(dbName + ";CIPHER=AES", true);
......@@ -443,7 +444,7 @@ int test;
private void testExclusiveLock() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" +
";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine";
";MV_STORE=TRUE";
Connection conn, conn2;
Statement stat, stat2;
conn = getConnection(dbName);
......@@ -467,7 +468,7 @@ int test;
private void testReadOnly() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" +
";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine";
";MV_STORE=TRUE";
Connection conn;
Statement stat;
conn = getConnection(dbName);
......@@ -485,7 +486,7 @@ int test;
private void testReuseDiskSpace() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" +
";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine";
";MV_STORE=TRUE";
Connection conn;
Statement stat;
long maxSize = 0;
......@@ -511,7 +512,7 @@ int test;
private void testDataTypes() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" +
";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine";
";MV_STORE=TRUE";
Connection conn = getConnection(dbName);
Statement stat = conn.createStatement();
......@@ -661,7 +662,7 @@ int test;
private void testLocking() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" +
";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine";
";MV_STORE=TRUE";
Connection conn = getConnection(dbName);
Statement stat = conn.createStatement();
stat.execute("set lock_timeout 1000");
......@@ -698,7 +699,7 @@ int test;
private void testSimple() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" +
";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine";
";MV_STORE=TRUE";
Connection conn = getConnection(dbName);
Statement stat = conn.createStatement();
// create table test(id int, name varchar)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论