Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
bf0a4bb5
提交
bf0a4bb5
authored
7月 17, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Server-less multi-connection mode: more bugs are fixed.
上级
b8f74f1b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
15 行删除
+22
-15
TestFileLockSerialized.java
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
+22
-15
没有找到文件。
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
浏览文件 @
bf0a4bb5
...
@@ -33,13 +33,19 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -33,13 +33,19 @@ public class TestFileLockSerialized extends TestBase {
}
}
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
Class
.
forName
(
"org.h2.Driver
"
);
println
(
"testThreeMostlyReaders true
"
);
testThreeMostlyReaders
(
true
);
testThreeMostlyReaders
(
true
);
println
(
"testThreeMostlyReaders false"
);
testThreeMostlyReaders
(
false
);
testThreeMostlyReaders
(
false
);
println
(
"testTwoReaders"
);
testTwoReaders
();
testTwoReaders
();
println
(
"testTwoWriters"
);
testTwoWriters
();
testTwoWriters
();
println
(
"testPendingWrite"
);
testPendingWrite
();
testPendingWrite
();
println
(
"testKillWriter"
);
testKillWriter
();
testKillWriter
();
println
(
"testConcurrentReadWrite"
);
testConcurrentReadWrite
();
testConcurrentReadWrite
();
}
}
...
@@ -62,13 +68,13 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -62,13 +68,13 @@ public class TestFileLockSerialized extends TestBase {
try
{
try
{
PreparedStatement
p
=
c
.
prepareStatement
(
"select * from test where id = ?"
);
PreparedStatement
p
=
c
.
prepareStatement
(
"select * from test where id = ?"
);
while
(!
stop
[
0
])
{
while
(!
stop
[
0
])
{
Thread
.
sleep
(
100
);
if
(
write
)
{
if
(
write
)
{
if
(
Math
.
random
()
>
0.9
)
{
if
(
Math
.
random
()
>
0.9
)
{
c
.
createStatement
().
execute
(
"update test set id = id"
);
c
.
createStatement
().
execute
(
"update test set id = id"
);
}
}
}
}
p
.
setInt
(
1
,
1
);
p
.
setInt
(
1
,
1
);
Thread
.
sleep
(
10
);
p
.
executeQuery
();
p
.
executeQuery
();
p
.
clearParameters
();
p
.
clearParameters
();
}
}
...
@@ -81,7 +87,7 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -81,7 +87,7 @@ public class TestFileLockSerialized extends TestBase {
t
.
start
();
t
.
start
();
threads
[
i
]
=
t
;
threads
[
i
]
=
t
;
}
}
Thread
.
sleep
(
10
00
);
Thread
.
sleep
(
4
00
);
stop
[
0
]
=
true
;
stop
[
0
]
=
true
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
threads
[
i
].
join
();
threads
[
i
].
join
();
...
@@ -118,17 +124,18 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -118,17 +124,18 @@ public class TestFileLockSerialized extends TestBase {
public
void
run
()
{
public
void
run
()
{
while
(!
stop
[
0
])
{
while
(!
stop
[
0
])
{
try
{
try
{
Thread
.
sleep
(
10
);
Connection
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Connection
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
conn
.
createStatement
().
execute
(
"select * from test"
);
conn
.
createStatement
().
execute
(
"select * from test"
);
conn
.
close
();
conn
.
close
();
}
catch
(
SQL
Exception
e
)
{
}
catch
(
Exception
e
)
{
// ignore
// ignore
}
}
}
}
}
}
}.
start
();
}.
start
();
Thread
.
sleep
(
10
0
);
Thread
.
sleep
(
2
0
);
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"drop table test"
);
...
@@ -151,7 +158,7 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -151,7 +158,7 @@ public class TestFileLockSerialized extends TestBase {
Connection
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Connection
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key)"
);
stat
.
execute
(
"create table test(id int primary key)"
);
Thread
.
sleep
(
5
00
);
Thread
.
sleep
(
1
00
);
String
propFile
=
baseDir
+
"/fileLockSerialized.lock.db"
;
String
propFile
=
baseDir
+
"/fileLockSerialized.lock.db"
;
SortedProperties
p
=
SortedProperties
.
loadProperties
(
propFile
);
SortedProperties
p
=
SortedProperties
.
loadProperties
(
propFile
);
p
.
setProperty
(
"changePending"
,
"true"
);
p
.
setProperty
(
"changePending"
,
"true"
);
...
@@ -162,7 +169,7 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -162,7 +169,7 @@ public class TestFileLockSerialized extends TestBase {
}
finally
{
}
finally
{
out
.
close
();
out
.
close
();
}
}
Thread
.
sleep
(
5
00
);
Thread
.
sleep
(
1
00
);
stat
.
execute
(
"select * from test"
);
stat
.
execute
(
"select * from test"
);
conn
.
close
();
conn
.
close
();
}
}
...
@@ -199,7 +206,7 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -199,7 +206,7 @@ public class TestFileLockSerialized extends TestBase {
// ;TRACE_LEVEL_SYSTEM_OUT=3
// ;TRACE_LEVEL_SYSTEM_OUT=3
// String readUrl = writeUrl + ";ACCESS_MODE_LOG=R;ACCESS_MODE_DATA=R";
// String readUrl = writeUrl + ";ACCESS_MODE_LOG=R;ACCESS_MODE_DATA=R";
trace
(
"create database"
);
trace
(
"
create database"
);
Class
.
forName
(
"org.h2.Driver"
);
Class
.
forName
(
"org.h2.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Connection
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
...
@@ -212,12 +219,12 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -212,12 +219,12 @@ public class TestFileLockSerialized extends TestBase {
Statement
stat2
=
conn2
.
createStatement
();
Statement
stat2
=
conn2
.
createStatement
();
printResult
(
stat2
,
"select * from test"
);
printResult
(
stat2
,
"select * from test"
);
stat2
.
execute
(
"create local temporary table temp(name varchar)"
);
stat2
.
execute
(
"create local temporary table temp(name varchar)
not persistent
"
);
printResult
(
stat2
,
"select * from temp"
);
printResult
(
stat2
,
"select * from temp"
);
trace
(
"insert row 1"
);
trace
(
"
insert row 1"
);
stat
.
execute
(
"insert into test values(1)"
);
stat
.
execute
(
"insert into test values(1)"
);
trace
(
"insert row 2"
);
trace
(
"
insert row 2"
);
prep3
.
setInt
(
1
,
2
);
prep3
.
setInt
(
1
,
2
);
prep3
.
execute
();
prep3
.
execute
();
printResult
(
stat2
,
"select * from test"
);
printResult
(
stat2
,
"select * from test"
);
...
@@ -229,13 +236,13 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -229,13 +236,13 @@ public class TestFileLockSerialized extends TestBase {
}
}
private
void
printResult
(
Statement
stat
,
String
sql
)
throws
SQLException
{
private
void
printResult
(
Statement
stat
,
String
sql
)
throws
SQLException
{
trace
(
"query: "
+
sql
);
trace
(
"
query: "
+
sql
);
ResultSet
rs
=
stat
.
executeQuery
(
sql
);
ResultSet
rs
=
stat
.
executeQuery
(
sql
);
int
rowCount
=
0
;
int
rowCount
=
0
;
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
trace
(
" "
+
rs
.
getString
(
1
));
trace
(
"
"
+
rs
.
getString
(
1
));
rowCount
++;
rowCount
++;
}
}
trace
(
" "
+
rowCount
+
" row(s)"
);
trace
(
"
"
+
rowCount
+
" row(s)"
);
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论