Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
6fad76b1
提交
6fad76b1
authored
2月 17, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
bfe7a536
隐藏空白字符变更
内嵌
并排
正在显示
26 个修改的文件
包含
305 行增加
和
22 行删除
+305
-22
ConstraintCheck.java
h2/src/main/org/h2/constraint/ConstraintCheck.java
+2
-1
ConstraintReferential.java
h2/src/main/org/h2/constraint/ConstraintReferential.java
+1
-0
ConstraintUnique.java
h2/src/main/org/h2/constraint/ConstraintUnique.java
+1
-0
Comment.java
h2/src/main/org/h2/engine/Comment.java
+1
-0
Database.java
h2/src/main/org/h2/engine/Database.java
+1
-1
FunctionAlias.java
h2/src/main/org/h2/engine/FunctionAlias.java
+1
-0
Right.java
h2/src/main/org/h2/engine/Right.java
+1
-0
Role.java
h2/src/main/org/h2/engine/Role.java
+1
-0
Setting.java
h2/src/main/org/h2/engine/Setting.java
+2
-1
User.java
h2/src/main/org/h2/engine/User.java
+1
-0
UserAggregate.java
h2/src/main/org/h2/engine/UserAggregate.java
+1
-0
UserDataType.java
h2/src/main/org/h2/engine/UserDataType.java
+1
-0
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+1
-0
Constant.java
h2/src/main/org/h2/schema/Constant.java
+1
-0
Schema.java
h2/src/main/org/h2/schema/Schema.java
+1
-0
Sequence.java
h2/src/main/org/h2/schema/Sequence.java
+2
-1
TriggerObject.java
h2/src/main/org/h2/schema/TriggerObject.java
+2
-1
FileSystemDisk.java
h2/src/main/org/h2/store/fs/FileSystemDisk.java
+1
-1
Table.java
h2/src/main/org/h2/table/Table.java
+9
-7
TableData.java
h2/src/main/org/h2/table/TableData.java
+2
-1
TableLink.java
h2/src/main/org/h2/table/TableLink.java
+1
-0
TableView.java
h2/src/main/org/h2/table/TableView.java
+1
-0
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+5
-3
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+1
-1
TestKillRestart.java
h2/src/test/org/h2/test/synth/TestKillRestart.java
+3
-4
TestKillRestartMulti.java
h2/src/test/org/h2/test/synth/TestKillRestartMulti.java
+261
-0
没有找到文件。
h2/src/main/org/h2/constraint/ConstraintCheck.java
浏览文件 @
6fad76b1
...
...
@@ -75,8 +75,9 @@ public class ConstraintCheck extends Constraint {
return
getCreateSQLForCopy
(
table
,
getSQL
());
}
public
void
removeChildrenAndResources
(
Session
session
)
{
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
table
.
removeConstraint
(
this
);
database
.
removeMeta
(
session
,
getId
());
filter
=
null
;
expr
=
null
;
table
=
null
;
...
...
h2/src/main/org/h2/constraint/ConstraintReferential.java
浏览文件 @
6fad76b1
...
...
@@ -207,6 +207,7 @@ public class ConstraintReferential extends Constraint {
if
(
refIndexOwner
)
{
refTable
.
removeIndexOrTransferOwnership
(
session
,
refIndex
);
}
database
.
removeMeta
(
session
,
getId
());
refTable
=
null
;
index
=
null
;
refIndex
=
null
;
...
...
h2/src/main/org/h2/constraint/ConstraintUnique.java
浏览文件 @
6fad76b1
...
...
@@ -116,6 +116,7 @@ public class ConstraintUnique extends Constraint {
if
(
indexOwner
)
{
table
.
removeIndexOrTransferOwnership
(
session
,
index
);
}
database
.
removeMeta
(
session
,
getId
());
index
=
null
;
columns
=
null
;
table
=
null
;
...
...
h2/src/main/org/h2/engine/Comment.java
浏览文件 @
6fad76b1
...
...
@@ -84,6 +84,7 @@ public class Comment extends DbObjectBase {
}
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
database
.
removeMeta
(
session
,
getId
());
}
public
void
checkRename
()
throws
SQLException
{
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
6fad76b1
...
...
@@ -673,7 +673,7 @@ public class Database implements DataHandler {
}
}
p
rivate
synchronized
void
removeMeta
(
Session
session
,
int
id
)
throws
SQLException
{
p
ublic
synchronized
void
removeMeta
(
Session
session
,
int
id
)
throws
SQLException
{
SearchRow
r
=
meta
.
getTemplateSimpleRow
(
false
);
r
.
setValue
(
0
,
ValueInt
.
get
(
id
));
Cursor
cursor
=
metaIdIndex
.
find
(
session
,
r
,
r
);
...
...
h2/src/main/org/h2/engine/FunctionAlias.java
浏览文件 @
6fad76b1
...
...
@@ -138,6 +138,7 @@ public class FunctionAlias extends DbObjectBase {
}
public
synchronized
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
database
.
removeMeta
(
session
,
getId
());
className
=
methodName
=
null
;
javaMethod
=
null
;
invalidate
();
...
...
h2/src/main/org/h2/engine/Right.java
浏览文件 @
6fad76b1
...
...
@@ -106,6 +106,7 @@ public class Right extends DbObjectBase {
}
else
{
grantee
.
revokeRole
(
session
,
grantedRole
);
}
database
.
removeMeta
(
session
,
getId
());
grantedRole
=
null
;
grantedTable
=
null
;
grantee
=
null
;
...
...
h2/src/main/org/h2/engine/Role.java
浏览文件 @
6fad76b1
...
...
@@ -66,6 +66,7 @@ public class Role extends RightOwner {
database
.
removeDatabaseObject
(
session
,
right
);
}
}
database
.
removeMeta
(
session
,
getId
());
invalidate
();
}
...
...
h2/src/main/org/h2/engine/Setting.java
浏览文件 @
6fad76b1
...
...
@@ -63,7 +63,8 @@ public class Setting extends DbObjectBase {
return
DbObject
.
SETTING
;
}
public
void
removeChildrenAndResources
(
Session
session
)
{
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
database
.
removeMeta
(
session
,
getId
());
invalidate
();
}
...
...
h2/src/main/org/h2/engine/User.java
浏览文件 @
6fad76b1
...
...
@@ -172,6 +172,7 @@ public class User extends RightOwner {
database
.
removeDatabaseObject
(
session
,
right
);
}
}
database
.
removeMeta
(
session
,
getId
());
salt
=
null
;
ByteUtils
.
clear
(
passwordHash
);
passwordHash
=
null
;
...
...
h2/src/main/org/h2/engine/UserAggregate.java
浏览文件 @
6fad76b1
...
...
@@ -64,6 +64,7 @@ public class UserAggregate extends DbObjectBase {
}
public
synchronized
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
database
.
removeMeta
(
session
,
getId
());
className
=
null
;
javaClass
=
null
;
invalidate
();
...
...
h2/src/main/org/h2/engine/UserDataType.java
浏览文件 @
6fad76b1
...
...
@@ -48,6 +48,7 @@ public class UserDataType extends DbObjectBase {
}
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
database
.
removeMeta
(
session
,
getId
());
}
public
void
checkRename
()
throws
SQLException
{
...
...
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
6fad76b1
...
...
@@ -151,6 +151,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
table
.
removeIndex
(
this
);
remove
(
session
);
database
.
removeMeta
(
session
,
getId
());
}
public
boolean
canFindNext
()
{
...
...
h2/src/main/org/h2/schema/Constant.java
浏览文件 @
6fad76b1
...
...
@@ -49,6 +49,7 @@ public class Constant extends SchemaObjectBase {
}
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
database
.
removeMeta
(
session
,
getId
());
invalidate
();
}
...
...
h2/src/main/org/h2/schema/Schema.java
浏览文件 @
6fad76b1
...
...
@@ -107,6 +107,7 @@ public class Schema extends DbObjectBase {
Constant
obj
=
(
Constant
)
constants
.
values
().
toArray
()[
0
];
database
.
removeSchemaObject
(
session
,
obj
);
}
database
.
removeMeta
(
session
,
getId
());
owner
=
null
;
invalidate
();
}
...
...
h2/src/main/org/h2/schema/Sequence.java
浏览文件 @
6fad76b1
...
...
@@ -117,7 +117,8 @@ public class Sequence extends SchemaObjectBase {
return
DbObject
.
SEQUENCE
;
}
public
void
removeChildrenAndResources
(
Session
session
)
{
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
database
.
removeMeta
(
session
,
getId
());
invalidate
();
}
...
...
h2/src/main/org/h2/schema/TriggerObject.java
浏览文件 @
6fad76b1
...
...
@@ -236,8 +236,9 @@ public class TriggerObject extends SchemaObjectBase {
return
DbObject
.
TRIGGER
;
}
public
void
removeChildrenAndResources
(
Session
session
)
{
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
table
.
removeTrigger
(
session
,
this
);
database
.
removeMeta
(
session
,
getId
());
table
=
null
;
triggerClassName
=
null
;
triggerCallback
=
null
;
...
...
h2/src/main/org/h2/store/fs/FileSystemDisk.java
浏览文件 @
6fad76b1
...
...
@@ -54,7 +54,7 @@ public class FileSystemDisk extends FileSystem {
public
void
rename
(
String
oldName
,
String
newName
)
throws
SQLException
{
File
oldFile
=
new
File
(
oldName
);
File
newFile
=
new
File
(
newName
);
if
(
oldFile
.
get
Name
().
equals
(
newFile
.
getName
()))
{
if
(
oldFile
.
get
AbsolutePath
().
equals
(
newFile
.
getAbsolutePath
()))
{
throw
Message
.
getInternalError
(
"rename file old=new"
);
}
if
(!
oldFile
.
exists
())
{
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
6fad76b1
...
...
@@ -332,13 +332,6 @@ public abstract class Table extends SchemaObjectBase {
constraints
.
remove
(
0
);
database
.
removeSchemaObject
(
session
,
constraint
);
}
while
(
sequences
!=
null
&&
sequences
.
size
()
>
0
)
{
Sequence
sequence
=
(
Sequence
)
sequences
.
get
(
0
);
sequences
.
remove
(
0
);
if
(!
getTemporary
())
{
database
.
removeSchemaObject
(
session
,
sequence
);
}
}
ObjectArray
rights
=
database
.
getAllRights
();
for
(
int
i
=
0
;
i
<
rights
.
size
();
i
++)
{
Right
right
=
(
Right
)
rights
.
get
(
i
);
...
...
@@ -346,6 +339,15 @@ public abstract class Table extends SchemaObjectBase {
database
.
removeDatabaseObject
(
session
,
right
);
}
}
database
.
removeMeta
(
session
,
getId
());
// must delete sequences later (in case there is a power failure before removing the table object)
while
(
sequences
!=
null
&&
sequences
.
size
()
>
0
)
{
Sequence
sequence
=
(
Sequence
)
sequences
.
get
(
0
);
sequences
.
remove
(
0
);
if
(!
getTemporary
())
{
database
.
removeSchemaObject
(
session
,
sequence
);
}
}
}
public
void
checkColumnIsNotReferenced
(
Column
col
)
throws
SQLException
{
...
...
h2/src/main/org/h2/table/TableData.java
浏览文件 @
6fad76b1
...
...
@@ -115,7 +115,7 @@ public class TableData extends Table implements RecordReader {
throw
Message
.
convert
(
e
);
}
}
private
void
checkRowCount
(
Session
session
,
Index
index
,
int
offset
)
{
if
(
SysProperties
.
CHECK
&&
!
database
.
isMultiVersion
())
{
long
rc
=
index
.
getRowCount
(
session
);
...
...
@@ -498,6 +498,7 @@ public class TableData extends Table implements RecordReader {
}
}
scanIndex
.
remove
(
session
);
database
.
removeMeta
(
session
,
getId
());
scanIndex
=
null
;
lockExclusive
=
null
;
lockShared
=
null
;
...
...
h2/src/main/org/h2/table/TableLink.java
浏览文件 @
6fad76b1
...
...
@@ -326,6 +326,7 @@ public class TableLink extends Table {
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
super
.
removeChildrenAndResources
(
session
);
close
(
session
);
database
.
removeMeta
(
session
,
getId
());
driver
=
null
;
url
=
user
=
password
=
originalTable
=
null
;
conn
=
null
;
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
6fad76b1
...
...
@@ -221,6 +221,7 @@ public class TableView extends Table {
public
void
removeChildrenAndResources
(
Session
session
)
throws
SQLException
{
removeViewFromTables
();
super
.
removeChildrenAndResources
(
session
);
database
.
removeMeta
(
session
,
getId
());
querySQL
=
null
;
index
=
null
;
invalidate
();
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
6fad76b1
...
...
@@ -75,6 +75,7 @@ import org.h2.test.synth.TestHaltApp;
import
org.h2.test.synth.TestJoin
;
import
org.h2.test.synth.TestKill
;
import
org.h2.test.synth.TestKillRestart
;
import
org.h2.test.synth.TestKillRestartMulti
;
import
org.h2.test.synth.TestRandomSQL
;
import
org.h2.test.synth.TestTimer
;
import
org.h2.test.synth.sql.TestSynth
;
...
...
@@ -174,7 +175,7 @@ Adjust cache memory usage
Test Recovery with MAX_LOG_FILE_SIZE=1; test with various log file sizes
History:
CSV tool now support lineSeparator
Roadmap:
...
...
@@ -472,6 +473,7 @@ DROP TABLE MY_TEST;
new
TestCrashAPI
().
runTest
(
this
);
new
TestRandomSQL
().
runTest
(
this
);
new
TestKillRestart
().
runTest
(
this
);
new
TestKillRestartMulti
().
runTest
(
this
);
// unit
new
TestBitField
().
runTest
(
this
);
...
...
@@ -513,10 +515,10 @@ DROP TABLE MY_TEST;
test
.
runTest
(
this
);
}
catch
(
Exception
e
)
{
// ignore
TestBase
.
logError
(
"Class not found: "
+
className
,
null
);
TestBase
.
printlnWithTime
(
0
,
className
+
" class not found"
);
}
catch
(
NoClassDefFoundError
e
)
{
// ignore
TestBase
.
logError
(
"Class not found: "
+
className
,
null
);
TestBase
.
printlnWithTime
(
0
,
className
+
" class not found"
);
}
}
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
6fad76b1
...
...
@@ -247,7 +247,7 @@ public abstract class TestBase {
printlnWithTime
(
time
,
getClass
().
getName
()
+
" "
+
s
);
}
private
static
void
printlnWithTime
(
long
time
,
String
s
)
{
static
void
printlnWithTime
(
long
time
,
String
s
)
{
String
t
=
"0000000000"
+
time
;
t
=
t
.
substring
(
t
.
length
()
-
6
);
System
.
out
.
println
(
t
+
" "
+
s
);
...
...
h2/src/test/org/h2/test/synth/TestKillRestart.java
浏览文件 @
6fad76b1
...
...
@@ -24,9 +24,9 @@ public class TestKillRestart extends TestBase {
if
(
config
.
networked
)
{
return
;
}
deleteDb
(
"
corrup
t"
);
String
url
=
getURL
(
"
corrup
t"
,
true
);
// String url = getURL("
corrup
t;CACHE_SIZE=2048;WRITE_DELAY=0;STORAGE=TEXT", true);
deleteDb
(
"
killRestar
t"
);
String
url
=
getURL
(
"
killRestar
t"
,
true
);
// String url = getURL("
killRestar
t;CACHE_SIZE=2048;WRITE_DELAY=0;STORAGE=TEXT", true);
String
user
=
getUser
(),
password
=
getPassword
();
String
[]
procDef
=
new
String
[]
{
"java"
,
"-cp"
,
"bin"
,
getClass
().
getName
(),
"-url"
,
url
,
"-user"
,
user
,
...
...
@@ -35,7 +35,6 @@ public class TestKillRestart extends TestBase {
int
len
=
getSize
(
2
,
15
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
Process
p
=
Runtime
.
getRuntime
().
exec
(
procDef
);
// InputStream err = p.getErrorStream();
InputStream
in
=
p
.
getInputStream
();
OutputCatcher
catcher
=
new
OutputCatcher
(
in
);
catcher
.
start
();
...
...
h2/src/test/org/h2/test/synth/TestKillRestartMulti.java
0 → 100644
浏览文件 @
6fad76b1
/*
* Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
synth
;
import
java.io.InputStream
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
java.util.Random
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Backup
;
import
org.h2.util.FileUtils
;
/**
* Standalone recovery test. A new process is started and then killed while it
* executes random statements using multiple connection.
*/
public
class
TestKillRestartMulti
extends
TestBase
{
private
String
driver
=
"org.h2.Driver"
;
private
String
url
=
null
,
user
=
"sa"
,
password
=
"sa"
;
private
ArrayList
connections
=
new
ArrayList
();
private
ArrayList
tables
=
new
ArrayList
();
private
int
openCount
;
public
void
test
()
throws
Exception
{
if
(
config
.
networked
)
{
return
;
}
deleteDb
(
"killRestartMulti"
);
url
=
getURL
(
"killRestartMulti"
,
true
);
// String url = getURL("killRestartMulti;CACHE_SIZE=2048;WRITE_DELAY=0;STORAGE=TEXT", true);
user
=
getUser
();
password
=
getPassword
();
String
[]
procDef
=
new
String
[]
{
"java"
,
"-cp"
,
"bin"
,
getClass
().
getName
(),
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
};
deleteDb
(
"killRestartMulti"
);
int
len
=
getSize
(
3
,
10
);
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
Process
p
=
Runtime
.
getRuntime
().
exec
(
procDef
);
InputStream
in
=
p
.
getInputStream
();
OutputCatcher
catcher
=
new
OutputCatcher
(
in
);
catcher
.
start
();
while
(
true
)
{
String
s
=
catcher
.
readLine
(
5
*
60
*
1000
);
// System.out.println("> " + s);
if
(
s
==
null
)
{
error
(
"No reply from process"
);
}
else
if
(!
s
.
startsWith
(
"#"
))
{
// System.out.println(s);
error
(
"Expected: #..., got: "
+
s
);
}
else
if
(
s
.
startsWith
(
"#Running"
))
{
int
sleep
=
10
+
random
.
nextInt
(
100
);
Thread
.
sleep
(
sleep
);
printTime
(
"killing: "
+
i
);
p
.
destroy
();
break
;
}
else
if
(
s
.
startsWith
(
"#Info"
))
{
// System.out.println(s);
}
else
if
(
s
.
startsWith
(
"#Fail"
))
{
System
.
err
.
println
(
s
);
while
(
true
)
{
String
a
=
catcher
.
readLine
(
5
*
60
*
1000
);
if
(
a
==
null
||
"#End"
.
endsWith
(
a
))
{
break
;
}
System
.
err
.
println
(
" "
+
a
);
}
error
(
"Failed: "
+
s
);
}
}
String
backup
=
baseDir
+
"/killRestartMulti-"
+
System
.
currentTimeMillis
()
+
".zip"
;
try
{
Backup
.
execute
(
backup
,
baseDir
,
"killRestartMulti"
,
true
);
Connection
conn
=
openConnection
();
testConsistent
(
conn
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"DROP ALL OBJECTS"
);
conn
.
close
();
conn
=
openConnection
();
conn
.
close
();
FileUtils
.
delete
(
backup
);
}
catch
(
SQLException
e
)
{
FileUtils
.
rename
(
backup
,
backup
+
".error"
);
throw
e
;
}
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
TestKillRestartMulti
().
test
(
args
);
}
void
test
(
String
[]
args
)
throws
Exception
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
"-url"
.
equals
(
args
[
i
]))
{
url
=
args
[++
i
];
}
else
if
(
"-driver"
.
equals
(
args
[
i
]))
{
driver
=
args
[++
i
];
}
else
if
(
"-user"
.
equals
(
args
[
i
]))
{
user
=
args
[++
i
];
}
else
if
(
"-password"
.
equals
(
args
[
i
]))
{
password
=
args
[++
i
];
}
}
System
.
out
.
println
(
"#Started; driver: "
+
driver
+
" url: "
+
url
+
" user: "
+
user
+
" password: "
+
password
);
try
{
System
.
out
.
println
(
"#Starting..."
);
Random
random
=
new
Random
();
boolean
wasRunning
=
false
;
for
(
int
i
=
0
;
i
<
3000
;
i
++)
{
if
(
i
>
1000
&&
connections
.
size
()
>
1
&&
tables
.
size
()
>
1
)
{
System
.
out
.
println
(
"#Running connections: "
+
connections
.
size
()
+
" tables: "
+
tables
.
size
());
wasRunning
=
true
;
}
if
(
connections
.
size
()
<
1
)
{
openConnection
();
}
if
(
tables
.
size
()
<
1
)
{
createTable
(
random
);
}
int
p
=
random
.
nextInt
(
100
);
int
todoLargeInsertsDeletes
;
int
todoAlterTable
;
if
((
p
-=
2
)
<=
0
)
{
// 2%: open new connection
if
(
connections
.
size
()
<
5
)
{
openConnection
();
}
}
else
if
((
p
-=
1
)
<=
0
)
{
// 1%: close connection
if
(
connections
.
size
()
>
1
)
{
Connection
conn
=
(
Connection
)
connections
.
remove
(
random
.
nextInt
(
connections
.
size
()));
if
(
random
.
nextBoolean
())
{
conn
.
close
();
}
}
}
else
if
((
p
-=
10
)
<=
0
)
{
// 10% create table
createTable
(
random
);
}
else
if
((
p
-=
20
)
<=
0
)
{
// 20% large insert, delete, or update
if
(
tables
.
size
()
>
0
)
{
Connection
conn
=
(
Connection
)
connections
.
get
(
random
.
nextInt
(
connections
.
size
()));
Statement
stat
=
conn
.
createStatement
();
String
table
=
(
String
)
tables
.
get
(
random
.
nextInt
(
tables
.
size
()));
if
(
random
.
nextBoolean
())
{
// 10% insert
stat
.
execute
(
"INSERT INTO "
+
table
+
"(NAME) SELECT 'Hello ' || X FROM SYSTEM_RANGE(0, 20)"
);
}
else
if
(
random
.
nextBoolean
())
{
// 5% update
stat
.
execute
(
"UPDATE "
+
table
+
" SET NAME='Hallo Welt'"
);
}
else
{
// 5% delete
stat
.
execute
(
"DELETE FROM "
+
table
);
}
}
}
else
if
((
p
-=
5
)
<
0
)
{
// 5% truncate or drop table
if
(
tables
.
size
()
>
0
)
{
Connection
conn
=
(
Connection
)
connections
.
get
(
random
.
nextInt
(
connections
.
size
()));
Statement
stat
=
conn
.
createStatement
();
String
table
=
(
String
)
tables
.
get
(
random
.
nextInt
(
tables
.
size
()));
if
(
random
.
nextBoolean
())
{
stat
.
execute
(
"TRUNCATE TABLE "
+
table
);
}
else
{
stat
.
execute
(
"DROP TABLE "
+
table
);
System
.
out
.
println
(
"#Info table dropped: "
+
table
);
tables
.
remove
(
table
);
}
}
}
else
if
((
p
-=
30
)
<=
0
)
{
// 30% insert
if
(
tables
.
size
()
>
0
)
{
Connection
conn
=
(
Connection
)
connections
.
get
(
random
.
nextInt
(
connections
.
size
()));
Statement
stat
=
conn
.
createStatement
();
String
table
=
(
String
)
tables
.
get
(
random
.
nextInt
(
tables
.
size
()));
stat
.
execute
(
"INSERT INTO "
+
table
+
"(NAME) VALUES('Hello World')"
);
}
}
else
{
// 32% delete
if
(
tables
.
size
()
>
0
)
{
Connection
conn
=
(
Connection
)
connections
.
get
(
random
.
nextInt
(
connections
.
size
()));
Statement
stat
=
conn
.
createStatement
();
String
table
=
(
String
)
tables
.
get
(
random
.
nextInt
(
tables
.
size
()));
stat
.
execute
(
"DELETE FROM "
+
table
+
" WHERE ID = SELECT MIN(ID) FROM "
+
table
);
}
}
}
System
.
out
.
println
(
"#Fail: end "
+
wasRunning
);
System
.
out
.
println
(
"#End"
);
}
catch
(
Throwable
e
)
{
System
.
out
.
println
(
"#Fail: openCount="
+
openCount
+
" url="
+
url
+
" "
+
e
.
toString
());
e
.
printStackTrace
(
System
.
out
);
System
.
out
.
println
(
"#End"
);
}
}
Connection
openConnection
()
throws
Exception
{
Class
.
forName
(
driver
);
openCount
++;
Connection
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
connections
.
add
(
conn
);
return
conn
;
}
void
createTable
(
Random
random
)
throws
Exception
{
Connection
conn
=
(
Connection
)
connections
.
get
(
random
.
nextInt
(
connections
.
size
()));
Statement
stat
=
conn
.
createStatement
();
String
table
=
"TEST"
+
random
.
nextInt
(
10
);
try
{
stat
.
execute
(
"CREATE TABLE "
+
table
+
"(ID IDENTITY, NAME VARCHAR)"
);
System
.
out
.
println
(
"#Info table created: "
+
table
);
tables
.
add
(
table
);
}
catch
(
SQLException
e
)
{
if
(
e
.
getErrorCode
()
==
ErrorCode
.
TABLE_OR_VIEW_ALREADY_EXISTS_1
)
{
System
.
out
.
println
(
"#Info table already exists: "
+
table
);
if
(!
tables
.
contains
(
table
))
{
tables
.
add
(
table
);
}
// ok
}
else
{
throw
e
;
}
}
}
void
testConsistent
(
Connection
conn
)
throws
Exception
{
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
Statement
stat
=
conn
.
createStatement
();
try
{
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
+
i
);
while
(
rs
.
next
())
{
rs
.
getLong
(
"ID"
);
rs
.
getString
(
"NAME"
);
}
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
+
i
+
" ORDER BY ID"
);
while
(
rs
.
next
())
{
rs
.
getLong
(
"ID"
);
rs
.
getString
(
"NAME"
);
}
}
catch
(
SQLException
e
)
{
if
(
e
.
getErrorCode
()
==
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
)
{
// ok
}
else
{
throw
e
;
}
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论