Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a4f19e7d
提交
a4f19e7d
authored
11月 07, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
c9b81c49
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
39 行增加
和
12 行删除
+39
-12
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+3
-1
TestMultiThreaded.java
h2/src/test/org/h2/test/synth/TestMultiThreaded.java
+36
-11
没有找到文件。
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
a4f19e7d
...
...
@@ -39,7 +39,7 @@ public abstract class TestBase {
/**
* The test configuration.
*/
p
rotected
TestAll
config
;
p
ublic
TestAll
config
;
/**
* The time when the test was started.
...
...
@@ -363,6 +363,7 @@ public abstract class TestBase {
e
=
new
Exception
(
s
);
}
System
.
out
.
println
(
"ERROR: "
+
s
+
" "
+
e
.
toString
()
+
" ------------------------------"
);
System
.
out
.
flush
();
e
.
printStackTrace
();
try
{
TraceSystem
ts
=
new
TraceSystem
(
null
,
false
);
...
...
@@ -377,6 +378,7 @@ public abstract class TestBase {
}
catch
(
Throwable
t
)
{
t
.
printStackTrace
();
}
System
.
err
.
flush
();
}
/**
...
...
h2/src/test/org/h2/test/synth/TestMultiThreaded.java
浏览文件 @
a4f19e7d
...
...
@@ -36,6 +36,8 @@ public class TestMultiThreaded extends TestBase {
private
Statement
stat
;
private
Random
random
;
private
volatile
Throwable
exception
;
private
boolean
stop
;
Processor
(
Connection
conn
,
int
id
)
throws
SQLException
{
this
.
id
=
id
;
stat
=
conn
.
createStatement
();
...
...
@@ -48,20 +50,22 @@ public class TestMultiThreaded extends TestBase {
int
count
=
0
;
ResultSet
rs
;
try
{
while
(!
isInterrupted
()
)
{
while
(!
stop
)
{
switch
(
random
.
nextInt
(
6
))
{
case
0
:
// insert a row for this connection
trace
(
"insert "
+
id
+
" count: "
+
count
);
trace
Thread
(
"insert "
+
id
+
" count: "
+
count
);
stat
.
execute
(
"INSERT INTO TEST(NAME) VALUES('"
+
id
+
"')"
);
traceThread
(
"insert done"
);
count
++;
break
;
case
1
:
// delete a row for this connection
if
(
count
>
0
)
{
trace
(
"delete "
+
id
+
" count: "
+
count
);
trace
Thread
(
"delete "
+
id
+
" count: "
+
count
);
int
updateCount
=
stat
.
executeUpdate
(
"DELETE FROM TEST WHERE NAME = '"
+
id
+
"' AND ROWNUM()<2"
);
traceThread
(
"delete done"
);
if
(
updateCount
!=
1
)
{
throw
new
Error
(
"Expected: 1 Deleted: "
+
updateCount
);
}
...
...
@@ -70,8 +74,9 @@ public class TestMultiThreaded extends TestBase {
break
;
case
2
:
// select the number of rows of this connection
trace
(
"select "
+
id
+
" count: "
+
count
);
trace
Thread
(
"select "
+
id
+
" count: "
+
count
);
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST WHERE NAME = '"
+
id
+
"'"
);
traceThread
(
"select done"
);
rs
.
next
();
int
got
=
rs
.
getInt
(
1
);
if
(
got
!=
count
)
{
...
...
@@ -79,16 +84,19 @@ public class TestMultiThreaded extends TestBase {
}
break
;
case
3
:
// insert a row
traceThread
(
"insert"
);
stat
.
execute
(
"INSERT INTO TEST(NAME) VALUES(NULL)"
);
traceThread
(
"insert done"
);
break
;
case
4
:
// delete a row
traceThread
(
"delete"
);
stat
.
execute
(
"DELETE FROM TEST WHERE NAME IS NULL"
);
traceThread
(
"delete done"
);
break
;
case
5
:
// select rows
traceThread
(
"select"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST WHERE NAME IS NULL"
);
traceThread
(
"select done"
);
while
(
rs
.
next
())
{
rs
.
getString
(
1
);
}
...
...
@@ -99,6 +107,15 @@ public class TestMultiThreaded extends TestBase {
exception
=
e
;
}
}
private
void
traceThread
(
String
s
)
{
if
(
config
.
traceTest
)
{
trace
(
id
+
" "
+
s
);
}
}
public
void
stopNow
()
{
this
.
stop
=
true
;
}
}
public
void
test
()
throws
Exception
{
...
...
@@ -109,38 +126,46 @@ public class TestMultiThreaded extends TestBase {
int
size
=
getSize
(
2
,
4
);
Connection
[]
connList
=
new
Connection
[
size
];
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
connList
[
i
]
=
getConnection
(
"multiThreaded;MULTI_THREADED=1"
);
connList
[
i
]
=
getConnection
(
"multiThreaded;MULTI_THREADED=1
;TRACE_LEVEL_SYSTEM_OUT=1
"
);
}
Connection
conn
=
connList
[
0
];
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET LOCK_TIMEOUT 10000"
);
stat
.
execute
(
"CREATE SEQUENCE TEST_SEQ"
);
stat
.
execute
(
"CREATE TABLE TEST(ID BIGINT DEFAULT NEXT VALUE FOR TEST_SEQ, NAME VARCHAR)"
);
// stat.execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)");
// stat.execute("CREATE INDEX IDX_TEST_NAME ON TEST(NAME)");
trace
(
"init done"
);
Processor
[]
processors
=
new
Processor
[
size
];
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
conn
=
connList
[
i
];
conn
.
createStatement
().
execute
(
"SET LOCK_TIMEOUT 1000"
);
processors
[
i
]
=
new
Processor
(
conn
,
i
);
processors
[
i
].
start
();
trace
(
"started "
+
i
);
Thread
.
sleep
(
100
);
}
for
(
int
t
=
0
;
t
<
2
;
t
++)
{
Thread
.
sleep
(
1000
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
Processor
p
=
processors
[
i
];
if
(
p
.
getException
()
!=
null
)
{
throw
new
Exception
(
p
.
getException
());
throw
new
Exception
(
""
+
i
,
p
.
getException
());
}
}
}
trace
(
"stopping"
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
Processor
p
=
processors
[
i
];
p
.
stopNow
();
}
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
Processor
p
=
processors
[
i
];
p
.
interrupt
();
p
.
join
(
100
);
if
(
p
.
getException
()
!=
null
)
{
throw
new
Exception
(
p
.
getException
());
}
}
trace
(
"close"
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
connList
[
i
].
close
();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论