Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3793f779
提交
3793f779
authored
6月 24, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVTableEngine
上级
ba2e2de7
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
130 行增加
和
27 行删除
+130
-27
TestMVTableEngine.java
h2/src/test/org/h2/test/store/TestMVTableEngine.java
+87
-17
TestTransactionStore.java
h2/src/test/org/h2/test/store/TestTransactionStore.java
+43
-10
没有找到文件。
h2/src/test/org/h2/test/store/TestMVTableEngine.java
浏览文件 @
3793f779
...
...
@@ -23,7 +23,9 @@ import org.h2.engine.Database;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Recover
;
import
org.h2.tools.Restore
;
import
org.h2.tools.Script
;
import
org.h2.util.Task
;
/**
...
...
@@ -43,6 +45,9 @@ public class TestMVTableEngine extends TestBase {
@Override
public
void
test
()
throws
Exception
{
// testSpeed();
// testRecover();
testSeparateKey
();
testRollback
();
testRollbackAfterCrash
();
testReferentialIntegrity
();
testWriteDelay
();
...
...
@@ -112,14 +117,78 @@ int test;
System
.
out
.
println
((
System
.
currentTimeMillis
()
-
time
)
+
" "
+
dbName
+
" after"
);
}
private
void
testR
ollbackAfterCrash
()
throws
Exception
{
private
void
testR
ecover
()
throws
Exception
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
Connection
conn
;
Statement
stat
;
String
url
=
"mvstore;default_table_engine=org.h2.mvstore.db.MVTableEngine"
;
conn
=
getConnection
(
url
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key)"
);
stat
.
execute
(
"insert into test values(1)"
);
conn
.
close
();
Recover
.
execute
(
getBaseDir
(),
"mvstore"
);
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
Script
.
execute
(
url
,
getUser
(),
getPassword
(),
System
.
out
);
conn
=
getConnection
(
url
);
stat
=
conn
.
createStatement
();
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"select * from test"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
conn
.
close
();
}
private
void
testRollback
()
throws
Exception
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
Connection
conn
;
Statement
stat
;
String
url
=
"mvstore;default_table_engine=org.h2.mvstore.db.MVTableEngine"
;
conn
=
getConnection
(
url
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id identity)"
);
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"insert into test values(1)"
);
stat
.
execute
(
"delete from test"
);
conn
.
rollback
();
conn
.
close
();
}
private
void
testSeparateKey
()
throws
Exception
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
Connection
conn
;
Statement
stat
;
String
url
=
"mvstore;default_table_engine=org.h2.mvstore.db.MVTableEngine"
;
conn
=
getConnection
(
url
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table a(id int)"
);
stat
.
execute
(
"insert into a values(1)"
);
stat
.
execute
(
"insert into a values(1)"
);
stat
.
execute
(
"create table test(id int not null) as select 100"
);
stat
.
execute
(
"create primary key on test(id)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test where id = 100"
);
assertTrue
(
rs
.
next
());
conn
.
close
();
conn
=
getConnection
(
url
);
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
"select * from test where id = 100"
);
assertTrue
(
rs
.
next
());
conn
.
close
();
}
private
void
testRollbackAfterCrash
()
throws
Exception
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
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"
;
conn
=
getConnection
(
url
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int)"
);
...
...
@@ -128,10 +197,10 @@ int test;
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"insert into test values(1)"
);
stat
.
execute
(
"shutdown immediately"
);
conn
=
getConnection
(
url
);
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"select row_count_estimate "
+
ResultSet
rs
=
stat
.
executeQuery
(
"select row_count_estimate "
+
"from information_schema.tables where table_name='TEST'"
);
rs
.
next
();
assertEquals
(
1
,
rs
.
getLong
(
1
));
...
...
@@ -143,14 +212,14 @@ int test;
stat
.
execute
(
"delete from test"
);
stat
.
execute
(
"checkpoint"
);
stat
.
execute
(
"shutdown immediately"
);
conn
=
getConnection
(
url
);
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
"select * from test"
);
assertTrue
(
rs
.
next
());
stat
.
execute
(
"drop all objects delete files"
);
conn
.
close
();
conn
=
getConnection
(
url
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
...
...
@@ -165,35 +234,35 @@ int test;
conn2
=
getConnection
(
url2
);
conn
.
close
();
conn2
.
close
();
}
private
void
testReferentialIntegrity
()
throws
Exception
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
Connection
conn
;
Statement
stat
;
conn
=
getConnection
(
"mvstore;default_table_engine=org.h2.mvstore.db.MVTableEngine"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, parent int "
+
stat
.
execute
(
"create table test(id int, parent int "
+
"references test(id) on delete cascade)"
);
stat
.
execute
(
"insert into test values(0, 0)"
);
stat
.
execute
(
"delete from test"
);
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"create table parent(id int, name varchar)"
);
stat
.
execute
(
"create table child(id int, parentid int, "
+
stat
.
execute
(
"create table child(id int, parentid int, "
+
"foreign key(parentid) references parent(id))"
);
stat
.
execute
(
"insert into parent values(1, 'mary'), (2, 'john')"
);
stat
.
execute
(
"insert into child values(10, 1), (11, 1), (20, 2), (21, 2)"
);
stat
.
execute
(
"update parent set name = 'marc' where id = 1"
);
stat
.
execute
(
"merge into parent key(id) values(1, 'marcy')"
);
stat
.
execute
(
"drop table parent, child"
);
stat
.
execute
(
"create table test(id identity, parent bigint, "
+
stat
.
execute
(
"create table test(id identity, parent bigint, "
+
"foreign key(parent) references(id))"
);
stat
.
execute
(
"insert into test values(0, 0), (1, NULL), "
+
stat
.
execute
(
"insert into test values(0, 0), (1, NULL), "
+
"(2, 1), (3, 3), (4, 3)"
);
stat
.
execute
(
"drop table test"
);
...
...
@@ -224,9 +293,9 @@ int test;
}
stat
.
execute
(
"drop table child, parent"
);
stat
.
execute
(
"create table test(id identity, parent bigint, "
+
stat
.
execute
(
"create table test(id identity, parent bigint, "
+
"foreign key(parent) references(id))"
);
stat
.
execute
(
"insert into test values(0, 0), (1, NULL), "
+
stat
.
execute
(
"insert into test values(0, 0), (1, NULL), "
+
"(2, 1), (3, 3), (4, 3)"
);
stat
.
execute
(
"drop table test"
);
...
...
@@ -272,6 +341,7 @@ int test;
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar) "
+
"engine \"org.h2.mvstore.db.MVTableEngine\""
);
stat
.
execute
(
"create index on test(name)"
);
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"insert into test values(1, 'Hello')"
);
stat
.
execute
(
"insert into test values(2, 'World')"
);
...
...
h2/src/test/org/h2/test/store/TestTransactionStore.java
浏览文件 @
3793f779
...
...
@@ -15,10 +15,10 @@ import java.util.ArrayList;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Random
;
import
java.util.TreeSet
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.db.TransactionStore
;
import
org.h2.mvstore.db.TransactionStore.Change
;
import
org.h2.mvstore.db.TransactionStore.Transaction
;
import
org.h2.mvstore.db.TransactionStore.TransactionMap
;
import
org.h2.store.fs.FileUtils
;
...
...
@@ -58,14 +58,12 @@ public class TestTransactionStore extends TestBase {
Transaction
tx
;
TransactionMap
<
String
,
String
>
m1
,
m2
,
m3
;
long
sp
;
TreeSet
<
String
>
changed
;
tx
=
ts
.
begin
();
m1
=
tx
.
openMap
(
"m1"
);
m2
=
tx
.
openMap
(
"m2"
);
m3
=
tx
.
openMap
(
"m3"
);
changed
=
new
TreeSet
<
String
>(
tx
.
getChangedMaps
(
0
));
assertEquals
(
0
,
changed
.
size
());
assertFalse
(
tx
.
getChanges
(
0
).
hasNext
());
tx
.
commit
();
tx
=
ts
.
begin
();
...
...
@@ -76,13 +74,48 @@ public class TestTransactionStore extends TestBase {
sp
=
tx
.
setSavepoint
();
m2
.
put
(
"1"
,
"100"
);
m3
.
put
(
"1"
,
"100"
);
changed
=
new
TreeSet
<
String
>(
tx
.
getChangedMaps
(
sp
));
assertEquals
(
"[m2, m3]"
,
changed
.
toString
());
changed
=
new
TreeSet
<
String
>(
tx
.
getChangedMaps
(
0
));
assertEquals
(
"[m1, m2, m3]"
,
changed
.
toString
());
Iterator
<
Change
>
it
=
tx
.
getChanges
(
sp
);
assertTrue
(
it
.
hasNext
());
Change
c
;
c
=
it
.
next
();
assertEquals
(
"m3"
,
c
.
mapName
);
assertEquals
(
"1"
,
c
.
key
.
toString
());
assertNull
(
c
.
value
);
assertTrue
(
it
.
hasNext
());
c
=
it
.
next
();
assertEquals
(
"m2"
,
c
.
mapName
);
assertEquals
(
"1"
,
c
.
key
.
toString
());
assertNull
(
c
.
value
);
assertFalse
(
it
.
hasNext
());
it
=
tx
.
getChanges
(
0
);
assertTrue
(
it
.
hasNext
());
c
=
it
.
next
();
assertEquals
(
"m3"
,
c
.
mapName
);
assertEquals
(
"1"
,
c
.
key
.
toString
());
assertNull
(
c
.
value
);
assertTrue
(
it
.
hasNext
());
c
=
it
.
next
();
assertEquals
(
"m2"
,
c
.
mapName
);
assertEquals
(
"1"
,
c
.
key
.
toString
());
assertNull
(
c
.
value
);
assertTrue
(
it
.
hasNext
());
c
=
it
.
next
();
assertEquals
(
"m1"
,
c
.
mapName
);
assertEquals
(
"1"
,
c
.
key
.
toString
());
assertNull
(
c
.
value
);
assertFalse
(
it
.
hasNext
());
tx
.
rollbackToSavepoint
(
sp
);
changed
=
new
TreeSet
<
String
>(
tx
.
getChangedMaps
(
0
));
assertEquals
(
"[m1]"
,
changed
.
toString
());
it
=
tx
.
getChanges
(
0
);
assertTrue
(
it
.
hasNext
());
c
=
it
.
next
();
assertEquals
(
"m1"
,
c
.
mapName
);
assertEquals
(
"1"
,
c
.
key
.
toString
());
assertNull
(
c
.
value
);
assertFalse
(
it
.
hasNext
());
tx
.
commit
();
s
.
close
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论