Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
14f69a1c
提交
14f69a1c
authored
6 年前
作者:
Andrei Tokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tighten test conditions - do not ignore any exceptions
上级
8b4bfee5
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
71 行增加
和
89 行删除
+71
-89
TestConcurrentUpdate.java
h2/src/test/org/h2/test/synth/TestConcurrentUpdate.java
+71
-89
没有找到文件。
h2/src/test/org/h2/test/synth/TestConcurrentUpdate.java
浏览文件 @
14f69a1c
...
...
@@ -8,10 +8,8 @@ package org.h2.test.synth;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Random
;
import
org.h2.api.ErrorCode
;
import
org.h2.test.TestBase
;
import
org.h2.util.Task
;
...
...
@@ -29,19 +27,26 @@ public class TestConcurrentUpdate extends TestBase {
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
t
=
TestBase
.
createCaller
().
init
();
t
.
config
.
memory
=
true
;
t
.
test
();
org
.
h2
.
test
.
TestAll
config
=
new
org
.
h2
.
test
.
TestAll
();
config
.
memory
=
true
;
config
.
multiThreaded
=
true
;
// config.mvStore = false;
// config.mvcc = false;
System
.
out
.
println
(
config
);
TestBase
test
=
createCaller
().
init
(
config
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
System
.
out
.
println
(
"Pass #"
+
i
);
test
.
config
.
beforeTest
();
test
.
test
();
test
.
config
.
afterTest
();
}
}
@Override
public
void
test
()
throws
Exception
{
if
(!
config
.
multiThreaded
)
{
return
;
}
deleteDb
(
"concurrent"
);
final
String
url
=
getURL
(
"concurrent"
,
true
);
Connection
conn
=
getConnection
(
url
);
try
(
Connection
conn
=
getConnection
(
url
))
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
...
...
@@ -52,9 +57,9 @@ public class TestConcurrentUpdate extends TestBase {
@Override
public
void
call
()
throws
Exception
{
Random
r
=
new
Random
(
threadId
);
Connection
conn
=
getConnection
(
url
);
try
(
Connection
conn
=
getConnection
(
url
))
{
PreparedStatement
insert
=
conn
.
prepareStatement
(
"insert
into test values(?, ?)"
);
"merge
into test values(?, ?)"
);
PreparedStatement
update
=
conn
.
prepareStatement
(
"update test set name = ? where id = ?"
);
PreparedStatement
delete
=
conn
.
prepareStatement
(
...
...
@@ -62,7 +67,6 @@ public class TestConcurrentUpdate extends TestBase {
PreparedStatement
select
=
conn
.
prepareStatement
(
"select * from test where id = ?"
);
while
(!
stop
)
{
try
{
int
x
=
r
.
nextInt
(
ROW_COUNT
);
String
data
=
"x"
+
r
.
nextInt
(
ROW_COUNT
);
switch
(
r
.
nextInt
(
3
))
{
...
...
@@ -88,13 +92,9 @@ public class TestConcurrentUpdate extends TestBase {
}
break
;
}
}
catch
(
SQLException
e
)
{
handleException
(
e
);
}
}
conn
.
close
();
}
};
tasks
[
i
]
=
t
;
t
.
execute
();
...
...
@@ -112,24 +112,6 @@ public class TestConcurrentUpdate extends TestBase {
for
(
Task
t
:
tasks
)
{
t
.
get
();
}
conn
.
close
();
}
/**
* Handle or ignore the exception.
*
* @param e the exception
*/
void
handleException
(
SQLException
e
)
throws
SQLException
{
switch
(
e
.
getErrorCode
())
{
case
ErrorCode
.
CONCURRENT_UPDATE_1
:
case
ErrorCode
.
DUPLICATE_KEY_1
:
case
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
:
case
ErrorCode
.
LOCK_TIMEOUT_1
:
break
;
default
:
throw
e
;
}
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论