Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a715afa5
Unverified
提交
a715afa5
authored
4月 28, 2018
作者:
Evgenij Ryazanov
提交者:
GitHub
4月 28, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1101 from katzyn/tests
Move some tests in better place and add an additional test for 2PC
上级
d7bfc163
7034de30
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
93 行增加
和
76 行删除
+93
-76
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+0
-37
TestDuplicateKeyUpdate.java
h2/src/test/org/h2/test/db/TestDuplicateKeyUpdate.java
+38
-0
TestTransaction.java
h2/src/test/org/h2/test/db/TestTransaction.java
+0
-39
TestTwoPhaseCommit.java
h2/src/test/org/h2/test/db/TestTwoPhaseCommit.java
+55
-0
没有找到文件。
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
a715afa5
...
...
@@ -35,7 +35,6 @@ public class TestCompatibility extends TestBase {
public
void
test
()
throws
SQLException
{
deleteDb
(
"compatibility"
);
testOnDuplicateKey
();
testCaseSensitiveIdentifiers
();
testKeyAsColumnInMySQLMode
();
...
...
@@ -56,42 +55,6 @@ public class TestCompatibility extends TestBase {
deleteDb
(
"compatibility"
);
}
private
void
testOnDuplicateKey
()
throws
SQLException
{
Connection
c
=
getConnection
(
"compatibility;MODE=MYSQL"
);
Statement
stat
=
c
.
createStatement
();
stat
.
execute
(
"set mode mysql"
);
stat
.
execute
(
"create schema s2"
);
stat
.
execute
(
"create table s2.test(id int primary key, name varchar(255))"
);
stat
.
execute
(
"insert into s2.test(id, name) values(1, 'a')"
);
assertEquals
(
2
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(1, 'b') "
+
"on duplicate key update name = values(name)"
));
assertEquals
(
0
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(1, 'b') "
+
"on duplicate key update name = values(name)"
));
assertEquals
(
1
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'c') "
+
"on duplicate key update name = values(name)"
));
ResultSet
rs
=
stat
.
executeQuery
(
"select id, name from s2.test order by id"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
"b"
,
rs
.
getString
(
2
));
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertEquals
(
"c"
,
rs
.
getString
(
2
));
assertFalse
(
rs
.
next
());
// Check qualified names in ON UPDATE case
assertEquals
(
2
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'd') "
+
"on duplicate key update test.name = values(name)"
));
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
)
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'd') "
+
"on duplicate key update test2.name = values(name)"
);
assertEquals
(
2
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'e') "
+
"on duplicate key update s2.test.name = values(name)"
));
assertThrows
(
ErrorCode
.
SCHEMA_NAME_MUST_MATCH
,
stat
)
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'd') "
+
"on duplicate key update s3.test.name = values(name)"
);
stat
.
execute
(
"drop schema s2 cascade"
);
c
.
close
();
}
private
void
testKeyAsColumnInMySQLMode
()
throws
SQLException
{
Connection
c
=
getConnection
(
"compatibility;MODE=MYSQL"
);
Statement
stat
=
c
.
createStatement
();
...
...
h2/src/test/org/h2/test/db/TestDuplicateKeyUpdate.java
浏览文件 @
a715afa5
...
...
@@ -10,6 +10,8 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.api.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -37,6 +39,7 @@ public class TestDuplicateKeyUpdate extends TestBase {
testOnDuplicateKeyInsertBatch
(
conn
);
testOnDuplicateKeyInsertMultiValue
(
conn
);
testPrimaryKeyAndUniqueKey
(
conn
);
testUpdateCountAndQualifiedNames
(
conn
);
conn
.
close
();
deleteDb
(
"duplicateKeyUpdate"
);
}
...
...
@@ -262,4 +265,39 @@ public class TestDuplicateKeyUpdate extends TestBase {
stat
.
execute
(
"drop table test"
);
}
private
void
testUpdateCountAndQualifiedNames
(
Connection
conn
)
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"set mode mysql"
);
stat
.
execute
(
"create schema s2"
);
stat
.
execute
(
"create table s2.test(id int primary key, name varchar(255))"
);
stat
.
execute
(
"insert into s2.test(id, name) values(1, 'a')"
);
assertEquals
(
2
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(1, 'b') "
+
"on duplicate key update name = values(name)"
));
assertEquals
(
0
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(1, 'b') "
+
"on duplicate key update name = values(name)"
));
assertEquals
(
1
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'c') "
+
"on duplicate key update name = values(name)"
));
ResultSet
rs
=
stat
.
executeQuery
(
"select id, name from s2.test order by id"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
"b"
,
rs
.
getString
(
2
));
assertTrue
(
rs
.
next
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertEquals
(
"c"
,
rs
.
getString
(
2
));
assertFalse
(
rs
.
next
());
// Check qualified names in ON UPDATE case
assertEquals
(
2
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'd') "
+
"on duplicate key update test.name = values(name)"
));
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
)
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'd') "
+
"on duplicate key update test2.name = values(name)"
);
assertEquals
(
2
,
stat
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'e') "
+
"on duplicate key update s2.test.name = values(name)"
));
assertThrows
(
ErrorCode
.
SCHEMA_NAME_MUST_MATCH
,
stat
)
.
executeUpdate
(
"insert into s2.test(id, name) values(2, 'd') "
+
"on duplicate key update s3.test.name = values(name)"
);
stat
.
execute
(
"drop schema s2 cascade"
);
}
}
h2/src/test/org/h2/test/db/TestTransaction.java
浏览文件 @
a715afa5
...
...
@@ -48,7 +48,6 @@ public class TestTransaction extends TestBase {
testReferential
();
testSavepoint
();
testIsolation
();
testTwoPhaseCommit
();
deleteDb
(
"transaction"
);
}
...
...
@@ -544,42 +543,4 @@ public class TestTransaction extends TestBase {
stat
.
execute
(
sql
);
}
private
void
testTwoPhaseCommit
()
throws
SQLException
{
if
(
config
.
memory
)
{
return
;
}
deleteDb
(
"transaction2pc"
);
Connection
conn
=
getConnection
(
"transaction2pc"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST (ID INT PRIMARY KEY)"
);
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"INSERT INTO TEST VALUES (1)"
);
stat
.
execute
(
"PREPARE COMMIT \"#1\""
);
conn
.
commit
();
stat
.
execute
(
"SHUTDOWN IMMEDIATELY"
);
conn
=
getConnection
(
"transaction2pc"
);
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT TRANSACTION, STATE FROM INFORMATION_SCHEMA.IN_DOUBT"
);
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT ID FROM TEST"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"INSERT INTO TEST VALUES (2)"
);
stat
.
execute
(
"PREPARE COMMIT \"#2\""
);
conn
.
rollback
();
stat
.
execute
(
"SHUTDOWN IMMEDIATELY"
);
conn
=
getConnection
(
"transaction2pc"
);
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
"SELECT TRANSACTION, STATE FROM INFORMATION_SCHEMA.IN_DOUBT"
);
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT ID FROM TEST"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
conn
.
close
();
deleteDb
(
"transaction2pc"
);
}
}
h2/src/test/org/h2/test/db/TestTwoPhaseCommit.java
浏览文件 @
a715afa5
...
...
@@ -43,6 +43,8 @@ public class TestTwoPhaseCommit extends TestBase {
openWith
(
false
);
test
(
false
);
testInDoubtAfterShutdown
();
if
(!
config
.
mvStore
)
{
testLargeTransactionName
();
}
...
...
@@ -115,4 +117,57 @@ public class TestTwoPhaseCommit extends TestBase {
stat
.
execute
(
"PREPARE COMMIT XID_TEST_TRANSACTION_WITH_LONG_NAME"
);
crash
(
conn
);
}
private
void
testInDoubtAfterShutdown
()
throws
SQLException
{
if
(
config
.
memory
)
{
return
;
}
deleteDb
(
"twoPhaseCommit"
);
Connection
conn
=
getConnection
(
"twoPhaseCommit"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST (ID INT PRIMARY KEY)"
);
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"INSERT INTO TEST VALUES (1)"
);
stat
.
execute
(
"PREPARE COMMIT \"#1\""
);
conn
.
commit
();
stat
.
execute
(
"SHUTDOWN IMMEDIATELY"
);
conn
=
getConnection
(
"twoPhaseCommit"
);
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT TRANSACTION, STATE FROM INFORMATION_SCHEMA.IN_DOUBT"
);
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT ID FROM TEST"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"INSERT INTO TEST VALUES (2)"
);
stat
.
execute
(
"PREPARE COMMIT \"#2\""
);
conn
.
rollback
();
stat
.
execute
(
"SHUTDOWN IMMEDIATELY"
);
conn
=
getConnection
(
"twoPhaseCommit"
);
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
"SELECT TRANSACTION, STATE FROM INFORMATION_SCHEMA.IN_DOUBT"
);
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT ID FROM TEST"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"INSERT INTO TEST VALUES (3)"
);
stat
.
execute
(
"PREPARE COMMIT \"#3\""
);
stat
.
execute
(
"SHUTDOWN IMMEDIATELY"
);
conn
=
getConnection
(
"twoPhaseCommit"
);
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
"SELECT TRANSACTION, STATE FROM INFORMATION_SCHEMA.IN_DOUBT"
);
assertTrue
(
rs
.
next
());
assertEquals
(
"#3"
,
rs
.
getString
(
"TRANSACTION"
));
assertEquals
(
"IN_DOUBT"
,
rs
.
getString
(
"STATE"
));
rs
=
stat
.
executeQuery
(
"SELECT ID FROM TEST"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
conn
.
close
();
deleteDb
(
"twoPhaseCommit"
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论