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

MVStore: error codes; fix MVRTreeMap iterators

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