Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
4661db7b
提交
4661db7b
authored
1月 15, 2010
作者:
christian.peter.io
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test case for auto increment
上级
2e025903
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
75 行增加
和
0 行删除
+75
-0
TestFileLockSerialized.java
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
+75
-0
没有找到文件。
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
浏览文件 @
4661db7b
...
...
@@ -36,6 +36,8 @@ public class TestFileLockSerialized extends TestBase {
}
public
void
test
()
throws
Exception
{
println
(
"testAutoIncrement"
);
testAutoIncrement
();
println
(
"testSequenceFlush"
);
testSequenceFlush
();
println
(
"testLeftLogFiles"
);
...
...
@@ -308,6 +310,79 @@ public class TestFileLockSerialized extends TestBase {
}
}
private
void
testAutoIncrement
()
throws
Exception
{
boolean
longRun
=
false
;
if
(
longRun
)
{
for
(
int
waitTime
=
100
;
waitTime
<
10000
;
waitTime
+=
20
)
{
for
(
int
howManyThreads
=
1
;
howManyThreads
<
10
;
howManyThreads
++)
{
testAutoIncrement
(
waitTime
,
howManyThreads
,
2000
);
}
}
}
else
{
testAutoIncrement
(
400
,
2
,
2000
);
}
}
private
void
testAutoIncrement
(
final
int
waitTime
,
int
howManyThreads
,
int
runTime
)
throws
Exception
{
println
(
"testAutoIncrement waitTime: "
+
waitTime
+
" howManyThreads: "
+
howManyThreads
+
" runTime: "
+
runTime
);
deleteDb
(
"fileLockSerialized"
);
final
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;"
+
"AUTO_RECONNECT=TRUE;MAX_LENGTH_INPLACE_LOB=8192;COMPRESS_LOB=DEFLATE;LOG=2;CACHE_SIZE=65536"
;
Connection
c
=
DriverManager
.
getConnection
(
url
);
c
.
createStatement
().
execute
(
"create table test(id int auto_increment, id2 int)"
);
c
.
close
();
final
long
endTime
=
System
.
currentTimeMillis
()
+
runTime
;
final
Exception
[]
ex
=
new
Exception
[
1
];
final
Connection
[]
connList
=
new
Connection
[
howManyThreads
];
final
boolean
[]
stop
=
new
boolean
[
1
];
final
int
[]
nextInt
=
{
0
};
Thread
[]
threads
=
new
Thread
[
howManyThreads
];
for
(
int
i
=
0
;
i
<
howManyThreads
;
i
++)
{
final
int
finalNrOfConnection
=
i
;
Thread
t
=
new
Thread
(
new
Runnable
()
{
public
void
run
()
{
try
{
Connection
c
=
DriverManager
.
getConnection
(
url
);
connList
[
finalNrOfConnection
]
=
c
;
while
(!
stop
[
0
])
{
synchronized
(
nextInt
)
{
ResultSet
rs
=
c
.
createStatement
().
executeQuery
(
"select id, id2 from test"
);
while
(
rs
.
next
())
{
if
(
rs
.
getInt
(
1
)
!=
rs
.
getInt
(
2
))
{
throw
new
Exception
(
Thread
.
currentThread
().
getId
()
+
" nextInt: "
+
nextInt
[
0
]
+
" rs.getInt(1): "
+
rs
.
getInt
(
1
)
+
" rs.getInt(2): "
+
rs
.
getInt
(
2
));
}
}
nextInt
[
0
]++;
c
.
createStatement
().
execute
(
"insert into test (id2) values("
+
nextInt
[
0
]
+
")"
);
}
Thread
.
sleep
(
waitTime
);
}
c
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
ex
[
0
]
=
e
;
}
}
});
t
.
start
();
threads
[
i
]
=
t
;
}
while
((
ex
[
0
]
==
null
)
&&
(
System
.
currentTimeMillis
()
<
endTime
))
{
Thread
.
sleep
(
10
);
}
stop
[
0
]
=
true
;
for
(
int
i
=
0
;
i
<
howManyThreads
;
i
++)
{
threads
[
i
].
join
();
}
if
(
ex
[
0
]
!=
null
)
{
throw
ex
[
0
];
}
DriverManager
.
getConnection
(
url
).
close
();
deleteDb
(
"fileLockSerialized"
);
}
private
void
testConcurrentUpdates
(
final
int
waitTime
,
int
howManyThreads
,
int
runTime
)
throws
Exception
{
println
(
"testConcurrentUpdates waitTime: "
+
waitTime
+
" howManyThreads: "
+
howManyThreads
+
" runTime: "
+
runTime
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论