Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
eb18c317
提交
eb18c317
authored
12 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Code style.
上级
51de3761
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
292 行增加
和
134 行删除
+292
-134
BenchB.java
h2/src/test/org/h2/test/bench/BenchB.java
+17
-16
BenchC.java
h2/src/test/org/h2/test/bench/BenchC.java
+9
-9
Database.java
h2/src/test/org/h2/test/bench/Database.java
+3
-2
Profile.java
h2/src/test/org/h2/test/coverage/Profile.java
+0
-1
TestPowerOff.java
h2/src/test/org/h2/test/db/TestPowerOff.java
+11
-11
TestBatchUpdates.java
h2/src/test/org/h2/test/jdbc/TestBatchUpdates.java
+5
-4
TestJavaObjectSerializer.java
h2/src/test/org/h2/test/jdbc/TestJavaObjectSerializer.java
+4
-4
TestMetaData.java
h2/src/test/org/h2/test/jdbc/TestMetaData.java
+44
-44
MVRTreeMap.java
h2/src/test/org/h2/test/store/MVRTreeMap.java
+121
-1
TestConcurrent.java
h2/src/test/org/h2/test/store/TestConcurrent.java
+14
-11
TestMVRTree.java
h2/src/test/org/h2/test/store/TestMVRTree.java
+50
-19
TestKill.java
h2/src/test/org/h2/test/synth/TestKill.java
+6
-5
TestPowerOffFs2.java
h2/src/test/org/h2/test/synth/TestPowerOffFs2.java
+4
-3
TestMultiNews.java
h2/src/test/org/h2/test/synth/thread/TestMultiNews.java
+4
-4
没有找到文件。
h2/src/test/org/h2/test/bench/BenchB.java
浏览文件 @
eb18c317
...
...
@@ -21,13 +21,14 @@ import java.util.Random;
*/
public
class
BenchB
implements
Bench
,
Runnable
{
private
static
final
int
SCALE
=
1
;
private
static
final
int
BRANCHES
=
1
;
private
static
final
int
TELLERS
=
10
;
private
static
final
int
ACCOUNTS
=
100000
;
private
static
final
int
CLIENTS
=
10
;
// master data
private
Database
database
;
private
static
final
int
scale
=
1
;
private
static
final
int
branches
=
1
;
private
static
final
int
tellers
=
10
;
private
static
final
int
accounts
=
100000
;
private
static
final
int
clients
=
10
;
private
int
transactionPerClient
;
// client data
...
...
@@ -83,7 +84,7 @@ public class BenchB implements Bench, Runnable {
int
commitEvery
=
1000
;
prep
=
db
.
prepare
(
"INSERT INTO BRANCHES(BID, BBALANCE) VALUES(?, 0)"
);
for
(
int
i
=
0
;
i
<
branches
*
scale
;
i
++)
{
for
(
int
i
=
0
;
i
<
BRANCHES
*
SCALE
;
i
++)
{
prep
.
setInt
(
1
,
i
);
db
.
update
(
prep
,
"insertBranches"
);
if
(
i
%
commitEvery
==
0
)
{
...
...
@@ -93,21 +94,21 @@ public class BenchB implements Bench, Runnable {
db
.
commit
();
prep
=
db
.
prepare
(
"INSERT INTO TELLERS(TID, BID, TBALANCE) VALUES(?, ?, 0)"
);
for
(
int
i
=
0
;
i
<
tellers
*
scale
;
i
++)
{
for
(
int
i
=
0
;
i
<
TELLERS
*
SCALE
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
setInt
(
2
,
i
/
tellers
);
prep
.
setInt
(
2
,
i
/
TELLERS
);
db
.
update
(
prep
,
"insertTellers"
);
if
(
i
%
commitEvery
==
0
)
{
db
.
commit
();
}
}
db
.
commit
();
int
len
=
accounts
*
scale
;
int
len
=
ACCOUNTS
*
SCALE
;
prep
=
db
.
prepare
(
"INSERT INTO ACCOUNTS(AID, BID, ABALANCE) VALUES(?, ?, 0)"
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
setInt
(
2
,
i
/
accounts
);
prep
.
setInt
(
2
,
i
/
ACCOUNTS
);
db
.
update
(
prep
,
"insertAccounts"
);
if
(
i
%
commitEvery
==
0
)
{
db
.
commit
();
...
...
@@ -123,15 +124,15 @@ public class BenchB implements Bench, Runnable {
}
public
void
run
()
{
int
accountsPerBranch
=
accounts
/
branches
;
int
accountsPerBranch
=
ACCOUNTS
/
BRANCHES
;
for
(
int
i
=
0
;
i
<
master
.
transactionPerClient
;
i
++)
{
int
branch
=
random
.
nextInt
(
master
.
branches
);
int
teller
=
random
.
nextInt
(
master
.
tellers
);
int
branch
=
random
.
nextInt
(
BRANCHES
);
int
teller
=
random
.
nextInt
(
TELLERS
);
int
account
;
if
(
random
.
nextInt
(
100
)
<
85
)
{
account
=
random
.
nextInt
(
accountsPerBranch
)
+
branch
*
accountsPerBranch
;
}
else
{
account
=
random
.
nextInt
(
accounts
);
account
=
random
.
nextInt
(
ACCOUNTS
);
}
int
delta
=
random
.
nextInt
(
1000
);
doOne
(
branch
,
teller
,
account
,
delta
);
...
...
@@ -194,8 +195,8 @@ public class BenchB implements Bench, Runnable {
}
private
void
processTransactions
()
throws
Exception
{
Thread
[]
threads
=
new
Thread
[
clients
];
for
(
int
i
=
0
;
i
<
clients
;
i
++)
{
Thread
[]
threads
=
new
Thread
[
CLIENTS
];
for
(
int
i
=
0
;
i
<
CLIENTS
;
i
++)
{
threads
[
i
]
=
new
Thread
(
new
BenchB
(
this
,
i
));
}
for
(
Thread
t
:
threads
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/bench/BenchC.java
浏览文件 @
eb18c317
...
...
@@ -21,8 +21,11 @@ import java.sql.Types;
*/
public
class
BenchC
implements
Bench
{
private
static
final
String
[]
TABLES
=
{
"WAREHOUSE"
,
"DISTRICT"
,
"CUSTOMER"
,
"HISTORY"
,
"ORDERS"
,
private
static
final
int
COMMIT_EVERY
=
1000
;
private
static
final
String
[]
TABLES
=
{
"WAREHOUSE"
,
"DISTRICT"
,
"CUSTOMER"
,
"HISTORY"
,
"ORDERS"
,
"NEW_ORDER"
,
"ITEM"
,
"STOCK"
,
"ORDER_LINE"
,
"RESULTS"
};
private
static
final
String
[]
CREATE_SQL
=
{
"CREATE TABLE WAREHOUSE(\n"
+
" W_ID INT NOT NULL PRIMARY KEY,\n"
+
...
...
@@ -176,9 +179,6 @@ public class BenchC implements Bench {
private
BenchCRandom
random
;
private
String
action
;
private
static
final
int
commitEvery
=
1000
;
public
void
init
(
Database
db
,
int
size
)
throws
SQLException
{
this
.
database
=
db
;
...
...
@@ -248,7 +248,7 @@ public class BenchC implements Bench {
prep
.
setString
(
5
,
data
);
database
.
update
(
prep
,
"insertItem"
);
trace
(
id
,
items
);
if
(
id
%
commitEvery
==
0
)
{
if
(
id
%
COMMIT_EVERY
==
0
)
{
database
.
commit
();
}
}
...
...
@@ -282,7 +282,7 @@ public class BenchC implements Bench {
database
.
update
(
prep
,
"insertWarehouse"
);
loadStock
(
id
);
loadDistrict
(
id
);
if
(
id
%
commitEvery
==
0
)
{
if
(
id
%
COMMIT_EVERY
==
0
)
{
database
.
commit
();
}
}
...
...
@@ -296,7 +296,7 @@ public class BenchC implements Bench {
for
(
int
districtId
=
1
;
districtId
<=
districtsPerWarehouse
;
districtId
++)
{
loadCustomerSub
(
districtId
,
id
);
trace
(
i
++,
max
);
if
(
i
%
commitEvery
==
0
)
{
if
(
i
%
COMMIT_EVERY
==
0
)
{
database
.
commit
();
}
}
...
...
@@ -452,7 +452,7 @@ public class BenchC implements Bench {
prepLine
.
setBigDecimal
(
8
,
amount
);
prepLine
.
setString
(
9
,
distInfo
);
database
.
update
(
prepLine
,
"insertOrderLine"
);
if
(
i
++
%
commitEvery
==
0
)
{
if
(
i
++
%
COMMIT_EVERY
==
0
)
{
database
.
commit
();
}
}
...
...
@@ -502,7 +502,7 @@ public class BenchC implements Bench {
prep
.
setInt
(
16
,
0
);
prep
.
setInt
(
17
,
0
);
database
.
update
(
prep
,
"insertStock"
);
if
(
id
%
commitEvery
==
0
)
{
if
(
id
%
COMMIT_EVERY
==
0
)
{
database
.
commit
();
}
trace
(
id
,
items
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/bench/Database.java
浏览文件 @
eb18c317
...
...
@@ -30,6 +30,8 @@ import org.h2.util.StringUtils;
*/
class
Database
{
private
static
final
boolean
TRACE
=
true
;
private
TestPerformance
test
;
private
int
id
;
private
String
name
,
url
,
user
,
password
;
...
...
@@ -38,7 +40,6 @@ class Database {
private
long
startTime
;
private
Connection
conn
;
private
Statement
stat
;
private
static
final
boolean
trace
=
true
;
private
long
lastTrace
;
private
final
Random
random
=
new
Random
(
1
);
private
final
ArrayList
<
Object
[]>
results
=
new
ArrayList
<
Object
[]>();
...
...
@@ -373,7 +374,7 @@ class Database {
* @param max the maximum value
*/
void
trace
(
String
action
,
int
i
,
int
max
)
{
if
(
trace
)
{
if
(
TRACE
)
{
long
time
=
System
.
currentTimeMillis
();
if
(
i
==
0
||
lastTrace
==
0
)
{
lastTrace
=
time
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/coverage/Profile.java
浏览文件 @
eb18c317
...
...
@@ -12,7 +12,6 @@ import java.io.FileReader;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.LineNumberReader
;
import
java.io.Writer
;
/**
* The class used at runtime to measure the code usage and performance.
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestPowerOff.java
浏览文件 @
eb18c317
...
...
@@ -24,7 +24,7 @@ import org.h2.util.JdbcUtils;
*/
public
class
TestPowerOff
extends
TestBase
{
private
static
final
String
dbName
=
"powerOff"
;
private
static
final
String
DB_NAME
=
"powerOff"
;
private
String
dir
,
url
;
private
int
maxPowerOffCount
;
...
...
@@ -44,10 +44,10 @@ public class TestPowerOff extends TestBase {
}
if
(
config
.
big
||
config
.
googleAppEngine
)
{
dir
=
getBaseDir
();
url
=
dbName
;
url
=
DB_NAME
;
}
else
{
dir
=
"memFS:"
;
url
=
"memFS:/"
+
dbName
;
url
=
"memFS:/"
+
DB_NAME
;
}
url
+=
";FILE_LOCK=NO;TRACE_LEVEL_FILE=0"
;
testLobCrash
();
...
...
@@ -56,14 +56,14 @@ public class TestPowerOff extends TestBase {
testShutdown
();
testMemoryTables
();
testPersistentTables
();
deleteDb
(
dir
,
dbName
);
deleteDb
(
dir
,
DB_NAME
);
}
private
void
testLobCrash
()
throws
SQLException
{
if
(
config
.
networked
)
{
return
;
}
deleteDb
(
dir
,
dbName
);
deleteDb
(
dir
,
DB_NAME
);
Connection
conn
=
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id identity, data clob)"
);
...
...
@@ -97,7 +97,7 @@ public class TestPowerOff extends TestBase {
if
(
config
.
networked
)
{
return
;
}
deleteDb
(
dir
,
dbName
);
deleteDb
(
dir
,
DB_NAME
);
Connection
conn
=
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
...
...
@@ -141,7 +141,7 @@ public class TestPowerOff extends TestBase {
if
(
config
.
networked
)
{
return
;
}
deleteDb
(
dir
,
dbName
);
deleteDb
(
dir
,
DB_NAME
);
Random
random
=
new
Random
(
1
);
SysProperties
.
runFinalize
=
false
;
int
repeat
=
getSize
(
1
,
20
);
...
...
@@ -179,7 +179,7 @@ public class TestPowerOff extends TestBase {
}
private
void
testShutdown
()
throws
SQLException
{
deleteDb
(
dir
,
dbName
);
deleteDb
(
dir
,
DB_NAME
);
Connection
conn
=
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
...
...
@@ -199,7 +199,7 @@ public class TestPowerOff extends TestBase {
if
(
config
.
networked
)
{
return
;
}
deleteDb
(
dir
,
dbName
);
deleteDb
(
dir
,
DB_NAME
);
Connection
conn
=
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
...
...
@@ -239,7 +239,7 @@ public class TestPowerOff extends TestBase {
// individual writes, many thousand operations)
return
;
}
deleteDb
(
dir
,
dbName
);
deleteDb
(
dir
,
DB_NAME
);
// ((JdbcConnection)conn).setPowerOffCount(Integer.MAX_VALUE);
testRun
(
true
);
...
...
@@ -253,7 +253,7 @@ public class TestPowerOff extends TestBase {
private
void
runTest
(
int
min
,
int
max
,
boolean
withConsistencyCheck
)
throws
SQLException
{
for
(
int
i
=
min
;
i
<
max
;
i
++)
{
deleteDb
(
dir
,
dbName
);
deleteDb
(
dir
,
DB_NAME
);
Database
.
setInitialPowerOffCount
(
i
);
int
expect
=
testRun
(
false
);
if
(
withConsistencyCheck
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestBatchUpdates.java
浏览文件 @
eb18c317
...
...
@@ -37,8 +37,9 @@ public class TestBatchUpdates extends TestBase {
private
static
final
String
COFFEE_UPDATE_SET
=
"UPDATE TEST SET KEY_ID=?, C_NAME=? WHERE C_NAME=?"
;
private
static
final
String
COFFEE_SELECT_CONTINUED
=
"SELECT COUNT(*) FROM TEST WHERE C_NAME='Continue-1'"
;
private
static
final
int
coffeeSize
=
10
;
private
static
final
int
coffeeType
=
11
;
private
static
final
int
COFFEE_SIZE
=
10
;
private
static
final
int
COFFEE_TYPE
=
11
;
private
Connection
conn
;
private
Statement
stat
;
private
PreparedStatement
prep
;
...
...
@@ -173,8 +174,8 @@ public class TestBatchUpdates extends TestBase {
int
newType
=
0
;
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?,?,?,?)"
);
int
newKey
=
1
;
for
(
int
i
=
1
;
i
<=
coffeeType
&&
newKey
<=
coffeeSize
;
i
++)
{
for
(
int
j
=
1
;
j
<=
i
&&
newKey
<=
coffeeSize
;
j
++)
{
for
(
int
i
=
1
;
i
<=
COFFEE_TYPE
&&
newKey
<=
COFFEE_SIZE
;
i
++)
{
for
(
int
j
=
1
;
j
<=
i
&&
newKey
<=
COFFEE_SIZE
;
j
++)
{
newName
=
"COFFEE-"
+
newKey
;
newPrice
=
newKey
+
(
float
)
.
00
;
newType
=
i
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestJavaObjectSerializer.java
浏览文件 @
eb18c317
...
...
@@ -42,14 +42,14 @@ public class TestJavaObjectSerializer extends TestBase {
Utils
.
serializer
=
new
JavaObjectSerializer
()
{
@Override
public
byte
[]
serialize
(
Object
obj
)
throws
Exception
{
assertEquals
(
100500
,
((
Integer
)
obj
).
intValue
());
assertEquals
(
100500
,
((
Integer
)
obj
).
intValue
());
return
new
byte
[]
{
1
,
2
,
3
};
return
new
byte
[]
{
1
,
2
,
3
};
}
@Override
public
Object
deserialize
(
byte
[]
bytes
)
throws
Exception
{
assertEquals
(
new
byte
[]
{
1
,
2
,
3
},
bytes
);
assertEquals
(
new
byte
[]
{
1
,
2
,
3
},
bytes
);
return
100500
;
}
...
...
@@ -72,7 +72,7 @@ public class TestJavaObjectSerializer extends TestBase {
assertTrue
(
rs
.
next
());
assertEquals
(
100500
,
((
Integer
)
rs
.
getObject
(
1
)).
intValue
());
assertEquals
(
new
byte
[]
{
1
,
2
,
3
},
rs
.
getBytes
(
1
));
assertEquals
(
new
byte
[]
{
1
,
2
,
3
},
rs
.
getBytes
(
1
));
deleteDb
(
"javaSerializer"
);
}
finally
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestMetaData.java
浏览文件 @
eb18c317
差异被折叠。
点击展开。
h2/src/test/org/h2/test/store/MVRTreeMap.java
浏览文件 @
eb18c317
...
...
@@ -7,6 +7,9 @@
package
org
.
h2
.
test
.
store
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
org.h2.dev.store.btree.Cursor
;
import
org.h2.dev.store.btree.CursorPos
;
import
org.h2.dev.store.btree.DataType
;
import
org.h2.dev.store.btree.MVMap
;
import
org.h2.dev.store.btree.MVStore
;
...
...
@@ -21,7 +24,7 @@ import org.h2.util.New;
*/
public
class
MVRTreeMap
<
K
,
V
>
extends
MVMap
<
K
,
V
>
{
private
final
SpatialType
keyType
;
final
SpatialType
keyType
;
private
boolean
quadraticSplit
;
MVRTreeMap
(
MVStore
store
,
int
id
,
String
name
,
DataType
keyType
,
...
...
@@ -36,6 +39,39 @@ public class MVRTreeMap<K, V> extends MVMap<K, V> {
return
(
V
)
get
(
root
,
key
);
}
/**
* Iterate over all keys that have an intersection with the given rectangle.
*
* @param x the rectangle
* @return the iterator
*/
public
Iterator
<
K
>
findIntersectingKeys
(
K
x
)
{
checkOpen
();
return
new
RTreeCursor
<
K
>(
this
,
root
,
x
)
{
protected
boolean
check
(
K
key
,
K
test
)
{
System
.
out
.
println
(
"key "
+
key
+
" contains "
+
test
+
" = "
+
keyType
.
contains
(
key
,
test
));
return
keyType
.
contains
(
key
,
test
);
}
};
}
/**
* Iterate over all keys that are fully contained within the given rectangle.
*
* @param x the rectangle
* @return the iterator
*/
public
Iterator
<
K
>
findContainedKeys
(
K
x
)
{
checkOpen
();
return
new
RTreeCursor
<
K
>(
this
,
root
,
x
)
{
protected
boolean
check
(
K
key
,
K
test
)
{
System
.
out
.
println
(
"key "
+
key
+
" isInside "
+
test
+
" = "
+
keyType
.
contains
(
test
,
key
));
return
keyType
.
isInside
(
test
,
key
);
}
};
}
private
boolean
contains
(
Page
p
,
int
index
,
Object
key
)
{
return
keyType
.
contains
(
p
.
getKey
(
index
),
key
);
}
...
...
@@ -411,4 +447,88 @@ public class MVRTreeMap<K, V> extends MVMap<K, V> {
return
p
.
getChildPageCount
()
-
1
;
}
/**
* A cursor to iterate over a subset of the keys.
*
* @param <K> the key class
*/
static
class
RTreeCursor
<
K
>
extends
Cursor
<
K
>
{
protected
RTreeCursor
(
MVRTreeMap
<
K
,
?>
map
,
Page
root
,
K
from
)
{
super
(
map
,
root
,
from
);
}
public
void
skip
(
long
n
)
{
if
(!
hasNext
())
{
return
;
}
while
(
n
--
>
0
)
{
fetchNext
();
}
}
/**
* Check a given key.
*
* @param key the stored key
* @param test the user-supplied test key
* @return true if there is a match
*/
protected
boolean
check
(
K
key
,
K
test
)
{
return
true
;
}
@SuppressWarnings
(
"unchecked"
)
protected
void
min
(
Page
p
,
K
x
)
{
while
(
true
)
{
if
(
p
.
isLeaf
())
{
pos
=
new
CursorPos
(
p
,
0
,
pos
);
return
;
// for (int i = 0; i < p.getKeyCount(); i++) {
// if (check((K) p.getKey(i), x)) {
// pos = new CursorPos(p, i, pos);
// return;
// }
// }
// break;
}
boolean
found
=
false
;
for
(
int
i
=
0
;
i
<
p
.
getKeyCount
();
i
++)
{
if
(
check
((
K
)
p
.
getKey
(
i
),
x
))
{
pos
=
new
CursorPos
(
p
,
i
+
1
,
pos
);
p
=
p
.
getChildPage
(
i
);
found
=
true
;
break
;
}
}
if
(!
found
)
{
break
;
}
}
fetchNext
();
}
@SuppressWarnings
(
"unchecked"
)
protected
void
fetchNext
()
{
while
(
pos
!=
null
)
{
while
(
pos
.
index
<
pos
.
page
.
getKeyCount
())
{
K
k
=
(
K
)
pos
.
page
.
getKey
(
pos
.
index
++);
if
(
check
(
k
,
from
))
{
current
=
k
;
return
;
}
}
pos
=
pos
.
parent
;
if
(
pos
==
null
)
{
break
;
}
MVRTreeMap
<
K
,
?>
m
=
(
MVRTreeMap
<
K
,
?>)
map
;
if
(
pos
.
index
<
m
.
getChildPageCount
(
pos
.
page
))
{
min
(
pos
.
page
.
getChildPage
(
pos
.
index
++),
from
);
}
}
current
=
null
;
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/store/TestConcurrent.java
浏览文件 @
eb18c317
...
...
@@ -7,10 +7,10 @@ package org.h2.test.store;
import
java.io.BufferedInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.nio.channels.Channels
;
import
java.nio.channels.FileChannel
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Random
;
...
...
@@ -44,7 +44,9 @@ public class TestConcurrent extends TestMVStore {
}
private
void
testConcurrentOnlineBackup
()
throws
Exception
{
String
fileName
=
getBaseDir
()
+
"/onlineBackup.h3"
;
// because absolute and relative reads are mixed, this currently
// only works when using FileChannel directly
String
fileName
=
"nio:"
+
getBaseDir
()
+
"/onlineBackup.h3"
;
String
fileNameRestore
=
getBaseDir
()
+
"/onlineRestore.h3"
;
final
MVStore
s
=
openStore
(
fileName
);
final
MVMap
<
Integer
,
byte
[]>
map
=
s
.
openMap
(
"test"
);
...
...
@@ -59,7 +61,7 @@ public class TestConcurrent extends TestMVStore {
s
.
store
();
map
.
clear
();
s
.
store
();
long
len
=
new
File
(
s
.
getFileName
()).
length
();
long
len
=
s
.
getFile
().
size
();
if
(
len
>
1024
*
100
)
{
// slow down writing
Thread
.
sleep
(
10
);
...
...
@@ -70,8 +72,8 @@ public class TestConcurrent extends TestMVStore {
t
.
execute
();
// the wrong way to back up
try
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
byte
[]
buff
=
readFileSlowly
(
fileName
);
for
(
int
i
=
0
;
i
<
10
0
;
i
++)
{
byte
[]
buff
=
readFileSlowly
(
s
.
getFile
()
);
FileOutputStream
out
=
new
FileOutputStream
(
fileNameRestore
);
out
.
write
(
buff
);
MVStore
s2
=
openStore
(
fileNameRestore
);
...
...
@@ -92,7 +94,7 @@ public class TestConcurrent extends TestMVStore {
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
// System.out.println("test " + i);
s
.
setReuseSpace
(
false
);
byte
[]
buff
=
readFileSlowly
(
fileName
);
byte
[]
buff
=
readFileSlowly
(
s
.
getFile
()
);
s
.
setReuseSpace
(
true
);
FileOutputStream
out
=
new
FileOutputStream
(
fileNameRestore
);
out
.
write
(
buff
);
...
...
@@ -109,9 +111,9 @@ public class TestConcurrent extends TestMVStore {
s
.
close
();
}
private
static
byte
[]
readFileSlowly
(
String
fileNam
e
)
throws
Exception
{
InputStream
in
=
new
BufferedInputStream
(
new
FileInputStream
(
fileNam
e
));
private
static
byte
[]
readFileSlowly
(
FileChannel
fil
e
)
throws
Exception
{
file
.
position
(
0
);
InputStream
in
=
new
BufferedInputStream
(
Channels
.
newInputStream
(
fil
e
));
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
for
(
int
j
=
0
;;
j
++)
{
int
x
=
in
.
read
();
...
...
@@ -123,7 +125,8 @@ public class TestConcurrent extends TestMVStore {
Thread
.
sleep
(
1
);
}
}
in
.
close
();
// in.close() could close the stream
// in.close();
return
buff
.
toByteArray
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/store/TestMVRTree.java
浏览文件 @
eb18c317
...
...
@@ -15,6 +15,7 @@ import java.io.IOException;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Random
;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageWriter
;
...
...
@@ -40,7 +41,7 @@ public class TestMVRTree extends TestMVStore {
public
void
test
()
{
testMany
();
test
Tre
e
();
test
Simpl
e
();
testRandom
();
testCustomMapType
();
}
...
...
@@ -108,25 +109,26 @@ public class TestMVRTree extends TestMVStore {
// System.out.println("remove: " + (System.currentTimeMillis() - t));
}
private
void
test
Tre
e
()
{
private
void
test
Simpl
e
()
{
String
fileName
=
getBaseDir
()
+
"/testTree.h3"
;
FileUtils
.
delete
(
fileName
);
MVStore
s
;
s
=
openStore
(
fileName
);
MVRTreeMap
<
SpatialKey
,
String
>
r
=
s
.
openMap
(
"data"
,
"r"
,
"s2"
,
""
);
add
(
r
,
"Bern"
,
46.57
,
7.27
,
124381
);
add
(
r
,
"Basel"
,
47.34
,
7.36
,
170903
);
add
(
r
,
"Zurich"
,
47.22
,
8.33
,
376008
);
add
(
r
,
"Lucerne"
,
47.03
,
8.18
,
77491
);
add
(
r
,
"Geneva"
,
46.12
,
6.09
,
191803
);
add
(
r
,
"Lausanne"
,
46.31
,
6.38
,
127821
);
add
(
r
,
"Winterthur"
,
47.30
,
8.45
,
102966
);
add
(
r
,
"St. Gallen"
,
47.25
,
9.22
,
73500
);
add
(
r
,
"Biel/Bienne"
,
47.08
,
7.15
,
51203
);
add
(
r
,
"Lugano"
,
46.00
,
8.57
,
54667
);
add
(
r
,
"Thun"
,
46.46
,
7.38
,
42623
);
add
(
r
,
"Bellinzona"
,
46.12
,
9.01
,
17373
);
add
(
r
,
"Chur"
,
46.51
,
9.32
,
33756
);
add
(
r
,
"Bern"
,
key
(
0
,
46.57
,
7.27
,
124381
));
add
(
r
,
"Basel"
,
key
(
1
,
47.34
,
7.36
,
170903
));
add
(
r
,
"Zurich"
,
key
(
2
,
47.22
,
8.33
,
376008
));
add
(
r
,
"Lucerne"
,
key
(
3
,
47.03
,
8.18
,
77491
));
add
(
r
,
"Geneva"
,
key
(
4
,
46.12
,
6.09
,
191803
));
add
(
r
,
"Lausanne"
,
key
(
5
,
46.31
,
6.38
,
127821
));
add
(
r
,
"Winterthur"
,
key
(
6
,
47.30
,
8.45
,
102966
));
add
(
r
,
"St. Gallen"
,
key
(
7
,
47.25
,
9.22
,
73500
));
add
(
r
,
"Biel/Bienne"
,
key
(
8
,
47.08
,
7.15
,
51203
));
add
(
r
,
"Lugano"
,
key
(
9
,
46.00
,
8.57
,
54667
));
add
(
r
,
"Thun"
,
key
(
10
,
46.46
,
7.38
,
42623
));
add
(
r
,
"Bellinzona"
,
key
(
11
,
46.12
,
9.01
,
17373
));
add
(
r
,
"Chur"
,
key
(
12
,
46.51
,
9.32
,
33756
));
// render(r, getBaseDir() + "/test.png");
ArrayList
<
String
>
list
=
New
.
arrayList
();
for
(
SpatialKey
x
:
r
.
keySet
())
{
list
.
add
(
r
.
get
(
x
));
...
...
@@ -135,17 +137,46 @@ public class TestMVRTree extends TestMVStore {
assertEquals
(
"[Basel, Bellinzona, Bern, Biel/Bienne, Chur, Geneva, "
+
"Lausanne, Lucerne, Lugano, St. Gallen, Thun, Winterthur, Zurich]"
,
list
.
toString
());
// render(r, getBaseDir() + "/test.png");
SpatialKey
k
;
// intersection
list
.
clear
();
k
=
key
(
0
,
47.34
,
7.36
,
0
);
for
(
Iterator
<
SpatialKey
>
it
=
r
.
findIntersectingKeys
(
k
);
it
.
hasNext
();)
{
list
.
add
(
r
.
get
(
it
.
next
()));
}
Collections
.
sort
(
list
);
assertEquals
(
"[Basel]"
,
list
.
toString
());
// contains
list
.
clear
();
k
=
key
(
0
,
47.34
,
7.36
,
0
);
for
(
Iterator
<
SpatialKey
>
it
=
r
.
findContainedKeys
(
k
);
it
.
hasNext
();)
{
list
.
add
(
r
.
get
(
it
.
next
()));
}
assertEquals
(
0
,
list
.
size
());
k
=
key
(
0
,
47.34
,
7.36
,
170903
);
Collections
.
sort
(
list
);
assertEquals
(
"[Bern]"
,
list
.
toString
());
s
.
close
();
}
private
static
void
add
(
MVRTreeMap
<
SpatialKey
,
String
>
r
,
String
name
,
double
y
,
double
x
,
int
population
)
{
int
id
=
r
.
size
();
private
static
void
add
(
MVRTreeMap
<
SpatialKey
,
String
>
r
,
String
name
,
SpatialKey
k
)
{
r
.
put
(
k
,
name
);
}
private
static
SpatialKey
key
(
int
id
,
double
y
,
double
x
,
int
population
)
{
float
a
=
(
float
)
((
int
)
x
+
(
x
-
(
int
)
x
)
*
5
/
3
);
float
b
=
50
-
(
float
)
((
int
)
y
+
(
y
-
(
int
)
y
)
*
5
/
3
);
float
s
=
(
float
)
Math
.
sqrt
(
population
/
10000000
.);
SpatialKey
k
=
new
SpatialKey
(
id
,
a
-
s
,
a
+
s
,
b
-
s
,
b
+
s
);
r
.
put
(
k
,
name
)
;
r
eturn
k
;
}
private
static
void
render
(
MVRTreeMap
<
SpatialKey
,
String
>
r
,
String
fileName
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/TestKill.java
浏览文件 @
eb18c317
...
...
@@ -25,8 +25,9 @@ public class TestKill extends TestBase {
private
static
final
String
DIR
=
TestBase
.
getTestDir
(
"kill"
);
private
static
final
int
ACCOUNTS
=
10
;
private
Connection
conn
;
private
static
final
int
accounts
=
10
;
private
final
Random
random
=
new
Random
(
1
);
/**
...
...
@@ -51,7 +52,7 @@ public class TestKill extends TestBase {
"java"
,
selfDestruct
,
"-cp"
,
getClassPath
(),
"org.h2.test.synth.TestKillProcess"
,
url
,
user
,
password
,
getBaseDir
(),
""
+
accounts
};
password
,
getBaseDir
(),
""
+
ACCOUNTS
};
for
(
int
i
=
0
;;
i
++)
{
printTime
(
"TestKill "
+
i
);
...
...
@@ -102,13 +103,13 @@ public class TestKill extends TestBase {
conn
.
createStatement
().
execute
(
"DROP TABLE TEST_B"
);
createTables
();
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO ACCOUNT VALUES(?, 0)"
);
for
(
int
i
=
0
;
i
<
accounts
;
i
++)
{
for
(
int
i
=
0
;
i
<
ACCOUNTS
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
execute
();
}
PreparedStatement
p1
=
conn
.
prepareStatement
(
"INSERT INTO TEST_A VALUES(?, '')"
);
PreparedStatement
p2
=
conn
.
prepareStatement
(
"INSERT INTO TEST_B VALUES(?, '')"
);
for
(
int
i
=
0
;
i
<
accounts
;
i
++)
{
for
(
int
i
=
0
;
i
<
ACCOUNTS
;
i
++)
{
p1
.
setInt
(
1
,
i
);
p2
.
setInt
(
1
,
i
);
p1
.
execute
();
...
...
@@ -132,7 +133,7 @@ public class TestKill extends TestBase {
}
PreparedStatement
p1
=
conn
.
prepareStatement
(
"SELECT * FROM TEST_A WHERE ID=?"
);
PreparedStatement
p2
=
conn
.
prepareStatement
(
"SELECT * FROM TEST_B WHERE ID=?"
);
for
(
int
i
=
0
;
i
<
accounts
;
i
++)
{
for
(
int
i
=
0
;
i
<
ACCOUNTS
;
i
++)
{
p1
.
setInt
(
1
,
i
);
p2
.
setInt
(
1
,
i
);
ResultSet
r1
=
p1
.
executeQuery
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/TestPowerOffFs2.java
浏览文件 @
eb18c317
...
...
@@ -24,11 +24,12 @@ import org.h2.util.New;
*/
public
class
TestPowerOffFs2
extends
TestBase
{
private
static
final
String
USER
=
"sa"
;
private
static
final
String
PASSWORD
=
"sa"
;
private
FilePathDebug
fs
;
private
String
url
;
private
static
final
String
user
=
"sa"
;
private
static
final
String
password
=
"sa"
;
private
final
ArrayList
<
Connection
>
connections
=
New
.
arrayList
();
private
final
ArrayList
<
String
>
tables
=
New
.
arrayList
();
...
...
@@ -165,7 +166,7 @@ public class TestPowerOffFs2 extends TestBase {
}
private
Connection
openConnection
()
throws
SQLException
{
Connection
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
Connection
conn
=
DriverManager
.
getConnection
(
url
,
USER
,
PASSWORD
);
connections
.
add
(
conn
);
return
conn
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/thread/TestMultiNews.java
浏览文件 @
eb18c317
...
...
@@ -21,7 +21,7 @@ public class TestMultiNews extends TestMultiThread {
private
static
final
String
PREFIX_URL
=
"http://feeds.wizbangblog.com/WizbangFullFeed?m="
;
private
static
final
int
len
=
10000
;
private
static
final
int
LEN
=
10000
;
private
Connection
conn
;
TestMultiNews
(
TestMulti
base
)
throws
SQLException
{
...
...
@@ -49,7 +49,7 @@ public class TestMultiNews extends TestMultiThread {
}
else
{
prep
=
conn
.
prepareStatement
(
"SELECT * FROM NEWS WHERE VALUE = ?"
);
}
prep
.
setString
(
1
,
PREFIX_URL
+
random
.
nextInt
(
len
));
prep
.
setString
(
1
,
PREFIX_URL
+
random
.
nextInt
(
LEN
));
ResultSet
rs
=
prep
.
executeQuery
();
if
(!
rs
.
next
())
{
throw
new
SQLException
(
"expected one row, got none"
);
...
...
@@ -60,7 +60,7 @@ public class TestMultiNews extends TestMultiThread {
}
else
{
PreparedStatement
prep
=
conn
.
prepareStatement
(
"UPDATE NEWS SET STATE = ? WHERE FID = ?"
);
prep
.
setInt
(
1
,
random
.
nextInt
(
100
));
prep
.
setInt
(
2
,
random
.
nextInt
(
len
));
prep
.
setInt
(
2
,
random
.
nextInt
(
LEN
));
int
count
=
prep
.
executeUpdate
();
if
(
count
!=
1
)
{
throw
new
SQLException
(
"expected one row, got "
+
count
);
...
...
@@ -93,7 +93,7 @@ public class TestMultiNews extends TestMultiThread {
PreparedStatement
prep
=
c
.
prepareStatement
(
"INSERT INTO NEWS (FID, COMMENTS, LINK, STATE, VALUE) VALUES "
+
"(?, ?, ?, ?, ?) "
);
PreparedStatement
prep2
=
c
.
prepareStatement
(
"INSERT INTO TEST (NAME) VALUES (?)"
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
LEN
;
i
++)
{
int
x
=
random
.
nextInt
(
10
)
*
128
;
StringBuilder
buff
=
new
StringBuilder
();
while
(
buff
.
length
()
<
x
)
{
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论