Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f447a3e4
提交
f447a3e4
authored
17 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code style
上级
aed847e4
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
41 个修改的文件
包含
1135 行增加
和
1149 行删除
+1135
-1149
ant-build.properties
h2/ant-build.properties
+2
-2
FileFunctions.java
h2/src/test/org/h2/samples/FileFunctions.java
+1
-1
Function.java
h2/src/test/org/h2/samples/Function.java
+5
-5
FunctionMultiReturn.java
h2/src/test/org/h2/samples/FunctionMultiReturn.java
+10
-10
InitDatabaseFromJar.java
h2/src/test/org/h2/samples/InitDatabaseFromJar.java
+11
-5
MixedMode.java
h2/src/test/org/h2/samples/MixedMode.java
+8
-8
Newsfeed.java
h2/src/test/org/h2/samples/Newsfeed.java
+3
-3
SQLInjection.java
h2/src/test/org/h2/samples/SQLInjection.java
+18
-12
SecurePassword.java
h2/src/test/org/h2/samples/SecurePassword.java
+1
-1
ShowProgress.java
h2/src/test/org/h2/samples/ShowProgress.java
+10
-9
TriggerSample.java
h2/src/test/org/h2/samples/TriggerSample.java
+4
-4
BenchC.java
h2/src/test/org/h2/test/bench/BenchC.java
+67
-73
BenchCThread.java
h2/src/test/org/h2/test/bench/BenchCThread.java
+186
-186
TestAutoRecompile.java
h2/src/test/org/h2/test/db/TestAutoRecompile.java
+4
-4
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+6
-9
TestLobObject.java
h2/src/test/org/h2/test/db/TestLobObject.java
+1
-0
TestSQLInjection.java
h2/src/test/org/h2/test/db/TestSQLInjection.java
+18
-18
TestSpaceReuse.java
h2/src/test/org/h2/test/db/TestSpaceReuse.java
+3
-3
TestSpeed.java
h2/src/test/org/h2/test/db/TestSpeed.java
+334
-334
TestTempTables.java
h2/src/test/org/h2/test/db/TestTempTables.java
+6
-5
TestTransaction.java
h2/src/test/org/h2/test/db/TestTransaction.java
+65
-61
TestTwoPhaseCommit.java
h2/src/test/org/h2/test/db/TestTwoPhaseCommit.java
+11
-11
TestView.java
h2/src/test/org/h2/test/db/TestView.java
+4
-4
TestBitField.java
h2/src/test/org/h2/test/unit/TestBitField.java
+16
-16
TestCache.java
h2/src/test/org/h2/test/unit/TestCache.java
+5
-5
TestCompress.java
h2/src/test/org/h2/test/unit/TestCompress.java
+12
-14
TestDataPage.java
h2/src/test/org/h2/test/unit/TestDataPage.java
+10
-10
TestExit.java
h2/src/test/org/h2/test/unit/TestExit.java
+21
-27
TestFileLock.java
h2/src/test/org/h2/test/unit/TestFileLock.java
+3
-2
TestIntArray.java
h2/src/test/org/h2/test/unit/TestIntArray.java
+33
-33
TestIntIntHashMap.java
h2/src/test/org/h2/test/unit/TestIntIntHashMap.java
+3
-3
TestOverflow.java
h2/src/test/org/h2/test/unit/TestOverflow.java
+22
-22
TestPattern.java
h2/src/test/org/h2/test/unit/TestPattern.java
+18
-18
TestSampleApps.java
h2/src/test/org/h2/test/unit/TestSampleApps.java
+16
-17
TestScriptReader.java
h2/src/test/org/h2/test/unit/TestScriptReader.java
+39
-40
TestSecurity.java
h2/src/test/org/h2/test/unit/TestSecurity.java
+17
-22
TestStreams.java
h2/src/test/org/h2/test/unit/TestStreams.java
+21
-21
TestStringCache.java
h2/src/test/org/h2/test/unit/TestStringCache.java
+22
-22
TestStringUtils.java
h2/src/test/org/h2/test/unit/TestStringUtils.java
+43
-61
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+44
-36
TestValueHashMap.java
h2/src/test/org/h2/test/unit/TestValueHashMap.java
+12
-12
没有找到文件。
h2/ant-build.properties
浏览文件 @
f447a3e4
#Fri Aug 24 22:06:59 CEST 2007
#Sat Sep 01 17:01:19 CEST 2007
javac
=
javac
benchmark.drivers.dir
=
C
\:
/data/java
benchmark.drivers.dir
=
C
\:
/data/java
javac
=
javac
path.servlet.jar
=
C
\:
/data/classpath/servlet-api.jar
path.servlet.jar
=
C
\:
/data/classpath/servlet-api.jar
version.name.maven
=
1.0.57
version.name.maven
=
1.0.57
jdk
=
1.4
jdk
=
1.4
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/samples/FileFunctions.java
浏览文件 @
f447a3e4
...
@@ -46,7 +46,7 @@ public class FileFunctions {
...
@@ -46,7 +46,7 @@ public class FileFunctions {
public
static
byte
[]
readFile
(
String
fileName
)
throws
IOException
{
public
static
byte
[]
readFile
(
String
fileName
)
throws
IOException
{
RandomAccessFile
file
=
new
RandomAccessFile
(
fileName
,
"r"
);
RandomAccessFile
file
=
new
RandomAccessFile
(
fileName
,
"r"
);
try
{
try
{
byte
[]
buff
=
new
byte
[(
int
)
file
.
length
()];
byte
[]
buff
=
new
byte
[(
int
)
file
.
length
()];
file
.
readFully
(
buff
);
file
.
readFully
(
buff
);
return
buff
;
return
buff
;
}
finally
{
}
finally
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/samples/Function.java
浏览文件 @
f447a3e4
...
@@ -23,9 +23,9 @@ public class Function {
...
@@ -23,9 +23,9 @@ public class Function {
stat
.
execute
(
"CREATE ALIAS IS_PRIME FOR \"org.h2.samples.Function.isPrime\" "
);
stat
.
execute
(
"CREATE ALIAS IS_PRIME FOR \"org.h2.samples.Function.isPrime\" "
);
ResultSet
rs
;
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"SELECT IS_PRIME(X), X FROM SYSTEM_RANGE(1, 20) ORDER BY X"
);
rs
=
stat
.
executeQuery
(
"SELECT IS_PRIME(X), X FROM SYSTEM_RANGE(1, 20) ORDER BY X"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
boolean
isPrime
=
rs
.
getBoolean
(
1
);
boolean
isPrime
=
rs
.
getBoolean
(
1
);
if
(
isPrime
)
{
if
(
isPrime
)
{
int
x
=
rs
.
getInt
(
2
);
int
x
=
rs
.
getInt
(
2
);
System
.
out
.
println
(
x
+
" is prime"
);
System
.
out
.
println
(
x
+
" is prime"
);
}
}
...
@@ -53,11 +53,11 @@ public class Function {
...
@@ -53,11 +53,11 @@ public class Function {
SimpleResultSet
rs
=
new
SimpleResultSet
();
SimpleResultSet
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"X"
,
Types
.
INTEGER
,
10
,
0
);
rs
.
addColumn
(
"X"
,
Types
.
INTEGER
,
10
,
0
);
rs
.
addColumn
(
"Y"
,
Types
.
INTEGER
,
10
,
0
);
rs
.
addColumn
(
"Y"
,
Types
.
INTEGER
,
10
,
0
);
if
(
id
==
null
)
{
if
(
id
==
null
)
{
return
rs
;
return
rs
;
}
}
for
(
int
x
=
0
;
x
<
id
.
intValue
();
x
++)
{
for
(
int
x
=
0
;
x
<
id
.
intValue
();
x
++)
{
for
(
int
y
=
0
;
y
<
id
.
intValue
();
y
++)
{
for
(
int
y
=
0
;
y
<
id
.
intValue
();
y
++)
{
rs
.
addRow
(
new
Object
[]
{
new
Integer
(
x
),
new
Integer
(
y
)
});
rs
.
addRow
(
new
Object
[]
{
new
Integer
(
x
),
new
Integer
(
y
)
});
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/samples/FunctionMultiReturn.java
浏览文件 @
f447a3e4
...
@@ -25,7 +25,7 @@ public class FunctionMultiReturn {
...
@@ -25,7 +25,7 @@ public class FunctionMultiReturn {
prep
.
setDouble
(
1
,
5.0
);
prep
.
setDouble
(
1
,
5.0
);
prep
.
setDouble
(
2
,
0.5
);
prep
.
setDouble
(
2
,
0.5
);
ResultSet
rs
=
prep
.
executeQuery
();
ResultSet
rs
=
prep
.
executeQuery
();
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
x
=
rs
.
getDouble
(
1
);
double
x
=
rs
.
getDouble
(
1
);
double
y
=
rs
.
getDouble
(
2
);
double
y
=
rs
.
getDouble
(
2
);
System
.
out
.
println
(
"result: (x="
+
x
+
", y="
+
y
+
")"
);
System
.
out
.
println
(
"result: (x="
+
x
+
", y="
+
y
+
")"
);
...
@@ -35,7 +35,7 @@ public class FunctionMultiReturn {
...
@@ -35,7 +35,7 @@ public class FunctionMultiReturn {
stat
.
execute
(
"INSERT INTO TEST(R, A) VALUES(5.0, 0.5), (10.0, 0.6)"
);
stat
.
execute
(
"INSERT INTO TEST(R, A) VALUES(5.0, 0.5), (10.0, 0.6)"
);
stat
.
execute
(
"CREATE ALIAS P2C_SET FOR \"org.h2.samples.FunctionMultiReturn.polar2CartesianSet\" "
);
stat
.
execute
(
"CREATE ALIAS P2C_SET FOR \"org.h2.samples.FunctionMultiReturn.polar2CartesianSet\" "
);
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM P2C_SET('SELECT * FROM TEST')"
);
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM P2C_SET('SELECT * FROM TEST')"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
"R"
);
double
r
=
rs
.
getDouble
(
"R"
);
double
a
=
rs
.
getDouble
(
"A"
);
double
a
=
rs
.
getDouble
(
"A"
);
double
x
=
rs
.
getDouble
(
"X"
);
double
x
=
rs
.
getDouble
(
"X"
);
...
@@ -45,18 +45,18 @@ public class FunctionMultiReturn {
...
@@ -45,18 +45,18 @@ public class FunctionMultiReturn {
stat
.
execute
(
"CREATE ALIAS P2C_A FOR \"org.h2.samples.FunctionMultiReturn.polar2CartesianArray\" "
);
stat
.
execute
(
"CREATE ALIAS P2C_A FOR \"org.h2.samples.FunctionMultiReturn.polar2CartesianArray\" "
);
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT R, A, P2C_A(R, A) FROM TEST"
);
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT R, A, P2C_A(R, A) FROM TEST"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
1
);
double
r
=
rs
.
getDouble
(
1
);
double
a
=
rs
.
getDouble
(
2
);
double
a
=
rs
.
getDouble
(
2
);
Object
o
=
rs
.
getObject
(
3
);
Object
o
=
rs
.
getObject
(
3
);
Object
[]
xy
=
(
Object
[])
o
;
Object
[]
xy
=
(
Object
[])
o
;
double
x
=
((
Double
)
xy
[
0
]).
doubleValue
();
double
x
=
((
Double
)
xy
[
0
]).
doubleValue
();
double
y
=
((
Double
)
xy
[
1
]).
doubleValue
();
double
y
=
((
Double
)
xy
[
1
]).
doubleValue
();
System
.
out
.
println
(
"(r="
+
r
+
" a="
+
a
+
") : (x="
+
x
+
", y="
+
y
+
")"
);
System
.
out
.
println
(
"(r="
+
r
+
" a="
+
a
+
") : (x="
+
x
+
", y="
+
y
+
")"
);
}
}
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT R, A, ARRAY_GET(E, 1), ARRAY_GET(E, 2) FROM (SELECT R, A, P2C_A(R, A) E FROM TEST)"
);
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT R, A, ARRAY_GET(E, 1), ARRAY_GET(E, 2) FROM (SELECT R, A, P2C_A(R, A) E FROM TEST)"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
1
);
double
r
=
rs
.
getDouble
(
1
);
double
a
=
rs
.
getDouble
(
2
);
double
a
=
rs
.
getDouble
(
2
);
double
x
=
rs
.
getDouble
(
3
);
double
x
=
rs
.
getDouble
(
3
);
...
@@ -75,7 +75,7 @@ public class FunctionMultiReturn {
...
@@ -75,7 +75,7 @@ public class FunctionMultiReturn {
SimpleResultSet
rs
=
new
SimpleResultSet
();
SimpleResultSet
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"X"
,
Types
.
DOUBLE
,
0
,
0
);
rs
.
addColumn
(
"X"
,
Types
.
DOUBLE
,
0
,
0
);
rs
.
addColumn
(
"Y"
,
Types
.
DOUBLE
,
0
,
0
);
rs
.
addColumn
(
"Y"
,
Types
.
DOUBLE
,
0
,
0
);
if
(
r
!=
null
&&
alpha
!=
null
)
{
if
(
r
!=
null
&&
alpha
!=
null
)
{
double
x
=
r
.
doubleValue
()
*
Math
.
cos
(
alpha
.
doubleValue
());
double
x
=
r
.
doubleValue
()
*
Math
.
cos
(
alpha
.
doubleValue
());
double
y
=
r
.
doubleValue
()
*
Math
.
sin
(
alpha
.
doubleValue
());
double
y
=
r
.
doubleValue
()
*
Math
.
sin
(
alpha
.
doubleValue
());
rs
.
addRow
(
new
Object
[]
{
new
Double
(
x
),
new
Double
(
y
)
});
rs
.
addRow
(
new
Object
[]
{
new
Double
(
x
),
new
Double
(
y
)
});
...
@@ -99,9 +99,9 @@ public class FunctionMultiReturn {
...
@@ -99,9 +99,9 @@ public class FunctionMultiReturn {
result
.
addColumn
(
"A"
,
Types
.
DOUBLE
,
0
,
0
);
result
.
addColumn
(
"A"
,
Types
.
DOUBLE
,
0
,
0
);
result
.
addColumn
(
"X"
,
Types
.
DOUBLE
,
0
,
0
);
result
.
addColumn
(
"X"
,
Types
.
DOUBLE
,
0
,
0
);
result
.
addColumn
(
"Y"
,
Types
.
DOUBLE
,
0
,
0
);
result
.
addColumn
(
"Y"
,
Types
.
DOUBLE
,
0
,
0
);
if
(
query
!=
null
)
{
if
(
query
!=
null
)
{
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
query
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
query
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
"R"
);
double
r
=
rs
.
getDouble
(
"R"
);
double
alpha
=
rs
.
getDouble
(
"A"
);
double
alpha
=
rs
.
getDouble
(
"A"
);
double
x
=
r
*
Math
.
cos
(
alpha
);
double
x
=
r
*
Math
.
cos
(
alpha
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/samples/InitDatabaseFromJar.java
浏览文件 @
f447a3e4
...
@@ -4,8 +4,13 @@
...
@@ -4,8 +4,13 @@
*/
*/
package
org
.
h2
.
samples
;
package
org
.
h2
.
samples
;
import
java.io.*
;
import
java.io.InputStream
;
import
java.sql.*
;
import
java.io.InputStreamReader
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
org.h2.tools.RunScript
;
import
org.h2.tools.RunScript
;
public
class
InitDatabaseFromJar
{
public
class
InitDatabaseFromJar
{
...
@@ -29,12 +34,13 @@ public class InitDatabaseFromJar {
...
@@ -29,12 +34,13 @@ public class InitDatabaseFromJar {
Class
.
forName
(
"org.h2.Driver"
);
Class
.
forName
(
"org.h2.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:test"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:test"
);
InputStream
in
=
getClass
().
getResourceAsStream
(
"script.sql"
);
InputStream
in
=
getClass
().
getResourceAsStream
(
"script.sql"
);
if
(
in
==
null
)
{
if
(
in
==
null
)
{
System
.
out
.
println
(
"Please add the file script.sql to the classpath, package "
+
getClass
().
getPackage
().
getName
());
System
.
out
.
println
(
"Please add the file script.sql to the classpath, package "
+
getClass
().
getPackage
().
getName
());
}
else
{
}
else
{
RunScript
.
execute
(
conn
,
new
InputStreamReader
(
in
));
RunScript
.
execute
(
conn
,
new
InputStreamReader
(
in
));
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
));
System
.
out
.
println
(
rs
.
getString
(
1
));
}
}
conn
.
close
();
conn
.
close
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/samples/MixedMode.java
浏览文件 @
f447a3e4
...
@@ -30,14 +30,14 @@ public class MixedMode {
...
@@ -30,14 +30,14 @@ public class MixedMode {
System
.
out
.
println
(
"Execute this a few times: SELECT TIME FROM TIMER"
);
System
.
out
.
println
(
"Execute this a few times: SELECT TIME FROM TIMER"
);
System
.
out
.
println
(
"To stop this application (and the server), run: DROP TABLE TIMER"
);
System
.
out
.
println
(
"To stop this application (and the server), run: DROP TABLE TIMER"
);
try
{
try
{
while
(
true
)
{
while
(
true
)
{
// runs forever, except if you drop the table remotely
// runs forever, except if you drop the table remotely
stat
.
execute
(
"MERGE INTO TIMER VALUES(1, NOW())"
);
stat
.
execute
(
"MERGE INTO TIMER VALUES(1, NOW())"
);
Thread
.
sleep
(
1000
);
Thread
.
sleep
(
1000
);
}
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
"Error: "
+
e
.
toString
());
System
.
out
.
println
(
"Error: "
+
e
.
toString
());
}
}
conn
.
close
();
conn
.
close
();
// stop the server
// stop the server
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/samples/Newsfeed.java
浏览文件 @
f447a3e4
...
@@ -22,10 +22,10 @@ public class Newsfeed {
...
@@ -22,10 +22,10 @@ public class Newsfeed {
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:"
,
"sa"
,
""
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:"
,
"sa"
,
""
);
InputStream
in
=
Newsfeed
.
class
.
getResourceAsStream
(
"newsfeed.sql"
);
InputStream
in
=
Newsfeed
.
class
.
getResourceAsStream
(
"newsfeed.sql"
);
ResultSet
rs
=
RunScript
.
execute
(
conn
,
new
InputStreamReader
(
in
,
"ISO-8859-1"
));
ResultSet
rs
=
RunScript
.
execute
(
conn
,
new
InputStreamReader
(
in
,
"ISO-8859-1"
));
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
String
file
=
rs
.
getString
(
"FILE"
);
String
file
=
rs
.
getString
(
"FILE"
);
String
content
=
rs
.
getString
(
"CONTENT"
);
String
content
=
rs
.
getString
(
"CONTENT"
);
if
(
file
.
equals
(
"-newsletter-"
))
{
if
(
file
.
equals
(
"-newsletter-"
))
{
System
.
out
.
println
(
convertHtml2Text
(
content
));
System
.
out
.
println
(
convertHtml2Text
(
content
));
}
else
{
}
else
{
FileOutputStream
out
=
new
FileOutputStream
(
file
);
FileOutputStream
out
=
new
FileOutputStream
(
file
);
...
@@ -52,7 +52,7 @@ public class Newsfeed {
...
@@ -52,7 +52,7 @@ public class Newsfeed {
s
=
StringUtils
.
replaceAll
(
s
,
"<br />"
,
""
);
s
=
StringUtils
.
replaceAll
(
s
,
"<br />"
,
""
);
s
=
StringUtils
.
replaceAll
(
s
,
"<br/>"
,
""
);
s
=
StringUtils
.
replaceAll
(
s
,
"<br/>"
,
""
);
s
=
StringUtils
.
replaceAll
(
s
,
"<br>"
,
""
);
s
=
StringUtils
.
replaceAll
(
s
,
"<br>"
,
""
);
if
(
s
.
indexOf
(
'<'
)
>=
0
||
s
.
indexOf
(
'>'
)
>=
0
)
{
if
(
s
.
indexOf
(
'<'
)
>=
0
||
s
.
indexOf
(
'>'
)
>=
0
)
{
throw
new
Error
(
"Unsupported HTML Tag: < or > in "
+
s
);
throw
new
Error
(
"Unsupported HTML Tag: < or > in "
+
s
);
}
}
return
s
;
return
s
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/samples/SQLInjection.java
浏览文件 @
f447a3e4
...
@@ -4,8 +4,14 @@
...
@@ -4,8 +4,14 @@
*/
*/
package
org
.
h2
.
samples
;
package
org
.
h2
.
samples
;
import
java.io.*
;
import
java.io.BufferedReader
;
import
java.sql.*
;
import
java.io.InputStreamReader
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
SQLInjection
{
public
class
SQLInjection
{
...
@@ -43,14 +49,14 @@ public class SQLInjection {
...
@@ -43,14 +49,14 @@ public class SQLInjection {
// loginByNameInsecure();
// loginByNameInsecure();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
//
loginStoredProcedureInsecure();
// loginStoredProcedureInsecure();
limitRowAccess
();
limitRowAccess
();
}
}
// loginByNameSecure();
// loginByNameSecure();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
stat
.
execute
(
"SET ALLOW_LITERALS NONE"
);
stat
.
execute
(
"SET ALLOW_LITERALS NONE"
);
stat
.
execute
(
"SET ALLOW_LITERALS NUMBERS"
);
stat
.
execute
(
"SET ALLOW_LITERALS NUMBERS"
);
stat
.
execute
(
"SET ALLOW_LITERALS ALL"
);
stat
.
execute
(
"SET ALLOW_LITERALS ALL"
);
...
@@ -75,7 +81,7 @@ public class SQLInjection {
...
@@ -75,7 +81,7 @@ public class SQLInjection {
listActiveItems
();
listActiveItems
();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
stat
.
execute
(
"DROP CONSTANT IF EXISTS TYPE_INACTIVE"
);
stat
.
execute
(
"DROP CONSTANT IF EXISTS TYPE_INACTIVE"
);
stat
.
execute
(
"DROP CONSTANT IF EXISTS TYPE_ACTIVE"
);
stat
.
execute
(
"DROP CONSTANT IF EXISTS TYPE_ACTIVE"
);
stat
.
execute
(
"CREATE CONSTANT TYPE_INACTIVE VALUE 0"
);
stat
.
execute
(
"CREATE CONSTANT TYPE_INACTIVE VALUE 0"
);
...
@@ -86,7 +92,7 @@ public class SQLInjection {
...
@@ -86,7 +92,7 @@ public class SQLInjection {
// listItemsSortedInsecure();
// listItemsSortedInsecure();
// listItemsSortedSecure();
// listItemsSortedSecure();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
listItemsSortedSecureParam
();
listItemsSortedSecureParam
();
// storePasswordHashWithSalt();
// storePasswordHashWithSalt();
}
}
...
@@ -188,7 +194,7 @@ public class SQLInjection {
...
@@ -188,7 +194,7 @@ public class SQLInjection {
}
else
{
}
else
{
System
.
out
.
println
(
"Access denied!"
);
System
.
out
.
println
(
"Access denied!"
);
}
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
);
System
.
out
.
println
(
e
);
}
}
}
}
...
@@ -209,7 +215,7 @@ public class SQLInjection {
...
@@ -209,7 +215,7 @@ public class SQLInjection {
}
else
{
}
else
{
System
.
out
.
println
(
"Access denied!"
);
System
.
out
.
println
(
"Access denied!"
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
System
.
out
.
println
(
e
);
}
}
}
}
...
@@ -241,7 +247,7 @@ public class SQLInjection {
...
@@ -241,7 +247,7 @@ public class SQLInjection {
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
}
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
);
System
.
out
.
println
(
e
);
}
}
}
}
...
@@ -258,7 +264,7 @@ public class SQLInjection {
...
@@ -258,7 +264,7 @@ public class SQLInjection {
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
}
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
);
System
.
out
.
println
(
e
);
}
}
}
}
...
@@ -274,7 +280,7 @@ public class SQLInjection {
...
@@ -274,7 +280,7 @@ public class SQLInjection {
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
System
.
out
.
println
(
e
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/samples/SecurePassword.java
浏览文件 @
f447a3e4
...
@@ -39,7 +39,7 @@ public class SecurePassword {
...
@@ -39,7 +39,7 @@ public class SecurePassword {
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
executeUpdate
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
stat
.
executeUpdate
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
"NAME"
));
System
.
out
.
println
(
rs
.
getString
(
"NAME"
));
}
}
conn
.
close
();
conn
.
close
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/samples/ShowProgress.java
浏览文件 @
f447a3e4
...
@@ -35,21 +35,21 @@ public class ShowProgress implements DatabaseEventListener {
...
@@ -35,21 +35,21 @@ public class ShowProgress implements DatabaseEventListener {
long
time
;
long
time
;
time
=
System
.
currentTimeMillis
();
time
=
System
.
currentTimeMillis
();
int
len
=
1000
;
int
len
=
1000
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
long
last
=
System
.
currentTimeMillis
();
long
last
=
System
.
currentTimeMillis
();
if
(
last
>
time
+
1000
)
{
if
(
last
>
time
+
1000
)
{
time
=
last
;
time
=
last
;
System
.
out
.
println
(
"Inserting "
+
(
100L
*
i
/
len
)
+
"%"
);
System
.
out
.
println
(
"Inserting "
+
(
100L
*
i
/
len
)
+
"%"
);
}
}
prep
.
setInt
(
1
,
i
);
prep
.
setInt
(
1
,
i
);
prep
.
execute
();
prep
.
execute
();
}
}
boolean
abnormalTermination
=
true
;
boolean
abnormalTermination
=
true
;
if
(
abnormalTermination
)
{
if
(
abnormalTermination
)
{
((
JdbcConnection
)
conn
).
setPowerOffCount
(
1
);
((
JdbcConnection
)
conn
).
setPowerOffCount
(
1
);
try
{
try
{
stat
.
execute
(
"INSERT INTO TEST VALUES(-1, 'Test' || SPACE(100))"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(-1, 'Test' || SPACE(100))"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
}
}
}
else
{
}
else
{
conn
.
close
();
conn
.
close
();
...
@@ -75,12 +75,12 @@ public class ShowProgress implements DatabaseEventListener {
...
@@ -75,12 +75,12 @@ public class ShowProgress implements DatabaseEventListener {
public
void
setProgress
(
int
state
,
String
name
,
int
current
,
int
max
)
{
public
void
setProgress
(
int
state
,
String
name
,
int
current
,
int
max
)
{
long
time
=
System
.
currentTimeMillis
();
long
time
=
System
.
currentTimeMillis
();
if
(
time
<
last
+
5000
)
{
if
(
time
<
last
+
5000
)
{
return
;
return
;
}
}
last
=
time
;
last
=
time
;
String
stateName
=
"?"
;
String
stateName
=
"?"
;
switch
(
state
)
{
switch
(
state
)
{
case
STATE_SCAN_FILE:
case
STATE_SCAN_FILE:
stateName
=
"Scan "
+
name
;
stateName
=
"Scan "
+
name
;
break
;
break
;
...
@@ -95,7 +95,8 @@ public class ShowProgress implements DatabaseEventListener {
...
@@ -95,7 +95,8 @@ public class ShowProgress implements DatabaseEventListener {
Thread
.
sleep
(
1
);
Thread
.
sleep
(
1
);
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
}
}
System
.
out
.
println
(
"State: "
+
stateName
+
" "
+
(
100
*
current
/
max
)
+
"% ("
+
current
+
" of "
+
max
+
") "
+
(
time
-
start
)+
" ms"
);
System
.
out
.
println
(
"State: "
+
stateName
+
" "
+
(
100
*
current
/
max
)
+
"% ("
+
current
+
" of "
+
max
+
") "
+
(
time
-
start
)
+
" ms"
);
}
}
public
void
closingDatabase
()
{
public
void
closingDatabase
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/samples/TriggerSample.java
浏览文件 @
f447a3e4
...
@@ -49,11 +49,11 @@ public class TriggerSample {
...
@@ -49,11 +49,11 @@ public class TriggerSample {
Object
[]
oldRow
,
Object
[]
newRow
)
Object
[]
oldRow
,
Object
[]
newRow
)
throws
SQLException
{
throws
SQLException
{
BigDecimal
diff
=
null
;
BigDecimal
diff
=
null
;
if
(
newRow
!=
null
)
{
if
(
newRow
!=
null
)
{
diff
=
(
BigDecimal
)
newRow
[
1
];
diff
=
(
BigDecimal
)
newRow
[
1
];
}
}
if
(
oldRow
!=
null
)
{
if
(
oldRow
!=
null
)
{
BigDecimal
m
=
(
BigDecimal
)
oldRow
[
1
];
BigDecimal
m
=
(
BigDecimal
)
oldRow
[
1
];
diff
=
diff
==
null
?
m
.
negate
()
:
diff
.
subtract
(
m
);
diff
=
diff
==
null
?
m
.
negate
()
:
diff
.
subtract
(
m
);
}
}
PreparedStatement
prep
=
conn
.
prepareStatement
(
PreparedStatement
prep
=
conn
.
prepareStatement
(
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/bench/BenchC.java
浏览文件 @
f447a3e4
差异被折叠。
点击展开。
h2/src/test/org/h2/test/bench/BenchCThread.java
浏览文件 @
f447a3e4
差异被折叠。
点击展开。
h2/src/test/org/h2/test/db/TestAutoRecompile.java
浏览文件 @
f447a3e4
...
@@ -15,7 +15,7 @@ public class TestAutoRecompile extends TestBase {
...
@@ -15,7 +15,7 @@ public class TestAutoRecompile extends TestBase {
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
deleteDb
(
"autoRecompile"
);
deleteDb
(
"autoRecompile"
);
Connection
conn
=
getConnection
(
"autoRecompile"
);
Connection
conn
=
getConnection
(
"autoRecompile"
);
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)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM TEST"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM TEST"
);
...
@@ -26,19 +26,19 @@ public class TestAutoRecompile extends TestBase {
...
@@ -26,19 +26,19 @@ public class TestAutoRecompile extends TestBase {
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, X INT, Y INT)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, X INT, Y INT)"
);
check
(
prep
.
executeQuery
().
getMetaData
().
getColumnCount
(),
3
);
check
(
prep
.
executeQuery
().
getMetaData
().
getColumnCount
(),
3
);
// TODO test auto-recompile with insert..select, views and so on
// TODO test auto-recompile with insert..select, views and so on
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(1, 2, 3)"
);
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(1, 2, 3)"
);
stat
.
execute
(
"ALTER TABLE TEST ADD COLUMN Z INT"
);
stat
.
execute
(
"ALTER TABLE TEST ADD COLUMN Z INT"
);
try
{
try
{
prep
.
execute
();
prep
.
execute
();
error
(
"must fail"
);
error
(
"must fail"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
checkNotGeneralException
(
e
);
}
}
try
{
try
{
prep
.
execute
();
prep
.
execute
();
error
(
"must fail"
);
error
(
"must fail"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
checkNotGeneralException
(
e
);
}
}
conn
.
close
();
conn
.
close
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
f447a3e4
...
@@ -13,18 +13,18 @@ import org.h2.test.TestBase;
...
@@ -13,18 +13,18 @@ import org.h2.test.TestBase;
public
class
TestCompatibility
extends
TestBase
{
public
class
TestCompatibility
extends
TestBase
{
private
Connection
conn
;
private
Connection
conn
;
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
deleteDb
(
"compatibility"
);
deleteDb
(
"compatibility"
);
conn
=
getConnection
(
"compatibility"
);
conn
=
getConnection
(
"compatibility"
);
testHsqlDb
();
testHsqlDb
();
testMySQL
();
testMySQL
();
conn
.
close
();
conn
.
close
();
}
}
private
void
testHsqlDb
()
throws
Exception
{
private
void
testHsqlDb
()
throws
Exception
{
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"DROP TABLE TEST IF EXISTS; CREATE TABLE TEST(ID INT PRIMARY KEY); "
);
stat
.
execute
(
"DROP TABLE TEST IF EXISTS; CREATE TABLE TEST(ID INT PRIMARY KEY); "
);
...
@@ -37,15 +37,13 @@ public class TestCompatibility extends TestBase {
...
@@ -37,15 +37,13 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT LIMIT ? 1 ID FROM TEST"
);
"SELECT LIMIT ? 1 ID FROM TEST"
);
prep
.
setInt
(
1
,
2
);
prep
.
setInt
(
1
,
2
);
prep
.
executeQuery
();
prep
.
executeQuery
();
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
}
}
private
void
testMySQL
()
throws
Exception
{
private
void
testMySQL
()
throws
Exception
{
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT 1"
);
stat
.
execute
(
"SELECT 1"
);
...
@@ -53,6 +51,5 @@ public class TestCompatibility extends TestBase {
...
@@ -53,6 +51,5 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"CREATE TABLE TEST(ID INT, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT, NAME VARCHAR)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World')"
);
}
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestLobObject.java
浏览文件 @
f447a3e4
...
@@ -9,6 +9,7 @@ import java.io.Serializable;
...
@@ -9,6 +9,7 @@ import java.io.Serializable;
class
TestLobObject
implements
Serializable
{
class
TestLobObject
implements
Serializable
{
private
static
final
long
serialVersionUID
=
904356179316518715L
;
private
static
final
long
serialVersionUID
=
904356179316518715L
;
String
data
;
String
data
;
TestLobObject
(
String
data
)
{
TestLobObject
(
String
data
)
{
this
.
data
=
data
;
this
.
data
=
data
;
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestSQLInjection.java
浏览文件 @
f447a3e4
...
@@ -13,13 +13,13 @@ import java.sql.Statement;
...
@@ -13,13 +13,13 @@ import java.sql.Statement;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
public
class
TestSQLInjection
extends
TestBase
{
public
class
TestSQLInjection
extends
TestBase
{
Connection
conn
;
Connection
conn
;
Statement
stat
;
Statement
stat
;
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
deleteDb
(
"sqlInjection"
);
deleteDb
(
"sqlInjection"
);
reconnect
(
"sqlInjection"
);
reconnect
(
"sqlInjection"
);
stat
.
execute
(
"DROP TABLE IF EXISTS USERS"
);
stat
.
execute
(
"DROP TABLE IF EXISTS USERS"
);
stat
.
execute
(
"CREATE TABLE USERS(NAME VARCHAR PRIMARY KEY, PASSWORD VARCHAR, TYPE VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE USERS(NAME VARCHAR PRIMARY KEY, PASSWORD VARCHAR, TYPE VARCHAR)"
);
stat
.
execute
(
"CREATE SCHEMA CONST"
);
stat
.
execute
(
"CREATE SCHEMA CONST"
);
...
@@ -32,56 +32,56 @@ public class TestSQLInjection extends TestBase {
...
@@ -32,56 +32,56 @@ public class TestSQLInjection extends TestBase {
checkFalse
(
checkPasswordSecure
(
"abcdef"
));
checkFalse
(
checkPasswordSecure
(
"abcdef"
));
checkFalse
(
checkPasswordSecure
(
"' OR ''='"
));
checkFalse
(
checkPasswordSecure
(
"' OR ''='"
));
stat
.
execute
(
"SET ALLOW_LITERALS NONE"
);
stat
.
execute
(
"SET ALLOW_LITERALS NONE"
);
try
{
try
{
check
(
checkPasswordInsecure
(
"123456"
));
check
(
checkPasswordInsecure
(
"123456"
));
error
(
"Should fail now"
);
error
(
"Should fail now"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
checkNotGeneralException
(
e
);
}
}
check
(
checkPasswordSecure
(
"123456"
));
check
(
checkPasswordSecure
(
"123456"
));
checkFalse
(
checkPasswordSecure
(
"' OR ''='"
));
checkFalse
(
checkPasswordSecure
(
"' OR ''='"
));
conn
.
close
();
conn
.
close
();
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
return
;
}
}
reconnect
(
"sqlInjection"
);
reconnect
(
"sqlInjection"
);
try
{
try
{
check
(
checkPasswordInsecure
(
"123456"
));
check
(
checkPasswordInsecure
(
"123456"
));
error
(
"Should fail now"
);
error
(
"Should fail now"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
checkNotGeneralException
(
e
);
}
}
check
(
checkPasswordSecure
(
"123456"
));
check
(
checkPasswordSecure
(
"123456"
));
checkFalse
(
checkPasswordSecure
(
"' OR ''='"
));
checkFalse
(
checkPasswordSecure
(
"' OR ''='"
));
conn
.
close
();
conn
.
close
();
}
}
boolean
checkPasswordInsecure
(
String
pwd
)
throws
SQLException
{
boolean
checkPasswordInsecure
(
String
pwd
)
throws
SQLException
{
String
sql
=
"SELECT * FROM USERS WHERE PASSWORD='"
+
pwd
+
"'"
;
String
sql
=
"SELECT * FROM USERS WHERE PASSWORD='"
+
pwd
+
"'"
;
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
sql
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
sql
);
return
(
rs
.
next
());
return
(
rs
.
next
());
}
}
boolean
checkPasswordSecure
(
String
pwd
)
throws
Exception
{
boolean
checkPasswordSecure
(
String
pwd
)
throws
Exception
{
String
sql
=
"SELECT * FROM USERS WHERE PASSWORD=?"
;
String
sql
=
"SELECT * FROM USERS WHERE PASSWORD=?"
;
PreparedStatement
prep
=
conn
.
prepareStatement
(
sql
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
sql
);
prep
.
setString
(
1
,
pwd
);
prep
.
setString
(
1
,
pwd
);
ResultSet
rs
=
prep
.
executeQuery
();
ResultSet
rs
=
prep
.
executeQuery
();
return
(
rs
.
next
());
return
(
rs
.
next
());
}
}
private
void
reconnect
(
String
name
)
throws
Exception
{
private
void
reconnect
(
String
name
)
throws
Exception
{
if
(!
config
.
memory
)
{
if
(!
config
.
memory
)
{
if
(
conn
!=
null
)
{
if
(
conn
!=
null
)
{
conn
.
close
();
conn
.
close
();
conn
=
null
;
conn
=
null
;
}
}
}
}
if
(
conn
==
null
)
{
if
(
conn
==
null
)
{
conn
=
getConnection
(
name
);
conn
=
getConnection
(
name
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestSpaceReuse.java
浏览文件 @
f447a3e4
...
@@ -12,7 +12,7 @@ import org.h2.test.TestBase;
...
@@ -12,7 +12,7 @@ import org.h2.test.TestBase;
public
class
TestSpaceReuse
extends
TestBase
{
public
class
TestSpaceReuse
extends
TestBase
{
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
return
;
}
}
deleteDb
(
"spaceReuse"
);
deleteDb
(
"spaceReuse"
);
...
@@ -27,11 +27,11 @@ public class TestSpaceReuse extends TestBase {
...
@@ -27,11 +27,11 @@ public class TestSpaceReuse extends TestBase {
conn
.
createStatement
().
execute
(
"delete from t"
);
conn
.
createStatement
().
execute
(
"delete from t"
);
conn
.
close
();
conn
.
close
();
now
=
new
File
(
baseDir
+
"/spaceReuse.data.db"
).
length
();
now
=
new
File
(
baseDir
+
"/spaceReuse.data.db"
).
length
();
if
(
first
==
0
)
{
if
(
first
==
0
)
{
first
=
now
;
first
=
now
;
}
}
}
}
if
(
now
>
first
)
{
if
(
now
>
first
)
{
this
.
error
(
"first: "
+
first
+
" now: "
+
now
);
this
.
error
(
"first: "
+
first
+
" now: "
+
now
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestSpeed.java
浏览文件 @
f447a3e4
差异被折叠。
点击展开。
h2/src/test/org/h2/test/db/TestTempTables.java
浏览文件 @
f447a3e4
...
@@ -34,8 +34,9 @@ public class TestTempTables extends TestBase {
...
@@ -34,8 +34,9 @@ public class TestTempTables extends TestBase {
s2
.
execute
(
"DROP TABLE LT"
);
s2
.
execute
(
"DROP TABLE LT"
);
s1
.
execute
(
"DROP TABLE LT"
);
s1
.
execute
(
"DROP TABLE LT"
);
// temp tables: 'on commit' syntax is currently not documented, because not tested well
// temp tables: 'on commit' syntax is currently not documented, because
// and hopefully nobody is using it, as it looks like functional sugar
// not tested well
// and hopefully nobody is using it, as it looks like functional sugar
// (this features are here for compatibility only)
// (this features are here for compatibility only)
ResultSet
rs
;
ResultSet
rs
;
c1
.
setAutoCommit
(
false
);
c1
.
setAutoCommit
(
false
);
...
@@ -47,7 +48,7 @@ public class TestTempTables extends TestBase {
...
@@ -47,7 +48,7 @@ public class TestTempTables extends TestBase {
rs
=
s1
.
executeQuery
(
"select * from test_temp"
);
rs
=
s1
.
executeQuery
(
"select * from test_temp"
);
checkResultRowCount
(
rs
,
0
);
checkResultRowCount
(
rs
,
0
);
s1
.
execute
(
"drop table test_temp"
);
s1
.
execute
(
"drop table test_temp"
);
s1
.
execute
(
"create local temporary table test_temp(id int) on commit drop"
);
s1
.
execute
(
"create local temporary table test_temp(id int) on commit drop"
);
s1
.
execute
(
"insert into test_temp values(1)"
);
s1
.
execute
(
"insert into test_temp values(1)"
);
rs
=
s1
.
executeQuery
(
"select * from test_temp"
);
rs
=
s1
.
executeQuery
(
"select * from test_temp"
);
...
@@ -56,10 +57,10 @@ public class TestTempTables extends TestBase {
...
@@ -56,10 +57,10 @@ public class TestTempTables extends TestBase {
try
{
try
{
rs
=
s1
.
executeQuery
(
"select * from test_temp"
);
rs
=
s1
.
executeQuery
(
"select * from test_temp"
);
error
(
"test_temp should have been dropped automatically"
);
error
(
"test_temp should have been dropped automatically"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
checkNotGeneralException
(
e
);
}
}
c1
.
close
();
c1
.
close
();
c2
.
close
();
c2
.
close
();
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestTransaction.java
浏览文件 @
f447a3e4
...
@@ -16,12 +16,12 @@ import java.util.Vector;
...
@@ -16,12 +16,12 @@ import java.util.Vector;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
public
class
TestTransaction
extends
TestBase
{
public
class
TestTransaction
extends
TestBase
{
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testSavepoint
();
testSavepoint
();
testIsolation
();
testIsolation
();
}
}
public
void
testSavepoint
()
throws
Exception
{
public
void
testSavepoint
()
throws
Exception
{
deleteDb
(
"transaction"
);
deleteDb
(
"transaction"
);
Connection
conn
=
getConnection
(
"transaction"
);
Connection
conn
=
getConnection
(
"transaction"
);
...
@@ -35,40 +35,44 @@ public class TestTransaction extends TestBase {
...
@@ -35,40 +35,44 @@ public class TestTransaction extends TestBase {
int
len
=
getSize
(
2000
,
10000
);
int
len
=
getSize
(
2000
,
10000
);
Random
random
=
new
Random
(
10
);
Random
random
=
new
Random
(
10
);
Savepoint
sp
=
null
;
Savepoint
sp
=
null
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
tableId
=
random
.
nextInt
(
2
);
int
tableId
=
random
.
nextInt
(
2
);
String
table
=
"TEST"
+
tableId
;
String
table
=
"TEST"
+
tableId
;
int
op
=
random
.
nextInt
(
6
);
int
op
=
random
.
nextInt
(
6
);
switch
(
op
)
{
switch
(
op
)
{
case
0
:
case
0
:
stat
.
execute
(
"INSERT INTO "
+
table
+
"(NAME) VALUES('op"
+
i
+
"')"
);
stat
.
execute
(
"INSERT INTO "
+
table
+
"(NAME) VALUES('op"
+
i
+
"')"
);
count
[
tableId
]++;
count
[
tableId
]++;
break
;
break
;
case
1
:
case
1
:
if
(
count
[
tableId
]
>
0
)
{
if
(
count
[
tableId
]
>
0
)
{
stat
.
execute
(
"DELETE FROM "
+
table
+
" WHERE ID=SELECT MIN(ID) FROM "
+
table
);
stat
.
execute
(
"DELETE FROM "
+
table
+
" WHERE ID=SELECT MIN(ID) FROM "
+
table
);
count
[
tableId
]--;
count
[
tableId
]--;
}
}
break
;
break
;
case
2
:
case
2
:
sp
=
conn
.
setSavepoint
();
sp
=
conn
.
setSavepoint
();
countSave
[
0
]
=
count
[
0
];
countSave
[
1
]
=
count
[
1
];
countSave
[
0
]
=
count
[
0
];
countSave
[
1
]
=
count
[
1
];
break
;
break
;
case
3
:
case
3
:
if
(
sp
!=
null
)
{
if
(
sp
!=
null
)
{
conn
.
rollback
(
sp
);
conn
.
rollback
(
sp
);
count
[
0
]
=
countSave
[
0
];
count
[
1
]
=
countSave
[
1
];
count
[
0
]
=
countSave
[
0
];
count
[
1
]
=
countSave
[
1
];
}
}
break
;
break
;
case
4
:
case
4
:
conn
.
commit
();
conn
.
commit
();
sp
=
null
;
sp
=
null
;
countCommitted
[
0
]
=
count
[
0
];
countCommitted
[
1
]
=
count
[
1
];
countCommitted
[
0
]
=
count
[
0
];
countCommitted
[
1
]
=
count
[
1
];
break
;
break
;
case
5
:
case
5
:
conn
.
rollback
();
conn
.
rollback
();
sp
=
null
;
sp
=
null
;
count
[
0
]
=
countCommitted
[
0
];
count
[
1
]
=
countCommitted
[
1
];
count
[
0
]
=
countCommitted
[
0
];
count
[
1
]
=
countCommitted
[
1
];
break
;
break
;
}
}
checkTableCount
(
stat
,
"TEST0"
,
count
[
0
]);
checkTableCount
(
stat
,
"TEST0"
,
count
[
0
]);
...
@@ -76,22 +80,22 @@ public class TestTransaction extends TestBase {
...
@@ -76,22 +80,22 @@ public class TestTransaction extends TestBase {
}
}
conn
.
close
();
conn
.
close
();
}
}
private
void
checkTableCount
(
Statement
stat
,
String
tableName
,
int
count
)
throws
Exception
{
private
void
checkTableCount
(
Statement
stat
,
String
tableName
,
int
count
)
throws
Exception
{
ResultSet
rs
;
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM "
+
tableName
);
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM "
+
tableName
);
rs
.
next
();
rs
.
next
();
check
(
count
,
rs
.
getInt
(
1
));
check
(
count
,
rs
.
getInt
(
1
));
}
}
public
void
testIsolation
()
throws
Exception
{
public
void
testIsolation
()
throws
Exception
{
Connection
conn
=
getConnection
(
"transaction"
);
Connection
conn
=
getConnection
(
"transaction"
);
trace
(
"default TransactionIsolation="
+
conn
.
getTransactionIsolation
());
trace
(
"default TransactionIsolation="
+
conn
.
getTransactionIsolation
());
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_READ_COMMITTED
);
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_READ_COMMITTED
);
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_READ_COMMITTED
);
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_READ_COMMITTED
);
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_SERIALIZABLE
);
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_SERIALIZABLE
);
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_SERIALIZABLE
);
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_SERIALIZABLE
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
check
(
conn
.
getAutoCommit
());
check
(
conn
.
getAutoCommit
());
conn
.
setAutoCommit
(
false
);
conn
.
setAutoCommit
(
false
);
checkFalse
(
conn
.
getAutoCommit
());
checkFalse
(
conn
.
getAutoCommit
());
...
@@ -101,10 +105,10 @@ public class TestTransaction extends TestBase {
...
@@ -101,10 +105,10 @@ public class TestTransaction extends TestBase {
conn
.
commit
();
conn
.
commit
();
test
(
stat
,
"INSERT INTO TEST VALUES(0)"
);
test
(
stat
,
"INSERT INTO TEST VALUES(0)"
);
conn
.
rollback
();
conn
.
rollback
();
testValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
,
"1"
);
testValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
,
"1"
);
conn
.
setAutoCommit
(
false
);
conn
.
setAutoCommit
(
false
);
test
(
stat
,
"DELETE FROM TEST"
);
test
(
stat
,
"DELETE FROM TEST"
);
//testValue("SELECT COUNT(*) FROM TEST", "0");
//
testValue("SELECT COUNT(*) FROM TEST", "0");
conn
.
rollback
();
conn
.
rollback
();
testValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
,
"1"
);
testValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
,
"1"
);
conn
.
commit
();
conn
.
commit
();
...
@@ -114,78 +118,78 @@ public class TestTransaction extends TestBase {
...
@@ -114,78 +118,78 @@ public class TestTransaction extends TestBase {
testNestedResultSets
(
conn
);
testNestedResultSets
(
conn
);
conn
.
close
();
conn
.
close
();
}
}
void
testNestedResultSets
(
Connection
conn
)
throws
Exception
{
void
testNestedResultSets
(
Connection
conn
)
throws
Exception
{
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
test
(
stat
,
"CREATE TABLE NEST1(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
test
(
stat
,
"CREATE TABLE NEST1(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
test
(
stat
,
"CREATE TABLE NEST2(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
test
(
stat
,
"CREATE TABLE NEST2(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
DatabaseMetaData
meta
=
conn
.
getMetaData
();
DatabaseMetaData
meta
=
conn
.
getMetaData
();
Vector
result
;
Vector
result
;
ResultSet
rs1
,
rs2
;
ResultSet
rs1
,
rs2
;
result
=
new
Vector
();
result
=
new
Vector
();
rs1
=
meta
.
getTables
(
null
,
null
,
"NEST%"
,
null
);
rs1
=
meta
.
getTables
(
null
,
null
,
"NEST%"
,
null
);
while
(
rs1
.
next
())
{
while
(
rs1
.
next
())
{
String
table
=
rs1
.
getString
(
"TABLE_NAME"
);
String
table
=
rs1
.
getString
(
"TABLE_NAME"
);
rs2
=
meta
.
getColumns
(
null
,
null
,
table
,
null
);
rs2
=
meta
.
getColumns
(
null
,
null
,
table
,
null
);
while
(
rs2
.
next
())
{
while
(
rs2
.
next
())
{
String
column
=
rs2
.
getString
(
"COLUMN_NAME"
);
String
column
=
rs2
.
getString
(
"COLUMN_NAME"
);
trace
(
"Table: "
+
table
+
" Column: "
+
column
);
trace
(
"Table: "
+
table
+
" Column: "
+
column
);
result
.
add
(
table
+
"."
+
column
);
result
.
add
(
table
+
"."
+
column
);
}
}
}
}
if
(
result
.
size
()!=
4
)
{
if
(
result
.
size
()
!=
4
)
{
error
(
"Wrong result, should be NEST1.ID, NEST1.NAME, NEST2.ID, NEST2.NAME but is "
+
result
);
error
(
"Wrong result, should be NEST1.ID, NEST1.NAME, NEST2.ID, NEST2.NAME but is "
+
result
);
}
}
result
=
new
Vector
();
result
=
new
Vector
();
test
(
stat
,
"INSERT INTO NEST1 VALUES(1,'A')"
);
test
(
stat
,
"INSERT INTO NEST1 VALUES(1,'A')"
);
test
(
stat
,
"INSERT INTO NEST1 VALUES(2,'B')"
);
test
(
stat
,
"INSERT INTO NEST1 VALUES(2,'B')"
);
test
(
stat
,
"INSERT INTO NEST2 VALUES(1,'1')"
);
test
(
stat
,
"INSERT INTO NEST2 VALUES(1,'1')"
);
test
(
stat
,
"INSERT INTO NEST2 VALUES(2,'2')"
);
test
(
stat
,
"INSERT INTO NEST2 VALUES(2,'2')"
);
Statement
s1
=
conn
.
createStatement
();
Statement
s1
=
conn
.
createStatement
();
Statement
s2
=
conn
.
createStatement
();
Statement
s2
=
conn
.
createStatement
();
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
while
(
rs1
.
next
())
{
while
(
rs1
.
next
())
{
rs2
=
s2
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
rs2
=
s2
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
while
(
rs2
.
next
())
{
while
(
rs2
.
next
())
{
String
v1
=
rs1
.
getString
(
"VALUE"
);
String
v1
=
rs1
.
getString
(
"VALUE"
);
String
v2
=
rs2
.
getString
(
"VALUE"
);
String
v2
=
rs2
.
getString
(
"VALUE"
);
result
.
add
(
v1
+
"/"
+
v2
);
result
.
add
(
v1
+
"/"
+
v2
);
}
}
}
}
if
(
result
.
size
()!=
4
)
{
if
(
result
.
size
()
!=
4
)
{
error
(
"Wrong result, should be A/1, A/2, B/1, B/2 but is "
+
result
);
error
(
"Wrong result, should be A/1, A/2, B/1, B/2 but is "
+
result
);
}
}
result
=
new
Vector
();
result
=
new
Vector
();
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
rs2
=
s1
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
rs2
=
s1
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
try
{
try
{
rs1
.
next
();
rs1
.
next
();
error
(
"next worked on a closed result set"
);
error
(
"next worked on a closed result set"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
checkNotGeneralException
(
e
);
}
}
// this is already closed, so but closing again should no do any harm
// this is already closed, so but closing again should no do any harm
rs1
.
close
();
rs1
.
close
();
while
(
rs2
.
next
())
{
while
(
rs2
.
next
())
{
String
v1
=
rs2
.
getString
(
"VALUE"
);
String
v1
=
rs2
.
getString
(
"VALUE"
);
result
.
add
(
v1
);
result
.
add
(
v1
);
}
}
if
(
result
.
size
()!=
2
)
{
if
(
result
.
size
()
!=
2
)
{
error
(
"Wrong result, should be A, B but is "
+
result
);
error
(
"Wrong result, should be A, B but is "
+
result
);
}
}
test
(
stat
,
"DROP TABLE NEST1"
);
test
(
stat
,
"DROP TABLE NEST1"
);
test
(
stat
,
"DROP TABLE NEST2"
);
test
(
stat
,
"DROP TABLE NEST2"
);
}
}
void
testValue
(
Statement
stat
,
String
sql
,
String
data
)
throws
Exception
{
void
testValue
(
Statement
stat
,
String
sql
,
String
data
)
throws
Exception
{
ResultSet
rs
=
stat
.
executeQuery
(
sql
);
ResultSet
rs
=
stat
.
executeQuery
(
sql
);
rs
.
next
();
rs
.
next
();
String
s
=
rs
.
getString
(
1
);
String
s
=
rs
.
getString
(
1
);
if
(
s
==
null
?
(
data
!=
null
)
:
(!
s
.
equals
(
data
)))
{
if
(
s
==
null
?
(
data
!=
null
)
:
(!
s
.
equals
(
data
)))
{
error
(
"s= "
+
s
+
" should be: "
+
data
);
error
(
"s= "
+
s
+
" should be: "
+
data
);
}
}
}
}
void
test
(
Statement
stat
,
String
sql
)
throws
Exception
{
void
test
(
Statement
stat
,
String
sql
)
throws
Exception
{
trace
(
sql
);
trace
(
sql
);
stat
.
execute
(
sql
);
stat
.
execute
(
sql
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestTwoPhaseCommit.java
浏览文件 @
f447a3e4
...
@@ -13,21 +13,21 @@ import org.h2.test.TestBase;
...
@@ -13,21 +13,21 @@ import org.h2.test.TestBase;
public
class
TestTwoPhaseCommit
extends
TestBase
{
public
class
TestTwoPhaseCommit
extends
TestBase
{
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
if
(
config
.
memory
||
config
.
networked
||
config
.
logMode
==
0
)
{
if
(
config
.
memory
||
config
.
networked
||
config
.
logMode
==
0
)
{
return
;
return
;
}
}
deleteDb
(
"twoPhaseCommit"
);
deleteDb
(
"twoPhaseCommit"
);
prepare
();
prepare
();
openWith
(
true
);
openWith
(
true
);
test
(
true
);
test
(
true
);
prepare
();
prepare
();
openWith
(
false
);
openWith
(
false
);
test
(
false
);
test
(
false
);
}
}
void
test
(
boolean
rolledBack
)
throws
Exception
{
void
test
(
boolean
rolledBack
)
throws
Exception
{
Connection
conn
=
getConnection
(
"twoPhaseCommit"
);
Connection
conn
=
getConnection
(
"twoPhaseCommit"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
...
@@ -36,7 +36,7 @@ public class TestTwoPhaseCommit extends TestBase {
...
@@ -36,7 +36,7 @@ public class TestTwoPhaseCommit extends TestBase {
rs
.
next
();
rs
.
next
();
check
(
rs
.
getInt
(
1
),
1
);
check
(
rs
.
getInt
(
1
),
1
);
check
(
rs
.
getString
(
2
),
"Hello"
);
check
(
rs
.
getString
(
2
),
"Hello"
);
if
(
rolledBack
)
{
if
(
rolledBack
)
{
}
else
{
}
else
{
rs
.
next
();
rs
.
next
();
check
(
rs
.
getInt
(
1
),
2
);
check
(
rs
.
getInt
(
1
),
2
);
...
@@ -45,18 +45,18 @@ public class TestTwoPhaseCommit extends TestBase {
...
@@ -45,18 +45,18 @@ public class TestTwoPhaseCommit extends TestBase {
checkFalse
(
rs
.
next
());
checkFalse
(
rs
.
next
());
conn
.
close
();
conn
.
close
();
}
}
void
openWith
(
boolean
rollback
)
throws
Exception
{
void
openWith
(
boolean
rollback
)
throws
Exception
{
Connection
conn
=
getConnection
(
"twoPhaseCommit"
);
Connection
conn
=
getConnection
(
"twoPhaseCommit"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ArrayList
list
=
new
ArrayList
();
ArrayList
list
=
new
ArrayList
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM INFORMATION_SCHEMA.IN_DOUBT"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM INFORMATION_SCHEMA.IN_DOUBT"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
list
.
add
(
rs
.
getString
(
"TRANSACTION"
));
list
.
add
(
rs
.
getString
(
"TRANSACTION"
));
}
}
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
String
s
=
(
String
)
list
.
get
(
i
);
String
s
=
(
String
)
list
.
get
(
i
);
if
(
rollback
)
{
if
(
rollback
)
{
stat
.
execute
(
"ROLLBACK TRANSACTION "
+
s
);
stat
.
execute
(
"ROLLBACK TRANSACTION "
+
s
);
}
else
{
}
else
{
stat
.
execute
(
"COMMIT TRANSACTION "
+
s
);
stat
.
execute
(
"COMMIT TRANSACTION "
+
s
);
...
@@ -64,7 +64,7 @@ public class TestTwoPhaseCommit extends TestBase {
...
@@ -64,7 +64,7 @@ public class TestTwoPhaseCommit extends TestBase {
}
}
conn
.
close
();
conn
.
close
();
}
}
void
prepare
()
throws
Exception
{
void
prepare
()
throws
Exception
{
deleteDb
(
"twoPhaseCommit"
);
deleteDb
(
"twoPhaseCommit"
);
Connection
conn
=
getConnection
(
"twoPhaseCommit"
);
Connection
conn
=
getConnection
(
"twoPhaseCommit"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestView.java
浏览文件 @
f447a3e4
...
@@ -17,10 +17,10 @@ public class TestView extends TestBase {
...
@@ -17,10 +17,10 @@ public class TestView extends TestBase {
Statement
s
=
conn
.
createStatement
();
Statement
s
=
conn
.
createStatement
();
s
.
execute
(
"create table t0(id int primary key)"
);
s
.
execute
(
"create table t0(id int primary key)"
);
s
.
execute
(
"insert into t0 values(1), (2), (3)"
);
s
.
execute
(
"insert into t0 values(1), (2), (3)"
);
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
s
.
execute
(
"create view t"
+
(
i
+
1
)
+
" as select * from t"
+
i
);
s
.
execute
(
"create view t"
+
(
i
+
1
)
+
" as select * from t"
+
i
);
s
.
execute
(
"select * from t"
+
(
i
+
1
));
s
.
execute
(
"select * from t"
+
(
i
+
1
));
ResultSet
rs
=
s
.
executeQuery
(
"select count(*) from t"
+
(
i
+
1
)
+
" where id=2"
);
ResultSet
rs
=
s
.
executeQuery
(
"select count(*) from t"
+
(
i
+
1
)
+
" where id=2"
);
check
(
rs
.
next
());
check
(
rs
.
next
());
check
(
rs
.
getInt
(
1
),
1
);
check
(
rs
.
getInt
(
1
),
1
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestBitField.java
浏览文件 @
f447a3e4
...
@@ -15,22 +15,22 @@ import org.h2.util.BitField;
...
@@ -15,22 +15,22 @@ import org.h2.util.BitField;
*/
*/
public
class
TestBitField
extends
TestBase
{
public
class
TestBitField
extends
TestBase
{
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testRandom
();
testRandom
();
testGetSet
();
testGetSet
();
}
}
void
testRandom
()
throws
Exception
{
void
testRandom
()
throws
Exception
{
BitField
bits
=
new
BitField
();
BitField
bits
=
new
BitField
();
BitSet
set
=
new
BitSet
();
BitSet
set
=
new
BitSet
();
int
max
=
300
;
int
max
=
300
;
int
count
=
100000
;
int
count
=
100000
;
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
int
idx
=
random
.
nextInt
(
max
);
int
idx
=
random
.
nextInt
(
max
);
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
bits
.
set
(
idx
);
bits
.
set
(
idx
);
set
.
set
(
idx
);
set
.
set
(
idx
);
}
else
{
}
else
{
...
@@ -44,26 +44,26 @@ public class TestBitField extends TestBase {
...
@@ -44,26 +44,26 @@ public class TestBitField extends TestBase {
}
}
}
}
}
}
void
testGetSet
()
throws
Exception
{
void
testGetSet
()
throws
Exception
{
BitField
bits
=
new
BitField
();
BitField
bits
=
new
BitField
();
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
bits
.
set
(
i
);
bits
.
set
(
i
);
if
(!
bits
.
get
(
i
))
{
if
(!
bits
.
get
(
i
))
{
throw
new
Exception
(
"not set: "
+
i
);
throw
new
Exception
(
"not set: "
+
i
);
}
}
if
(
bits
.
get
(
i
+
1
))
{
if
(
bits
.
get
(
i
+
1
))
{
throw
new
Exception
(
"set: "
+
i
);
throw
new
Exception
(
"set: "
+
i
);
}
}
}
}
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
if
(!
bits
.
get
(
i
))
{
if
(!
bits
.
get
(
i
))
{
throw
new
Exception
(
"not set: "
+
i
);
throw
new
Exception
(
"not set: "
+
i
);
}
}
}
}
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
int
k
=
bits
.
nextClearBit
(
0
);
int
k
=
bits
.
nextClearBit
(
0
);
if
(
k
!=
10000
)
{
if
(
k
!=
10000
)
{
throw
new
Exception
(
""
+
k
);
throw
new
Exception
(
""
+
k
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestCache.java
浏览文件 @
f447a3e4
...
@@ -12,9 +12,9 @@ import java.util.Random;
...
@@ -12,9 +12,9 @@ import java.util.Random;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
public
class
TestCache
extends
TestBase
{
public
class
TestCache
extends
TestBase
{
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
return
;
}
}
deleteDb
(
"cache"
);
deleteDb
(
"cache"
);
...
@@ -26,7 +26,7 @@ public class TestCache extends TestBase {
...
@@ -26,7 +26,7 @@ public class TestCache extends TestBase {
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?)"
);
PreparedStatement
prep2
=
conn
.
prepareStatement
(
"INSERT INTO MAIN VALUES(?, ?)"
);
PreparedStatement
prep2
=
conn
.
prepareStatement
(
"INSERT INTO MAIN VALUES(?, ?)"
);
int
max
=
10000
;
int
max
=
10000
;
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
setInt
(
1
,
i
);
prep
.
setString
(
2
,
"Hello "
+
i
);
prep
.
setString
(
2
,
"Hello "
+
i
);
prep
.
execute
();
prep
.
execute
();
...
@@ -39,10 +39,10 @@ public class TestCache extends TestBase {
...
@@ -39,10 +39,10 @@ public class TestCache extends TestBase {
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET CACHE_SIZE 1024"
);
stat
.
execute
(
"SET CACHE_SIZE 1024"
);
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
stat
.
executeQuery
(
"SELECT * FROM MAIN WHERE ID BETWEEN 40 AND 50"
);
stat
.
executeQuery
(
"SELECT * FROM MAIN WHERE ID BETWEEN 40 AND 50"
);
stat
.
executeQuery
(
"SELECT * FROM MAIN WHERE ID = "
+
random
.
nextInt
(
max
));
stat
.
executeQuery
(
"SELECT * FROM MAIN WHERE ID = "
+
random
.
nextInt
(
max
));
if
((
i
%
10
)
==
0
)
{
if
((
i
%
10
)
==
0
)
{
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestCompress.java
浏览文件 @
f447a3e4
...
@@ -10,15 +10,15 @@ import org.h2.test.TestBase;
...
@@ -10,15 +10,15 @@ import org.h2.test.TestBase;
import
org.h2.tools.CompressTool
;
import
org.h2.tools.CompressTool
;
public
class
TestCompress
extends
TestBase
{
public
class
TestCompress
extends
TestBase
{
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
if
(
config
.
big
)
{
if
(
config
.
big
)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
test
(
i
);
test
(
i
);
}
}
for
(
int
i
=
100
;
i
<
10000
;
i
+=
(
i
+
i
+
1
))
{
for
(
int
i
=
100
;
i
<
10000
;
i
+=
(
i
+
i
+
1
))
{
test
(
i
);
test
(
i
);
}
}
}
else
{
}
else
{
test
(
0
);
test
(
0
);
test
(
1
);
test
(
1
);
...
@@ -27,17 +27,17 @@ public class TestCompress extends TestBase {
...
@@ -27,17 +27,17 @@ public class TestCompress extends TestBase {
test
(
200
);
test
(
200
);
}
}
}
}
void
test
(
int
len
)
throws
Exception
{
void
test
(
int
len
)
throws
Exception
{
for
(
int
pattern
=
0
;
pattern
<
3
;
pattern
++)
{
for
(
int
pattern
=
0
;
pattern
<
3
;
pattern
++)
{
byte
[]
buff
=
new
byte
[
len
];
byte
[]
buff
=
new
byte
[
len
];
switch
(
pattern
)
{
switch
(
pattern
)
{
case
0
:
case
0
:
// leave empty
// leave empty
break
;
break
;
case
1
:
{
case
1
:
{
for
(
int
x
=
0
;
x
<
len
;
x
++)
{
for
(
int
x
=
0
;
x
<
len
;
x
++)
{
buff
[
x
]
=
(
byte
)(
x
&
10
);
buff
[
x
]
=
(
byte
)
(
x
&
10
);
}
}
break
;
break
;
}
}
...
@@ -47,11 +47,9 @@ public class TestCompress extends TestBase {
...
@@ -47,11 +47,9 @@ public class TestCompress extends TestBase {
break
;
break
;
}
}
}
}
String
[]
algorithm
=
new
String
[]{
String
[]
algorithm
=
new
String
[]
{
"LZF"
,
"Deflate"
,
"No"
};
"LZF"
,
"Deflate"
,
"No"
};
CompressTool
utils
=
CompressTool
.
getInstance
();
CompressTool
utils
=
CompressTool
.
getInstance
();
for
(
int
i
=
0
;
i
<
algorithm
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
algorithm
.
length
;
i
++)
{
byte
[]
out
=
utils
.
compress
(
buff
,
algorithm
[
i
]);
byte
[]
out
=
utils
.
compress
(
buff
,
algorithm
[
i
]);
byte
[]
test
=
utils
.
expand
(
out
);
byte
[]
test
=
utils
.
expand
(
out
);
check
(
test
.
length
,
buff
.
length
);
check
(
test
.
length
,
buff
.
length
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestDataPage.java
浏览文件 @
f447a3e4
...
@@ -22,21 +22,21 @@ import org.h2.value.ValueString;
...
@@ -22,21 +22,21 @@ import org.h2.value.ValueString;
*/
*/
public
class
TestDataPage
extends
TestBase
implements
DataHandler
{
public
class
TestDataPage
extends
TestBase
implements
DataHandler
{
boolean
text
;
boolean
text
;
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testAll
();
testAll
();
text
=
true
;
text
=
true
;
testAll
();
testAll
();
}
}
private
void
testAll
()
throws
Exception
{
private
void
testAll
()
throws
Exception
{
DataPage
page
=
DataPage
.
create
(
this
,
128
);
DataPage
page
=
DataPage
.
create
(
this
,
128
);
char
[]
data
=
new
char
[
0x10000
];
char
[]
data
=
new
char
[
0x10000
];
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
data
[
i
]
=
(
char
)
i
;
data
[
i
]
=
(
char
)
i
;
}
}
String
s
=
new
String
(
data
);
String
s
=
new
String
(
data
);
page
.
writeString
(
s
);
page
.
writeString
(
s
);
...
@@ -45,7 +45,7 @@ public class TestDataPage extends TestBase implements DataHandler {
...
@@ -45,7 +45,7 @@ public class TestDataPage extends TestBase implements DataHandler {
page
.
reset
();
page
.
reset
();
check
(
s
,
page
.
readString
());
check
(
s
,
page
.
readString
());
page
.
reset
();
page
.
reset
();
page
.
writeString
(
"H\u1111!"
);
page
.
writeString
(
"H\u1111!"
);
page
.
writeString
(
"John\tBrack's \"how are you\" M\u1111ller"
);
page
.
writeString
(
"John\tBrack's \"how are you\" M\u1111ller"
);
page
.
writeValue
(
ValueInt
.
get
(
10
));
page
.
writeValue
(
ValueInt
.
get
(
10
));
...
@@ -60,8 +60,8 @@ public class TestDataPage extends TestBase implements DataHandler {
...
@@ -60,8 +60,8 @@ public class TestDataPage extends TestBase implements DataHandler {
trace
(
page
.
readString
());
trace
(
page
.
readString
());
trace
(
page
.
readValue
().
getInt
());
trace
(
page
.
readValue
().
getInt
());
trace
(
page
.
readValue
().
getString
());
trace
(
page
.
readValue
().
getString
());
trace
(
""
+
page
.
readValue
().
getFloat
());
trace
(
""
+
page
.
readValue
().
getFloat
());
trace
(
""
+
page
.
readValue
().
getDouble
());
trace
(
""
+
page
.
readValue
().
getDouble
());
trace
(
page
.
readValue
().
toString
());
trace
(
page
.
readValue
().
toString
());
page
.
reset
();
page
.
reset
();
...
@@ -98,7 +98,7 @@ public class TestDataPage extends TestBase implements DataHandler {
...
@@ -98,7 +98,7 @@ public class TestDataPage extends TestBase implements DataHandler {
}
}
public
int
getChecksum
(
byte
[]
data
,
int
start
,
int
end
)
{
public
int
getChecksum
(
byte
[]
data
,
int
start
,
int
end
)
{
return
end
-
start
;
return
end
-
start
;
}
}
public
void
checkPowerOff
()
throws
SQLException
{
public
void
checkPowerOff
()
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestExit.java
浏览文件 @
f447a3e4
...
@@ -16,18 +16,14 @@ import org.h2.test.TestBase;
...
@@ -16,18 +16,14 @@ import org.h2.test.TestBase;
public
class
TestExit
extends
TestBase
implements
DatabaseEventListener
{
public
class
TestExit
extends
TestBase
implements
DatabaseEventListener
{
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
if
(
config
.
codeCoverage
)
{
if
(
config
.
codeCoverage
)
{
return
;
return
;
}
}
String
classPath
=
"bin"
+
File
.
pathSeparator
+
"."
;
String
classPath
=
"bin"
+
File
.
pathSeparator
+
"."
;
deleteDb
(
"exit"
);
deleteDb
(
"exit"
);
String
[]
procDef
;
String
[]
procDef
;
procDef
=
new
String
[]{
procDef
=
new
String
[]
{
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITH_CLOSE_ON_EXIT
};
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITH_CLOSE_ON_EXIT
};
Process
proc
=
Runtime
.
getRuntime
().
exec
(
procDef
);
Process
proc
=
Runtime
.
getRuntime
().
exec
(
procDef
);
while
(
true
)
{
while
(
true
)
{
int
ch
=
proc
.
getErrorStream
().
read
();
int
ch
=
proc
.
getErrorStream
().
read
();
...
@@ -44,50 +40,48 @@ public class TestExit extends TestBase implements DatabaseEventListener {
...
@@ -44,50 +40,48 @@ public class TestExit extends TestBase implements DatabaseEventListener {
System
.
out
.
print
((
char
)
ch
);
System
.
out
.
print
((
char
)
ch
);
}
}
proc
.
waitFor
();
proc
.
waitFor
();
if
(!
getClosedFile
().
exists
())
{
if
(!
getClosedFile
().
exists
())
{
error
(
"did not close database"
);
error
(
"did not close database"
);
}
}
procDef
=
new
String
[]{
procDef
=
new
String
[]
{
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITHOUT_CLOSE_ON_EXIT
};
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITHOUT_CLOSE_ON_EXIT
};
proc
=
Runtime
.
getRuntime
().
exec
(
procDef
);
proc
=
Runtime
.
getRuntime
().
exec
(
procDef
);
proc
.
waitFor
();
proc
.
waitFor
();
if
(
getClosedFile
().
exists
())
{
if
(
getClosedFile
().
exists
())
{
error
(
"closed database"
);
error
(
"closed database"
);
}
}
}
}
static
final
int
OPEN_WITH_CLOSE_ON_EXIT
=
1
,
OPEN_WITHOUT_CLOSE_ON_EXIT
=
2
;
static
final
int
OPEN_WITH_CLOSE_ON_EXIT
=
1
,
OPEN_WITHOUT_CLOSE_ON_EXIT
=
2
;
public
static
Connection
conn
;
public
static
Connection
conn
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
if
(
args
.
length
==
0
)
{
if
(
args
.
length
==
0
)
{
System
.
exit
(
1
);
System
.
exit
(
1
);
}
}
int
action
=
Integer
.
parseInt
(
args
[
0
]);
int
action
=
Integer
.
parseInt
(
args
[
0
]);
TestExit
app
=
new
TestExit
();
TestExit
app
=
new
TestExit
();
app
.
execute
(
action
);
app
.
execute
(
action
);
}
}
void
execute
(
int
action
)
throws
Exception
{
void
execute
(
int
action
)
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
Class
.
forName
(
"org.h2.Driver"
);
String
url
=
""
;
String
url
=
""
;
switch
(
action
)
{
switch
(
action
)
{
case
OPEN_WITH_CLOSE_ON_EXIT:
case
OPEN_WITH_CLOSE_ON_EXIT:
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=true"
;
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=true"
;
break
;
break
;
case
OPEN_WITHOUT_CLOSE_ON_EXIT:
case
OPEN_WITHOUT_CLOSE_ON_EXIT:
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=false"
;
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=false"
;
break
;
break
;
}
}
conn
=
open
(
url
);
conn
=
open
(
url
);
Connection
conn2
=
open
(
url
);
Connection
conn2
=
open
(
url
);
conn2
.
close
();
conn2
.
close
();
}
}
private
static
Connection
open
(
String
url
)
throws
Exception
{
private
static
Connection
open
(
String
url
)
throws
Exception
{
getClosedFile
().
delete
();
getClosedFile
().
delete
();
return
DriverManager
.
getConnection
(
url
,
"sa"
,
""
);
return
DriverManager
.
getConnection
(
url
,
"sa"
,
""
);
...
@@ -102,16 +96,16 @@ public class TestExit extends TestBase implements DatabaseEventListener {
...
@@ -102,16 +96,16 @@ public class TestExit extends TestBase implements DatabaseEventListener {
public
void
closingDatabase
()
{
public
void
closingDatabase
()
{
try
{
try
{
getClosedFile
().
createNewFile
();
getClosedFile
().
createNewFile
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
TestBase
.
logError
(
"error"
,
e
);
TestBase
.
logError
(
"error"
,
e
);
}
}
}
}
private
static
File
getClosedFile
()
{
private
static
File
getClosedFile
()
{
return
new
File
(
baseDir
+
"/closed.txt"
);
return
new
File
(
baseDir
+
"/closed.txt"
);
}
}
public
void
setProgress
(
int
state
,
String
name
,
int
x
,
int
max
)
{
public
void
setProgress
(
int
state
,
String
name
,
int
x
,
int
max
)
{
}
}
public
void
init
(
String
url
)
{
public
void
init
(
String
url
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestFileLock.java
浏览文件 @
f447a3e4
...
@@ -23,13 +23,14 @@ public class TestFileLock extends TestBase implements Runnable {
...
@@ -23,13 +23,14 @@ public class TestFileLock extends TestBase implements Runnable {
private
static
volatile
int
locks
;
private
static
volatile
int
locks
;
private
static
volatile
boolean
stop
;
private
static
volatile
boolean
stop
;
public
TestFileLock
()
{}
public
TestFileLock
()
{
}
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
test
(
false
);
test
(
false
);
test
(
true
);
test
(
true
);
}
}
void
test
(
boolean
allowSockets
)
throws
Exception
{
void
test
(
boolean
allowSockets
)
throws
Exception
{
int
threadCount
=
getSize
(
3
,
5
);
int
threadCount
=
getSize
(
3
,
5
);
wait
=
getSize
(
20
,
200
);
wait
=
getSize
(
20
,
200
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestIntArray.java
浏览文件 @
f447a3e4
...
@@ -10,7 +10,7 @@ import org.h2.test.TestBase;
...
@@ -10,7 +10,7 @@ import org.h2.test.TestBase;
import
org.h2.util.IntArray
;
import
org.h2.util.IntArray
;
public
class
TestIntArray
extends
TestBase
{
public
class
TestIntArray
extends
TestBase
{
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testRandom
();
testRandom
();
}
}
...
@@ -19,11 +19,11 @@ public class TestIntArray extends TestBase {
...
@@ -19,11 +19,11 @@ public class TestIntArray extends TestBase {
IntArray
array
=
new
IntArray
();
IntArray
array
=
new
IntArray
();
int
[]
test
=
new
int
[
0
];
int
[]
test
=
new
int
[
0
];
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
int
idx
=
test
.
length
==
0
?
0
:
random
.
nextInt
(
test
.
length
);
int
idx
=
test
.
length
==
0
?
0
:
random
.
nextInt
(
test
.
length
);
int
v
=
random
.
nextInt
(
100
);
int
v
=
random
.
nextInt
(
100
);
int
op
=
random
.
nextInt
(
9
);
int
op
=
random
.
nextInt
(
9
);
switch
(
op
)
{
switch
(
op
)
{
case
0
:
case
0
:
array
.
add
(
idx
,
v
);
array
.
add
(
idx
,
v
);
test
=
add
(
test
,
idx
,
v
);
test
=
add
(
test
,
idx
,
v
);
...
@@ -46,7 +46,7 @@ public class TestIntArray extends TestBase {
...
@@ -46,7 +46,7 @@ public class TestIntArray extends TestBase {
check
(
a
,
b
);
check
(
a
,
b
);
break
;
break
;
case
4
:
case
4
:
if
(
test
.
length
>
idx
)
{
if
(
test
.
length
>
idx
)
{
check
(
array
.
get
(
idx
),
get
(
test
,
idx
));
check
(
array
.
get
(
idx
),
get
(
test
,
idx
));
}
}
break
;
break
;
...
@@ -55,7 +55,7 @@ public class TestIntArray extends TestBase {
...
@@ -55,7 +55,7 @@ public class TestIntArray extends TestBase {
test
=
remove
(
test
,
idx
);
test
=
remove
(
test
,
idx
);
break
;
break
;
case
6
:
case
6
:
if
(
test
.
length
>
idx
)
{
if
(
test
.
length
>
idx
)
{
v
=
test
[
idx
];
v
=
test
[
idx
];
array
.
removeValue
(
v
);
array
.
removeValue
(
v
);
test
=
removeValue
(
test
,
v
);
test
=
removeValue
(
test
,
v
);
...
@@ -70,34 +70,34 @@ public class TestIntArray extends TestBase {
...
@@ -70,34 +70,34 @@ public class TestIntArray extends TestBase {
break
;
break
;
}
}
check
(
array
.
size
(),
test
.
length
);
check
(
array
.
size
(),
test
.
length
);
for
(
int
j
=
0
;
j
<
test
.
length
;
j
++)
{
for
(
int
j
=
0
;
j
<
test
.
length
;
j
++)
{
check
(
test
[
j
],
array
.
get
(
j
));
check
(
test
[
j
],
array
.
get
(
j
));
}
}
}
}
}
}
int
[]
add
(
int
[]
array
,
int
i
,
int
value
)
{
int
[]
add
(
int
[]
array
,
int
i
,
int
value
)
{
int
[]
a2
=
new
int
[
array
.
length
+
1
];
int
[]
a2
=
new
int
[
array
.
length
+
1
];
System
.
arraycopy
(
array
,
0
,
a2
,
0
,
array
.
length
);
System
.
arraycopy
(
array
,
0
,
a2
,
0
,
array
.
length
);
if
(
i
<
array
.
length
)
{
if
(
i
<
array
.
length
)
{
System
.
arraycopy
(
a2
,
i
,
a2
,
i
+
1
,
a2
.
length
-
i
-
1
);
System
.
arraycopy
(
a2
,
i
,
a2
,
i
+
1
,
a2
.
length
-
i
-
1
);
}
}
array
=
a2
;
array
=
a2
;
array
[
i
]
=
value
;
array
[
i
]
=
value
;
return
array
;
return
array
;
}
}
int
[]
add
(
int
[]
array
,
int
value
)
{
int
[]
add
(
int
[]
array
,
int
value
)
{
return
add
(
array
,
array
.
length
,
value
);
return
add
(
array
,
array
.
length
,
value
);
}
}
int
[]
addValueSorted
(
int
[]
array
,
int
value
)
{
int
[]
addValueSorted
(
int
[]
array
,
int
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
<
value
)
{
if
(
array
[
i
]
<
value
)
{
continue
;
continue
;
}
}
if
(
array
[
i
]
==
value
)
{
if
(
array
[
i
]
==
value
)
{
return
array
;
return
array
;
}
else
{
}
else
{
return
add
(
array
,
i
,
value
);
return
add
(
array
,
i
,
value
);
...
@@ -105,32 +105,32 @@ public class TestIntArray extends TestBase {
...
@@ -105,32 +105,32 @@ public class TestIntArray extends TestBase {
}
}
return
add
(
array
,
value
);
return
add
(
array
,
value
);
}
}
int
findNextValueIndex
(
int
[]
array
,
int
value
)
{
int
findNextValueIndex
(
int
[]
array
,
int
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
>=
value
)
{
if
(
array
[
i
]
>=
value
)
{
return
i
;
return
i
;
}
}
}
}
return
array
.
length
;
return
array
.
length
;
}
}
int
get
(
int
[]
array
,
int
i
)
{
int
get
(
int
[]
array
,
int
i
)
{
return
array
[
i
];
return
array
[
i
];
}
}
int
[]
remove
(
int
[]
array
,
int
i
)
{
int
[]
remove
(
int
[]
array
,
int
i
)
{
int
[]
a2
=
new
int
[
array
.
length
-
1
];
int
[]
a2
=
new
int
[
array
.
length
-
1
];
System
.
arraycopy
(
array
,
0
,
a2
,
0
,
i
);
System
.
arraycopy
(
array
,
0
,
a2
,
0
,
i
);
if
(
i
<
a2
.
length
)
{
if
(
i
<
a2
.
length
)
{
System
.
arraycopy
(
array
,
i
+
1
,
a2
,
i
,
array
.
length
-
i
-
1
);
System
.
arraycopy
(
array
,
i
+
1
,
a2
,
i
,
array
.
length
-
i
-
1
);
}
}
return
a2
;
return
a2
;
}
}
int
[]
removeValue
(
int
[]
array
,
int
value
)
{
int
[]
removeValue
(
int
[]
array
,
int
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
==
value
)
{
if
(
array
[
i
]
==
value
)
{
return
remove
(
array
,
i
);
return
remove
(
array
,
i
);
}
}
}
}
...
@@ -141,14 +141,14 @@ public class TestIntArray extends TestBase {
...
@@ -141,14 +141,14 @@ public class TestIntArray extends TestBase {
array
[
i
]
=
value
;
array
[
i
]
=
value
;
return
array
;
return
array
;
}
}
int
size
(
int
[]
array
)
{
int
size
(
int
[]
array
)
{
return
array
.
length
;
return
array
.
length
;
}
}
int
[]
sort
(
int
[]
array
)
{
int
[]
sort
(
int
[]
array
)
{
Arrays
.
sort
(
array
);
Arrays
.
sort
(
array
);
return
array
;
return
array
;
}
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestIntIntHashMap.java
浏览文件 @
f447a3e4
...
@@ -30,11 +30,11 @@ public class TestIntIntHashMap extends TestBase {
...
@@ -30,11 +30,11 @@ public class TestIntIntHashMap extends TestBase {
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
map
.
put
(
x
[
i
],
i
);
map
.
put
(
x
[
i
],
i
);
}
}
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
map
.
get
(
x
[
i
])
!=
i
)
{
if
(
map
.
get
(
x
[
i
])
!=
i
)
{
throw
new
Error
(
"get "
+
x
[
i
]
+
" = "
+
map
.
get
(
i
)
+
" should be "
+
i
);
throw
new
Error
(
"get "
+
x
[
i
]
+
" = "
+
map
.
get
(
i
)
+
" should be "
+
i
);
}
}
}
}
for
(
int
i
=
1
;
i
<
len
;
i
+=
2
)
{
for
(
int
i
=
1
;
i
<
len
;
i
+=
2
)
{
map
.
remove
(
x
[
i
]);
map
.
remove
(
x
[
i
]);
}
}
...
@@ -46,7 +46,7 @@ public class TestIntIntHashMap extends TestBase {
...
@@ -46,7 +46,7 @@ public class TestIntIntHashMap extends TestBase {
for
(
int
i
=
1
;
i
<
len
;
i
+=
2
)
{
for
(
int
i
=
1
;
i
<
len
;
i
+=
2
)
{
map
.
put
(
x
[
i
],
i
);
map
.
put
(
x
[
i
],
i
);
}
}
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
map
.
get
(
x
[
i
])
!=
i
)
{
if
(
map
.
get
(
x
[
i
])
!=
i
)
{
throw
new
Error
(
"get "
+
x
[
i
]
+
" = "
+
map
.
get
(
i
)
+
" should be "
+
i
);
throw
new
Error
(
"get "
+
x
[
i
]
+
" = "
+
map
.
get
(
i
)
+
" should be "
+
i
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestOverflow.java
浏览文件 @
f447a3e4
...
@@ -31,50 +31,50 @@ public class TestOverflow extends TestBase {
...
@@ -31,50 +31,50 @@ public class TestOverflow extends TestBase {
private
void
test
(
int
type
,
long
min
,
long
max
)
throws
Exception
{
private
void
test
(
int
type
,
long
min
,
long
max
)
throws
Exception
{
values
=
new
ArrayList
();
values
=
new
ArrayList
();
this
.
type
=
type
;
this
.
type
=
type
;
this
.
min
=
new
BigInteger
(
""
+
min
);
this
.
min
=
new
BigInteger
(
""
+
min
);
this
.
max
=
new
BigInteger
(
""
+
max
);
this
.
max
=
new
BigInteger
(
""
+
max
);
add
(
0
);
add
(
0
);
add
(
min
);
add
(
min
);
add
(
max
);
add
(
max
);
add
(
max
-
1
);
add
(
max
-
1
);
add
(
min
+
1
);
add
(
min
+
1
);
add
(
1
);
add
(
1
);
add
(-
1
);
add
(-
1
);
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
40
;
i
++)
{
for
(
int
i
=
0
;
i
<
40
;
i
++)
{
if
(
max
>
Integer
.
MAX_VALUE
)
{
if
(
max
>
Integer
.
MAX_VALUE
)
{
add
(
random
.
nextLong
());
add
(
random
.
nextLong
());
}
else
{
}
else
{
add
((
random
.
nextBoolean
()
?
1
:
-
1
)
*
random
.
nextInt
((
int
)
max
));
add
((
random
.
nextBoolean
()
?
1
:
-
1
)
*
random
.
nextInt
((
int
)
max
));
}
}
}
}
for
(
int
a
=
0
;
a
<
values
.
size
();
a
++)
{
for
(
int
a
=
0
;
a
<
values
.
size
();
a
++)
{
for
(
int
b
=
0
;
b
<
values
.
size
();
b
++)
{
for
(
int
b
=
0
;
b
<
values
.
size
();
b
++)
{
Value
va
=
(
Value
)
values
.
get
(
a
);
Value
va
=
(
Value
)
values
.
get
(
a
);
Value
vb
=
(
Value
)
values
.
get
(
b
);
Value
vb
=
(
Value
)
values
.
get
(
b
);
testValues
(
va
,
vb
);
testValues
(
va
,
vb
);
}
}
}
}
}
}
void
checkIfExpected
(
String
a
,
String
b
)
throws
Exception
{
void
checkIfExpected
(
String
a
,
String
b
)
throws
Exception
{
if
(
successExpected
)
{
if
(
successExpected
)
{
check
(
a
,
b
);
check
(
a
,
b
);
}
}
}
}
void
onSuccess
()
throws
Exception
{
void
onSuccess
()
throws
Exception
{
if
(!
successExpected
&&
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
if
(!
successExpected
&&
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
error
(
"unexpected success"
);
error
(
"unexpected success"
);
}
}
}
}
void
onError
()
throws
Exception
{
void
onError
()
throws
Exception
{
if
(
successExpected
)
{
if
(
successExpected
)
{
error
(
"unexpected error"
);
error
(
"unexpected error"
);
}
}
}
}
private
void
testValues
(
Value
va
,
Value
vb
)
throws
Exception
{
private
void
testValues
(
Value
va
,
Value
vb
)
throws
Exception
{
BigInteger
a
=
new
BigInteger
(
va
.
getString
());
BigInteger
a
=
new
BigInteger
(
va
.
getString
());
BigInteger
b
=
new
BigInteger
(
vb
.
getString
());
BigInteger
b
=
new
BigInteger
(
vb
.
getString
());
...
@@ -82,32 +82,32 @@ public class TestOverflow extends TestBase {
...
@@ -82,32 +82,32 @@ public class TestOverflow extends TestBase {
try
{
try
{
checkIfExpected
(
va
.
negate
().
getString
(),
a
.
negate
().
toString
());
checkIfExpected
(
va
.
negate
().
getString
(),
a
.
negate
().
toString
());
onSuccess
();
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
onError
();
}
}
successExpected
=
inRange
(
a
.
add
(
b
));
successExpected
=
inRange
(
a
.
add
(
b
));
try
{
try
{
checkIfExpected
(
va
.
add
(
vb
).
getString
(),
a
.
add
(
b
).
toString
());
checkIfExpected
(
va
.
add
(
vb
).
getString
(),
a
.
add
(
b
).
toString
());
onSuccess
();
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
onError
();
}
}
successExpected
=
inRange
(
a
.
subtract
(
b
));
successExpected
=
inRange
(
a
.
subtract
(
b
));
try
{
try
{
checkIfExpected
(
va
.
subtract
(
vb
).
getString
(),
a
.
subtract
(
b
).
toString
());
checkIfExpected
(
va
.
subtract
(
vb
).
getString
(),
a
.
subtract
(
b
).
toString
());
onSuccess
();
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
onError
();
}
}
successExpected
=
inRange
(
a
.
multiply
(
b
));
successExpected
=
inRange
(
a
.
multiply
(
b
));
try
{
try
{
checkIfExpected
(
va
.
multiply
(
vb
).
getString
(),
a
.
multiply
(
b
).
toString
());
checkIfExpected
(
va
.
multiply
(
vb
).
getString
(),
a
.
multiply
(
b
).
toString
());
onSuccess
();
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
onError
();
}
}
}
}
private
boolean
inRange
(
BigInteger
v
)
{
private
boolean
inRange
(
BigInteger
v
)
{
return
v
.
compareTo
(
min
)
>=
0
&&
v
.
compareTo
(
max
)
<=
0
;
return
v
.
compareTo
(
min
)
>=
0
&&
v
.
compareTo
(
max
)
<=
0
;
}
}
...
@@ -115,5 +115,5 @@ public class TestOverflow extends TestBase {
...
@@ -115,5 +115,5 @@ public class TestOverflow extends TestBase {
private
void
add
(
long
l
)
throws
SQLException
{
private
void
add
(
long
l
)
throws
SQLException
{
values
.
add
(
ValueString
.
get
(
""
+
l
).
convertTo
(
type
));
values
.
add
(
ValueString
.
get
(
""
+
l
).
convertTo
(
type
));
}
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestPattern.java
浏览文件 @
f447a3e4
...
@@ -12,7 +12,7 @@ import org.h2.value.CompareMode;
...
@@ -12,7 +12,7 @@ import org.h2.value.CompareMode;
* @author Thomas
* @author Thomas
*/
*/
public
class
TestPattern
extends
TestBase
{
public
class
TestPattern
extends
TestBase
{
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
CompareMode
mode
=
new
CompareMode
(
null
,
null
);
CompareMode
mode
=
new
CompareMode
(
null
,
null
);
CompareLike
comp
=
new
CompareLike
(
mode
,
null
,
null
,
null
,
false
);
CompareLike
comp
=
new
CompareLike
(
mode
,
null
,
null
,
null
,
false
);
...
@@ -21,41 +21,41 @@ public class TestPattern extends TestBase {
...
@@ -21,41 +21,41 @@ public class TestPattern extends TestBase {
test
(
comp
,
"A"
,
"A%%"
);
test
(
comp
,
"A"
,
"A%%"
);
test
(
comp
,
"A_A"
,
"%\\_%"
);
test
(
comp
,
"A_A"
,
"%\\_%"
);
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
String
pattern
=
getRandomPattern
();
String
pattern
=
getRandomPattern
();
String
value
=
getRandomValue
();
String
value
=
getRandomValue
();
test
(
comp
,
value
,
pattern
);
test
(
comp
,
value
,
pattern
);
}
}
}
}
void
test
(
CompareLike
comp
,
String
value
,
String
pattern
)
throws
Exception
{
void
test
(
CompareLike
comp
,
String
value
,
String
pattern
)
throws
Exception
{
String
regexp
=
initPatternRegexp
(
pattern
,
'\\'
);
String
regexp
=
initPatternRegexp
(
pattern
,
'\\'
);
boolean
resultRegexp
=
value
.
matches
(
regexp
);
boolean
resultRegexp
=
value
.
matches
(
regexp
);
boolean
result
=
comp
.
test
(
pattern
,
value
,
'\\'
);
boolean
result
=
comp
.
test
(
pattern
,
value
,
'\\'
);
if
(
result
!=
resultRegexp
)
{
if
(
result
!=
resultRegexp
)
{
error
(
"Error: >"
+
value
+
"< LIKE >"
+
pattern
+
"< result="
+
result
+
" resultReg="
+
resultRegexp
);
error
(
"Error: >"
+
value
+
"< LIKE >"
+
pattern
+
"< result="
+
result
+
" resultReg="
+
resultRegexp
);
}
}
}
}
static
String
getRandomValue
()
{
static
String
getRandomValue
()
{
StringBuffer
buff
=
new
StringBuffer
();
StringBuffer
buff
=
new
StringBuffer
();
int
len
=
(
int
)(
Math
.
random
()
*
10
);
int
len
=
(
int
)
(
Math
.
random
()
*
10
);
String
s
=
"AB_%\\"
;
String
s
=
"AB_%\\"
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
s
.
charAt
((
int
)
(
Math
.
random
()*
s
.
length
())));
buff
.
append
(
s
.
charAt
((
int
)
(
Math
.
random
()
*
s
.
length
())));
}
}
return
buff
.
toString
();
return
buff
.
toString
();
}
}
static
String
getRandomPattern
()
{
static
String
getRandomPattern
()
{
StringBuffer
buff
=
new
StringBuffer
();
StringBuffer
buff
=
new
StringBuffer
();
int
len
=
(
int
)(
Math
.
random
()
*
4
);
int
len
=
(
int
)
(
Math
.
random
()
*
4
);
String
s
=
"A%_\\"
;
String
s
=
"A%_\\"
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
char
c
=
s
.
charAt
((
int
)
(
Math
.
random
()*
s
.
length
()));
char
c
=
s
.
charAt
((
int
)
(
Math
.
random
()
*
s
.
length
()));
if
((
c
==
'_'
||
c
==
'%'
)
&&
Math
.
random
()
>
0.5
)
{
if
((
c
==
'_'
||
c
==
'%'
)
&&
Math
.
random
()
>
0.5
)
{
buff
.
append
(
'\\'
);
buff
.
append
(
'\\'
);
}
else
if
(
c
==
'\\'
)
{
}
else
if
(
c
==
'\\'
)
{
buff
.
append
(
c
);
buff
.
append
(
c
);
}
}
buff
.
append
(
c
);
buff
.
append
(
c
);
...
@@ -79,7 +79,7 @@ public class TestPattern extends TestBase {
...
@@ -79,7 +79,7 @@ public class TestPattern extends TestBase {
buff
.
append
(
".*"
);
buff
.
append
(
".*"
);
}
else
if
(
c
==
'_'
)
{
}
else
if
(
c
==
'_'
)
{
buff
.
append
(
'.'
);
buff
.
append
(
'.'
);
}
else
if
(
c
==
'\\'
)
{
}
else
if
(
c
==
'\\'
)
{
buff
.
append
(
"\\\\"
);
buff
.
append
(
"\\\\"
);
}
else
{
}
else
{
buff
.
append
(
c
);
buff
.
append
(
c
);
...
@@ -87,8 +87,8 @@ public class TestPattern extends TestBase {
...
@@ -87,8 +87,8 @@ public class TestPattern extends TestBase {
// TODO regexp: there are other chars that need escaping
// TODO regexp: there are other chars that need escaping
}
}
String
regexp
=
buff
.
toString
();
String
regexp
=
buff
.
toString
();
//
System.out.println("regexp = " + regexp);
//
System.out.println("regexp = " + regexp);
return
regexp
;
return
regexp
;
}
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestSampleApps.java
浏览文件 @
f447a3e4
...
@@ -16,39 +16,38 @@ public class TestSampleApps extends TestBase {
...
@@ -16,39 +16,38 @@ public class TestSampleApps extends TestBase {
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testApp
(
org
.
h2
.
samples
.
Compact
.
class
,
null
,
"Compacting...\nDone."
);
testApp
(
org
.
h2
.
samples
.
Compact
.
class
,
null
,
"Compacting...\nDone."
);
testApp
(
org
.
h2
.
samples
.
CsvSample
.
class
,
null
,
testApp
(
org
.
h2
.
samples
.
CsvSample
.
class
,
null
,
"NAME: Bob Meier\n"
+
"EMAIL: bob.meier@abcde.abc\n"
"NAME: Bob Meier\n"
+
"PHONE: +41123456789\n\n"
+
"NAME: John Jones\n"
+
"EMAIL: john.jones@abcde.abc\n"
+
"EMAIL: bob.meier@abcde.abc\n"
+
"PHONE: +41976543210\n"
);
+
"PHONE: +41123456789\n\n"
testApp
(
org
.
h2
.
samples
.
Function
.
class
,
null
,
+
"NAME: John Jones\n"
+
"EMAIL: john.jones@abcde.abc\n"
+
"PHONE: +41976543210\n"
);
testApp
(
org
.
h2
.
samples
.
Function
.
class
,
null
,
"2 is prime\n3 is prime\n5 is prime\n7 is prime\n11 is prime\n13 is prime\n17 is prime\n19 is prime"
);
"2 is prime\n3 is prime\n5 is prime\n7 is prime\n11 is prime\n13 is prime\n17 is prime\n19 is prime"
);
testApp
(
org
.
h2
.
samples
.
SecurePassword
.
class
,
null
,
"Hello"
);
testApp
(
org
.
h2
.
samples
.
SecurePassword
.
class
,
null
,
"Hello"
);
// TODO test ShowProgress (percent numbers are hardware specific)
// TODO test ShowProgress (percent numbers are hardware specific)
// TODO test ShutdownServer (server needs to be started in a separate process)
// TODO test ShutdownServer (server needs to be started in a separate
// process)
testApp
(
org
.
h2
.
samples
.
TriggerSample
.
class
,
null
,
"The sum is 20.00"
);
testApp
(
org
.
h2
.
samples
.
TriggerSample
.
class
,
null
,
"The sum is 20.00"
);
// tools
// tools
testApp
(
org
.
h2
.
tools
.
ChangePassword
.
class
,
new
String
[]{
"-?"
},
"java org.h2.tools.ChangePassword [-dir <dir>] "
testApp
(
org
.
h2
.
tools
.
ChangePassword
.
class
,
new
String
[]
{
"-?"
},
+
"[-db <database>] [-cipher <cipher>] [-decrypt <pwd>] [-encrypt <pwd>] [-quiet]"
);
"java org.h2.tools.ChangePassword [-dir <dir>] "
+
"[-db <database>] [-cipher <cipher>] [-decrypt <pwd>] [-encrypt <pwd>] [-quiet]"
);
testApp
(
org
.
h2
.
tools
.
ChangePassword
.
class
,
null
,
"java org.h2.tools.ChangePassword [-dir <dir>] "
testApp
(
org
.
h2
.
tools
.
ChangePassword
.
class
,
null
,
"java org.h2.tools.ChangePassword [-dir <dir>] "
+
"[-db <database>] [-cipher <cipher>] [-decrypt <pwd>] [-encrypt <pwd>] [-quiet]"
);
+
"[-db <database>] [-cipher <cipher>] [-decrypt <pwd>] [-encrypt <pwd>] [-quiet]"
);
testApp
(
org
.
h2
.
tools
.
DeleteDbFiles
.
class
,
new
String
[]{
"-?"
},
"java org.h2.tools.DeleteDbFiles [-dir <dir>] [-db <database>] [-quiet]"
);
testApp
(
org
.
h2
.
tools
.
DeleteDbFiles
.
class
,
new
String
[]
{
"-?"
},
"java org.h2.tools.DeleteDbFiles [-dir <dir>] [-db <database>] [-quiet]"
);
}
}
private
void
testApp
(
Class
clazz
,
String
[]
args
,
String
expected
)
throws
Exception
{
private
void
testApp
(
Class
clazz
,
String
[]
args
,
String
expected
)
throws
Exception
{
DeleteDbFiles
.
execute
(
"data"
,
"test"
,
true
);
DeleteDbFiles
.
execute
(
"data"
,
"test"
,
true
);
Method
m
=
clazz
.
getMethod
(
"main"
,
new
Class
[]
{
String
[].
class
});
Method
m
=
clazz
.
getMethod
(
"main"
,
new
Class
[]
{
String
[].
class
});
PrintStream
oldOut
=
System
.
out
,
oldErr
=
System
.
err
;
PrintStream
oldOut
=
System
.
out
,
oldErr
=
System
.
err
;
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
PrintStream
out
=
new
PrintStream
(
buff
,
false
,
"UTF-8"
);
PrintStream
out
=
new
PrintStream
(
buff
,
false
,
"UTF-8"
);
System
.
setOut
(
out
);
System
.
setOut
(
out
);
System
.
setErr
(
out
);
System
.
setErr
(
out
);
try
{
try
{
m
.
invoke
(
null
,
new
Object
[]
{
args
});
m
.
invoke
(
null
,
new
Object
[]
{
args
});
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
TestBase
.
logError
(
"error"
,
e
);
TestBase
.
logError
(
"error"
,
e
);
}
}
out
.
flush
();
out
.
flush
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestScriptReader.java
浏览文件 @
f447a3e4
...
@@ -20,24 +20,24 @@ public class TestScriptReader extends TestBase {
...
@@ -20,24 +20,24 @@ public class TestScriptReader extends TestBase {
private
void
testRandom
()
throws
Exception
{
private
void
testRandom
()
throws
Exception
{
int
len
=
getSize
(
1000
,
10000
);
int
len
=
getSize
(
1000
,
10000
);
Random
random
=
new
Random
(
10
);
Random
random
=
new
Random
(
10
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
l
=
random
.
nextInt
(
10
);
int
l
=
random
.
nextInt
(
10
);
String
[]
sql
=
new
String
[
l
];
String
[]
sql
=
new
String
[
l
];
StringBuffer
buff
=
new
StringBuffer
();
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
sql
[
j
]
=
randomStatement
(
random
);
sql
[
j
]
=
randomStatement
(
random
);
buff
.
append
(
sql
[
j
]);
buff
.
append
(
sql
[
j
]);
if
(
j
<
l
-
1
)
{
if
(
j
<
l
-
1
)
{
buff
.
append
(
";"
);
buff
.
append
(
";"
);
}
}
}
}
String
s
=
buff
.
toString
();
String
s
=
buff
.
toString
();
StringReader
reader
=
new
StringReader
(
s
);
StringReader
reader
=
new
StringReader
(
s
);
ScriptReader
source
=
new
ScriptReader
(
reader
);
ScriptReader
source
=
new
ScriptReader
(
reader
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
String
e
=
source
.
readStatement
();
String
e
=
source
.
readStatement
();
String
c
=
sql
[
j
];
String
c
=
sql
[
j
];
if
(
c
.
length
()
==
0
&&
j
==
l
-
1
)
{
if
(
c
.
length
()
==
0
&&
j
==
l
-
1
)
{
c
=
null
;
c
=
null
;
}
}
check
(
e
,
c
);
check
(
e
,
c
);
...
@@ -45,25 +45,25 @@ public class TestScriptReader extends TestBase {
...
@@ -45,25 +45,25 @@ public class TestScriptReader extends TestBase {
check
(
source
.
readStatement
(),
null
);
check
(
source
.
readStatement
(),
null
);
}
}
}
}
private
String
randomStatement
(
Random
random
)
{
private
String
randomStatement
(
Random
random
)
{
StringBuffer
buff
=
new
StringBuffer
();
StringBuffer
buff
=
new
StringBuffer
();
int
len
=
random
.
nextInt
(
5
);
int
len
=
random
.
nextInt
(
5
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
switch
(
random
.
nextInt
(
10
))
{
switch
(
random
.
nextInt
(
10
))
{
case
0
:
{
case
0
:
{
int
l
=
random
.
nextInt
(
4
);
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]{
"\n"
,
"\r"
,
" "
,
"*"
,
"a"
,
"0"
};
String
[]
ch
=
new
String
[]
{
"\n"
,
"\r"
,
" "
,
"*"
,
"a"
,
"0"
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
}
break
;
break
;
}
}
case
1
:
{
case
1
:
{
buff
.
append
(
'\''
);
buff
.
append
(
'\''
);
int
l
=
random
.
nextInt
(
4
);
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\""
};
String
[]
ch
=
new
String
[]
{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\""
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
}
buff
.
append
(
'\''
);
buff
.
append
(
'\''
);
...
@@ -71,9 +71,9 @@ public class TestScriptReader extends TestBase {
...
@@ -71,9 +71,9 @@ public class TestScriptReader extends TestBase {
}
}
case
2
:
{
case
2
:
{
buff
.
append
(
'"'
);
buff
.
append
(
'"'
);
int
l
=
random
.
nextInt
(
4
);
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\'"
};
String
[]
ch
=
new
String
[]
{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\'"
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
}
buff
.
append
(
'"'
);
buff
.
append
(
'"'
);
...
@@ -81,17 +81,17 @@ public class TestScriptReader extends TestBase {
...
@@ -81,17 +81,17 @@ public class TestScriptReader extends TestBase {
}
}
case
3
:
{
case
3
:
{
buff
.
append
(
'-'
);
buff
.
append
(
'-'
);
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
String
[]
ch
=
new
String
[]{
"\n"
,
"\r"
,
"*"
,
"a"
,
" "
};
String
[]
ch
=
new
String
[]
{
"\n"
,
"\r"
,
"*"
,
"a"
,
" "
};
int
l
=
1
+
random
.
nextInt
(
4
);
int
l
=
1
+
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
}
}
else
{
}
else
{
buff
.
append
(
'-'
);
buff
.
append
(
'-'
);
String
[]
ch
=
new
String
[]{
";"
,
"-"
,
"//"
,
"/*"
,
"*/"
,
"a"
};
String
[]
ch
=
new
String
[]
{
";"
,
"-"
,
"//"
,
"/*"
,
"*/"
,
"a"
};
int
l
=
random
.
nextInt
(
4
);
int
l
=
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
}
buff
.
append
(
'\n'
);
buff
.
append
(
'\n'
);
...
@@ -100,17 +100,17 @@ public class TestScriptReader extends TestBase {
...
@@ -100,17 +100,17 @@ public class TestScriptReader extends TestBase {
}
}
case
4
:
{
case
4
:
{
buff
.
append
(
'/'
);
buff
.
append
(
'/'
);
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
String
[]
ch
=
new
String
[]{
"\n"
,
"\r"
,
"a"
,
" "
,
"- "
};
String
[]
ch
=
new
String
[]
{
"\n"
,
"\r"
,
"a"
,
" "
,
"- "
};
int
l
=
1
+
random
.
nextInt
(
4
);
int
l
=
1
+
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
}
}
else
{
}
else
{
buff
.
append
(
'*'
);
buff
.
append
(
'*'
);
String
[]
ch
=
new
String
[]{
";"
,
"-"
,
"//"
,
"/* "
,
"--"
,
"\n"
,
"\r"
,
"a"
};
String
[]
ch
=
new
String
[]
{
";"
,
"-"
,
"//"
,
"/* "
,
"--"
,
"\n"
,
"\r"
,
"a"
};
int
l
=
random
.
nextInt
(
4
);
int
l
=
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
}
buff
.
append
(
"*/"
);
buff
.
append
(
"*/"
);
...
@@ -123,16 +123,15 @@ public class TestScriptReader extends TestBase {
...
@@ -123,16 +123,15 @@ public class TestScriptReader extends TestBase {
}
}
private
void
testCommon
()
throws
Exception
{
private
void
testCommon
()
throws
Exception
{
String
s
=
String
s
=
"a;';';\";\";--;\n;/*;\n*/;//;\na;"
;
"a;';';\";\";--;\n;/*;\n*/;//;\na;"
;
StringReader
reader
=
new
StringReader
(
s
);
StringReader
reader
=
new
StringReader
(
s
);
ScriptReader
source
=
new
ScriptReader
(
reader
);
ScriptReader
source
=
new
ScriptReader
(
reader
);
check
(
source
.
readStatement
(),
"a"
);
check
(
source
.
readStatement
(),
"a"
);
check
(
source
.
readStatement
(),
"';'"
);
check
(
source
.
readStatement
(),
"';'"
);
check
(
source
.
readStatement
(),
"\";\""
);
check
(
source
.
readStatement
(),
"\";\""
);
check
(
source
.
readStatement
(),
"--;\n"
);
check
(
source
.
readStatement
(),
"--;\n"
);
check
(
source
.
readStatement
(),
"/*;\n*/"
);
check
(
source
.
readStatement
(),
"/*;\n*/"
);
check
(
source
.
readStatement
(),
"//;\na"
);
check
(
source
.
readStatement
(),
"//;\na"
);
check
(
source
.
readStatement
(),
null
);
check
(
source
.
readStatement
(),
null
);
source
.
close
();
source
.
close
();
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestSecurity.java
浏览文件 @
f447a3e4
...
@@ -10,19 +10,18 @@ import org.h2.security.XTEA;
...
@@ -10,19 +10,18 @@ import org.h2.security.XTEA;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.ByteUtils
;
/**
/**
* @author Thomas
* @author Thomas
*/
*/
public
class
TestSecurity
extends
TestBase
{
public
class
TestSecurity
extends
TestBase
{
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testSHA
();
testSHA
();
testAES
();
testAES
();
testXTEA
();
testXTEA
();
}
}
public
void
testSHA
()
throws
Exception
{
public
void
testSHA
()
throws
Exception
{
SHA256
sha
=
new
SHA256
();
SHA256
sha
=
new
SHA256
();
testOneSHA
(
sha
);
testOneSHA
(
sha
);
...
@@ -31,29 +30,26 @@ public class TestSecurity extends TestBase {
...
@@ -31,29 +30,26 @@ public class TestSecurity extends TestBase {
private
String
getHashString
(
SHA256
sha
,
byte
[]
data
)
{
private
String
getHashString
(
SHA256
sha
,
byte
[]
data
)
{
byte
[]
result
=
sha
.
getHash
(
data
);
byte
[]
result
=
sha
.
getHash
(
data
);
return
ByteUtils
.
convertBytesToString
(
result
);
return
ByteUtils
.
convertBytesToString
(
result
);
}
}
private
void
testOneSHA
(
SHA256
sha
)
throws
Exception
{
private
void
testOneSHA
(
SHA256
sha
)
throws
Exception
{
if
(!
getHashString
(
sha
,
new
byte
[]
{
})
if
(!
getHashString
(
sha
,
new
byte
[]
{}).
equals
(
.
equals
(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
))
{
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
))
{
throw
new
Exception
(
"x"
);
throw
new
Exception
(
"x"
);
}
}
if
(!
getHashString
(
sha
,
new
byte
[]
{
0x19
})
if
(!
getHashString
(
sha
,
new
byte
[]
{
0x19
}).
equals
(
.
equals
(
"68aa2e2ee5dff96e3355e6c7ee373e3d6a4e17f75f9518d843709c0c9bc3e3d4"
))
{
"68aa2e2ee5dff96e3355e6c7ee373e3d6a4e17f75f9518d843709c0c9bc3e3d4"
))
{
throw
new
Exception
(
"x"
);
throw
new
Exception
(
"x"
);
}
}
if
(!
getHashString
(
sha
,
new
byte
[]
{
(
byte
)
0xe3
,
(
byte
)
0xd7
,
0x25
,
0x70
,
(
byte
)
0xdc
,
(
byte
)
0xdd
,
0x78
,
0x7c
,
(
byte
)
0xe3
,
(
byte
)
0x88
,
0x7a
,
(
byte
)
0xb2
,
(
byte
)
0xcd
,
0x68
,
0x46
,
0x52
})
if
(!
getHashString
(
.
equals
(
sha
,
"175ee69b02ba9b58e2b0a5fd13819cea573f3940a94f825128cf4209beabb4e8"
))
{
new
byte
[]
{
(
byte
)
0xe3
,
(
byte
)
0xd7
,
0x25
,
0x70
,
(
byte
)
0xdc
,
(
byte
)
0xdd
,
0x78
,
0x7c
,
(
byte
)
0xe3
,
(
byte
)
0x88
,
0x7a
,
(
byte
)
0xb2
,
(
byte
)
0xcd
,
0x68
,
0x46
,
0x52
}).
equals
(
"175ee69b02ba9b58e2b0a5fd13819cea573f3940a94f825128cf4209beabb4e8"
))
{
throw
new
Exception
(
"x"
);
throw
new
Exception
(
"x"
);
}
}
}
}
public
void
testXTEA
()
throws
Exception
{
public
void
testXTEA
()
throws
Exception
{
byte
[]
test
=
new
byte
[
4096
];
byte
[]
test
=
new
byte
[
4096
];
XTEA
xtea
=
new
XTEA
();
XTEA
xtea
=
new
XTEA
();
...
@@ -61,25 +57,24 @@ public class TestSecurity extends TestBase {
...
@@ -61,25 +57,24 @@ public class TestSecurity extends TestBase {
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
xtea
.
decryptBlock
(
test
,
test
,
0
);
xtea
.
decryptBlock
(
test
,
test
,
0
);
}
}
}
}
private
void
testAES
()
throws
Exception
{
private
void
testAES
()
throws
Exception
{
AES
test
=
new
AES
();
AES
test
=
new
AES
();
test
.
setKey
(
ByteUtils
.
convertStringToBytes
(
"000102030405060708090A0B0C0D0E0F"
));
test
.
setKey
(
ByteUtils
.
convertStringToBytes
(
"000102030405060708090A0B0C0D0E0F"
));
byte
[]
in
=
new
byte
[
128
];
byte
[]
in
=
new
byte
[
128
];
byte
[]
enc
=
new
byte
[
128
];
byte
[]
enc
=
new
byte
[
128
];
test
.
encrypt
(
enc
,
0
,
128
);
test
.
encrypt
(
enc
,
0
,
128
);
test
.
decrypt
(
enc
,
0
,
128
);
test
.
decrypt
(
enc
,
0
,
128
);
if
(
ByteUtils
.
compareNotNull
(
in
,
enc
)!=
0
)
{
if
(
ByteUtils
.
compareNotNull
(
in
,
enc
)
!=
0
)
{
throw
new
Error
(
"hey!"
);
throw
new
Error
(
"hey!"
);
}
}
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
test
.
encrypt
(
in
,
0
,
128
);
test
.
encrypt
(
in
,
0
,
128
);
test
.
decrypt
(
enc
,
0
,
128
);
test
.
decrypt
(
enc
,
0
,
128
);
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestStreams.java
浏览文件 @
f447a3e4
...
@@ -17,42 +17,42 @@ public class TestStreams extends TestBase {
...
@@ -17,42 +17,42 @@ public class TestStreams extends TestBase {
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testLZFStreams
();
testLZFStreams
();
}
}
byte
[]
getRandomBytes
(
Random
random
)
{
byte
[]
getRandomBytes
(
Random
random
)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
1000
),
random
.
nextInt
(
100000
),
random
.
nextInt
(
1000000
)
};
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
1000
),
random
.
nextInt
(
100000
),
random
.
nextInt
(
1000000
)
};
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
byte
[]
buffer
=
new
byte
[
size
];
byte
[]
buffer
=
new
byte
[
size
];
if
(
random
.
nextInt
(
5
)
==
1
)
{
if
(
random
.
nextInt
(
5
)
==
1
)
{
random
.
nextBytes
(
buffer
);
random
.
nextBytes
(
buffer
);
}
else
if
(
random
.
nextBoolean
())
{
}
else
if
(
random
.
nextBoolean
())
{
int
patternLen
=
random
.
nextInt
(
100
)
+
1
;
int
patternLen
=
random
.
nextInt
(
100
)
+
1
;
for
(
int
j
=
0
;
j
<
size
;
j
++)
{
for
(
int
j
=
0
;
j
<
size
;
j
++)
{
buffer
[
j
]
=
(
byte
)(
j
%
patternLen
);
buffer
[
j
]
=
(
byte
)
(
j
%
patternLen
);
}
}
}
}
return
buffer
;
return
buffer
;
}
}
private
void
testLZFStreams
()
throws
Exception
{
private
void
testLZFStreams
()
throws
Exception
{
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
int
max
=
getSize
(
100
,
1000
);
int
max
=
getSize
(
100
,
1000
);
for
(
int
i
=
0
;
i
<
max
;
i
+=
3
)
{
for
(
int
i
=
0
;
i
<
max
;
i
+=
3
)
{
byte
[]
buffer
=
getRandomBytes
(
random
);
byte
[]
buffer
=
getRandomBytes
(
random
);
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
LZFOutputStream
comp
=
new
LZFOutputStream
(
out
);
LZFOutputStream
comp
=
new
LZFOutputStream
(
out
);
if
(
random
.
nextInt
(
10
)
==
1
)
{
if
(
random
.
nextInt
(
10
)
==
1
)
{
comp
.
write
(
buffer
);
comp
.
write
(
buffer
);
}
else
{
}
else
{
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
size
=
Math
.
min
(
size
,
buffer
.
length
-
j
);
size
=
Math
.
min
(
size
,
buffer
.
length
-
j
);
if
(
size
==
1
)
{
if
(
size
==
1
)
{
comp
.
write
(
buffer
[
j
]);
comp
.
write
(
buffer
[
j
]);
}
else
{
}
else
{
comp
.
write
(
buffer
,
j
,
size
);
comp
.
write
(
buffer
,
j
,
size
);
}
}
j
+=
size
;
j
+=
size
;
}
}
}
}
comp
.
close
();
comp
.
close
();
...
@@ -60,19 +60,19 @@ public class TestStreams extends TestBase {
...
@@ -60,19 +60,19 @@ public class TestStreams extends TestBase {
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
compressed
);
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
compressed
);
LZFInputStream
decompress
=
new
LZFInputStream
(
in
);
LZFInputStream
decompress
=
new
LZFInputStream
(
in
);
byte
[]
test
=
new
byte
[
buffer
.
length
];
byte
[]
test
=
new
byte
[
buffer
.
length
];
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
if
(
size
==
1
)
{
if
(
size
==
1
)
{
int
x
=
decompress
.
read
();
int
x
=
decompress
.
read
();
if
(
x
<
0
)
{
if
(
x
<
0
)
{
break
;
break
;
}
}
test
[
j
++]
=
(
byte
)
x
;
test
[
j
++]
=
(
byte
)
x
;
}
else
{
}
else
{
size
=
Math
.
min
(
size
,
test
.
length
-
j
);
size
=
Math
.
min
(
size
,
test
.
length
-
j
);
int
l
=
decompress
.
read
(
test
,
j
,
size
);
int
l
=
decompress
.
read
(
test
,
j
,
size
);
if
(
l
<
0
)
{
if
(
l
<
0
)
{
break
;
break
;
}
else
{
}
else
{
j
+=
l
;
j
+=
l
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestStringCache.java
浏览文件 @
f447a3e4
...
@@ -10,27 +10,27 @@ import org.h2.test.TestBase;
...
@@ -10,27 +10,27 @@ import org.h2.test.TestBase;
import
org.h2.util.StringCache
;
import
org.h2.util.StringCache
;
public
class
TestStringCache
extends
TestBase
{
public
class
TestStringCache
extends
TestBase
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
TestStringCache
().
runBenchmark
();
new
TestStringCache
().
runBenchmark
();
}
}
private
void
runBenchmark
()
throws
Exception
{
private
void
runBenchmark
()
throws
Exception
{
returnNew
=
false
;
returnNew
=
false
;
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
useIntern
=
(
i
%
2
)
==
1
;
useIntern
=
(
i
%
2
)
==
1
;
long
time
=
System
.
currentTimeMillis
();
long
time
=
System
.
currentTimeMillis
();
testSingleThread
(
100000
);
testSingleThread
(
100000
);
time
=
System
.
currentTimeMillis
()
-
time
;
time
=
System
.
currentTimeMillis
()
-
time
;
System
.
out
.
println
(
time
+
" ms (useIntern="
+
useIntern
+
")"
);
System
.
out
.
println
(
time
+
" ms (useIntern="
+
useIntern
+
")"
);
}
}
}
}
private
Random
random
=
new
Random
(
1
);
private
Random
random
=
new
Random
(
1
);
private
String
[]
some
=
new
String
[]
{
null
,
""
,
"ABC"
,
"this is a medium sized string"
,
"1"
,
"2"
};
private
String
[]
some
=
new
String
[]
{
null
,
""
,
"ABC"
,
"this is a medium sized string"
,
"1"
,
"2"
};
private
volatile
boolean
stop
;
private
volatile
boolean
stop
;
private
boolean
returnNew
;
private
boolean
returnNew
;
private
boolean
useIntern
;
private
boolean
useIntern
;
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
...
@@ -43,39 +43,39 @@ public class TestStringCache extends TestBase {
...
@@ -43,39 +43,39 @@ public class TestStringCache extends TestBase {
testSingleThread
(
getSize
(
5000
,
20000
));
testSingleThread
(
getSize
(
5000
,
20000
));
testMultiThreads
();
testMultiThreads
();
}
}
String
randomString
()
{
String
randomString
()
{
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
String
s
=
some
[
random
.
nextInt
(
some
.
length
)];
String
s
=
some
[
random
.
nextInt
(
some
.
length
)];
if
(
s
!=
null
&&
random
.
nextBoolean
())
{
if
(
s
!=
null
&&
random
.
nextBoolean
())
{
s
=
new
String
(
s
);
s
=
new
String
(
s
);
}
}
return
s
;
return
s
;
}
else
{
}
else
{
int
len
=
random
.
nextBoolean
()
?
random
.
nextInt
(
1000
)
:
random
.
nextInt
(
10
);
int
len
=
random
.
nextBoolean
()
?
random
.
nextInt
(
1000
)
:
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
(
len
);
StringBuffer
buff
=
new
StringBuffer
(
len
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
random
.
nextInt
(
0xfff
));
buff
.
append
(
random
.
nextInt
(
0xfff
));
}
}
return
buff
.
toString
();
return
buff
.
toString
();
}
}
}
}
void
testString
()
{
void
testString
()
{
String
a
=
randomString
();
String
a
=
randomString
();
if
(
returnNew
)
{
if
(
returnNew
)
{
String
b
=
StringCache
.
getNew
(
a
);
String
b
=
StringCache
.
getNew
(
a
);
try
{
try
{
check
(
a
,
b
);
check
(
a
,
b
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
TestBase
.
logError
(
"error"
,
e
);
TestBase
.
logError
(
"error"
,
e
);
}
}
if
(
a
!=
null
&&
a
==
b
&&
a
.
length
()>
0
)
{
if
(
a
!=
null
&&
a
==
b
&&
a
.
length
()
>
0
)
{
throw
new
Error
(
"a="
+
System
.
identityHashCode
(
a
)
+
" b="
+
System
.
identityHashCode
(
b
));
throw
new
Error
(
"a="
+
System
.
identityHashCode
(
a
)
+
" b="
+
System
.
identityHashCode
(
b
));
}
}
}
else
{
}
else
{
String
b
;
String
b
;
if
(
useIntern
)
{
if
(
useIntern
)
{
b
=
a
==
null
?
null
:
a
.
intern
();
b
=
a
==
null
?
null
:
a
.
intern
();
}
else
{
}
else
{
b
=
StringCache
.
get
(
a
);
b
=
StringCache
.
get
(
a
);
...
@@ -87,9 +87,9 @@ public class TestStringCache extends TestBase {
...
@@ -87,9 +87,9 @@ public class TestStringCache extends TestBase {
}
}
}
}
}
}
private
void
testSingleThread
(
int
len
)
throws
Exception
{
private
void
testSingleThread
(
int
len
)
throws
Exception
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
testString
();
testString
();
}
}
}
}
...
@@ -97,23 +97,23 @@ public class TestStringCache extends TestBase {
...
@@ -97,23 +97,23 @@ public class TestStringCache extends TestBase {
private
void
testMultiThreads
()
throws
Exception
{
private
void
testMultiThreads
()
throws
Exception
{
int
threadCount
=
getSize
(
3
,
100
);
int
threadCount
=
getSize
(
3
,
100
);
Thread
[]
threads
=
new
Thread
[
threadCount
];
Thread
[]
threads
=
new
Thread
[
threadCount
];
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
Thread
t
=
new
Thread
(
new
Runnable
()
{
Thread
t
=
new
Thread
(
new
Runnable
()
{
public
void
run
()
{
public
void
run
()
{
while
(!
stop
)
{
while
(!
stop
)
{
testString
();
testString
();
}
}
}
}
});
});
threads
[
i
]
=
t
;
threads
[
i
]
=
t
;
}
}
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
threads
[
i
].
start
();
threads
[
i
].
start
();
}
}
int
wait
=
getSize
(
200
,
2000
);
int
wait
=
getSize
(
200
,
2000
);
Thread
.
sleep
(
wait
);
Thread
.
sleep
(
wait
);
stop
=
true
;
stop
=
true
;
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
threads
[
i
].
join
();
threads
[
i
].
join
();
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestStringUtils.java
浏览文件 @
f447a3e4
...
@@ -28,64 +28,46 @@ public class TestStringUtils extends TestBase {
...
@@ -28,64 +28,46 @@ public class TestStringUtils extends TestBase {
check
(
"Rand&Blue"
,
StringUtils
.
xmlText
(
"Rand&Blue"
));
check
(
"Rand&Blue"
,
StringUtils
.
xmlText
(
"Rand&Blue"
));
check
(
"<<[[[]]]>>"
,
StringUtils
.
xmlCData
(
"<<[[[]]]>>"
));
check
(
"<<[[[]]]>>"
,
StringUtils
.
xmlCData
(
"<<[[[]]]>>"
));
Date
dt
=
StringUtils
.
parseDateTime
(
"2001-02-03 04:05:06 GMT"
,
"yyyy-MM-dd HH:mm:ss z"
,
"en"
,
"GMT"
);
Date
dt
=
StringUtils
.
parseDateTime
(
"2001-02-03 04:05:06 GMT"
,
"yyyy-MM-dd HH:mm:ss z"
,
"en"
,
"GMT"
);
String
s
=
StringUtils
.
xmlStartDoc
()
+
String
s
=
StringUtils
.
xmlStartDoc
()
StringUtils
.
xmlComment
(
"Test Comment"
)
+
+
StringUtils
.
xmlComment
(
"Test Comment"
)
StringUtils
.
xmlNode
(
"rss"
,
StringUtils
.
xmlAttr
(
"version"
,
"2.0"
),
+
StringUtils
.
xmlNode
(
"rss"
,
StringUtils
.
xmlAttr
(
"version"
,
"2.0"
),
StringUtils
StringUtils
.
xmlComment
(
"Test Comment\nZeile2"
)
+
.
xmlComment
(
"Test Comment\nZeile2"
)
StringUtils
.
xmlNode
(
"channel"
,
null
,
+
StringUtils
.
xmlNode
(
"channel"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
"H2 Database Engine"
)
StringUtils
.
xmlNode
(
"title"
,
null
,
"H2 Database Engine"
)
+
+
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
+
+
StringUtils
.
xmlNode
(
"description"
,
null
,
"H2 Database Engine"
)
StringUtils
.
xmlNode
(
"description"
,
null
,
"H2 Database Engine"
)
+
+
StringUtils
.
xmlNode
(
"language"
,
null
,
"en-us"
)
StringUtils
.
xmlNode
(
"language"
,
null
,
"en-us"
)
+
+
StringUtils
.
xmlNode
(
"pubDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
StringUtils
.
xmlNode
(
"pubDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
StringUtils
.
xmlNode
(
"lastBuildDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
+
StringUtils
.
xmlNode
(
"lastBuildDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
StringUtils
.
xmlNode
(
"item"
,
null
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
StringUtils
.
xmlNode
(
"title"
,
null
,
"New Version 0.9.9.9.9"
)
+
+
StringUtils
.
xmlNode
(
"item"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
+
"New Version 0.9.9.9.9"
)
StringUtils
.
xmlNode
(
"description"
,
null
,
+
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
StringUtils
.
xmlCData
(
"\nNew Features\nTest\n"
)
+
StringUtils
.
xmlNode
(
"description"
,
null
,
StringUtils
)
.
xmlCData
(
"\nNew Features\nTest\n"
)))));
)
check
(
s
,
"<?xml version=\"1.0\"?>\n"
+
"<!-- Test Comment -->\n"
+
"<rss version=\"2.0\">\n"
+
" <!--\n"
)
+
" Test Comment\n"
+
" Zeile2\n"
+
" -->\n"
+
" <channel>\n"
);
+
" <title>H2 Database Engine</title>\n"
+
" <link>http://www.h2database.com</link>\n"
check
(
s
,
"<?xml version=\"1.0\"?>\n"
+
" <description>H2 Database Engine</description>\n"
+
" <language>en-us</language>\n"
+
"<!-- Test Comment -->\n"
+
" <pubDate>Sat, 3 Feb 2001 04:05:06 GMT</pubDate>\n"
+
"<rss version=\"2.0\">\n"
+
" <lastBuildDate>Sat, 3 Feb 2001 04:05:06 GMT</lastBuildDate>\n"
+
" <item>\n"
+
" <!--\n"
+
" <title>New Version 0.9.9.9.9</title>\n"
+
" Test Comment\n"
+
" <link>http://www.h2database.com</link>\n"
+
" <description>\n"
+
" Zeile2\n"
+
" <![CDATA[\n"
+
" New Features\n"
+
" Test\n"
+
" -->\n"
+
" ]]>\n"
+
" </description>\n"
+
" </item>\n"
+
" </channel>\n"
+
" <channel>\n"
+
"</rss>\n"
);
+
" <title>H2 Database Engine</title>\n"
+
" <link>http://www.h2database.com</link>\n"
+
" <description>H2 Database Engine</description>\n"
+
" <language>en-us</language>\n"
+
" <pubDate>Sat, 3 Feb 2001 04:05:06 GMT</pubDate>\n"
+
" <lastBuildDate>Sat, 3 Feb 2001 04:05:06 GMT</lastBuildDate>\n"
+
" <item>\n"
+
" <title>New Version 0.9.9.9.9</title>\n"
+
" <link>http://www.h2database.com</link>\n"
+
" <description>\n"
+
" <![CDATA[\n"
+
" New Features\n"
+
" Test\n"
+
" ]]>\n"
+
" </description>\n"
+
" </item>\n"
+
" </channel>\n"
+
"</rss>\n"
);
}
}
private
void
testURL
()
throws
Exception
{
private
void
testURL
()
throws
Exception
{
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
int
len
=
random
.
nextInt
(
10
);
int
len
=
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
();
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
}
else
{
}
else
{
buff
.
append
((
char
)
random
.
nextInt
(
255
));
buff
.
append
((
char
)
random
.
nextInt
(
255
));
}
}
}
}
String
a
=
buff
.
toString
();
String
a
=
buff
.
toString
();
...
@@ -99,14 +81,14 @@ public class TestStringUtils extends TestBase {
...
@@ -99,14 +81,14 @@ public class TestStringUtils extends TestBase {
private
void
testJavaString
()
throws
Exception
{
private
void
testJavaString
()
throws
Exception
{
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
int
len
=
random
.
nextInt
(
10
);
int
len
=
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
();
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
}
else
{
}
else
{
buff
.
append
((
char
)
random
.
nextInt
(
255
));
buff
.
append
((
char
)
random
.
nextInt
(
255
));
}
}
}
}
String
a
=
buff
.
toString
();
String
a
=
buff
.
toString
();
...
@@ -118,17 +100,17 @@ public class TestStringUtils extends TestBase {
...
@@ -118,17 +100,17 @@ public class TestStringUtils extends TestBase {
private
void
testSplit
()
throws
Exception
{
private
void
testSplit
()
throws
Exception
{
check
(
3
,
StringUtils
.
arraySplit
(
"ABC,DEF,G\\,HI"
,
','
,
false
).
length
);
check
(
3
,
StringUtils
.
arraySplit
(
"ABC,DEF,G\\,HI"
,
','
,
false
).
length
);
check
(
StringUtils
.
arrayCombine
(
new
String
[]
{
""
,
" "
,
","
},
','
),
", ,\\,"
);
check
(
StringUtils
.
arrayCombine
(
new
String
[]
{
""
,
" "
,
","
},
','
),
", ,\\,"
);
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
int
len
=
random
.
nextInt
(
10
);
int
len
=
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
();
StringBuffer
buff
=
new
StringBuffer
();
String
select
=
"abcd,"
;
String
select
=
"abcd,"
;
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
char
c
=
select
.
charAt
(
random
.
nextInt
(
select
.
length
()));
char
c
=
select
.
charAt
(
random
.
nextInt
(
select
.
length
()));
if
(
c
==
'a'
)
{
if
(
c
==
'a'
)
{
buff
.
append
(
"\\\\"
);
buff
.
append
(
"\\\\"
);
}
else
if
(
c
==
'b'
)
{
}
else
if
(
c
==
'b'
)
{
buff
.
append
(
"\\,"
);
buff
.
append
(
"\\,"
);
}
else
{
}
else
{
buff
.
append
(
c
);
buff
.
append
(
c
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
f447a3e4
...
@@ -4,15 +4,19 @@
...
@@ -4,15 +4,19 @@
*/
*/
package
org
.
h2
.
test
.
unit
;
package
org
.
h2
.
test
.
unit
;
import
java.sql.*
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Backup
;
import
org.h2.tools.Backup
;
import
org.h2.tools.Restore
;
import
org.h2.tools.Script
;
import
org.h2.tools.ChangePassword
;
import
org.h2.tools.ChangePassword
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.tools.Restore
;
import
org.h2.tools.RunScript
;
import
org.h2.tools.RunScript
;
import
org.h2.tools.Script
;
import
org.h2.tools.Server
;
import
org.h2.tools.Server
;
import
org.h2.util.Resources
;
import
org.h2.util.Resources
;
...
@@ -27,90 +31,94 @@ public class TestTools extends TestBase {
...
@@ -27,90 +31,94 @@ public class TestTools extends TestBase {
testScriptRunscript
();
testScriptRunscript
();
testBackupRestore
();
testBackupRestore
();
}
}
private
void
testManagementDb
()
throws
Exception
{
private
void
testManagementDb
()
throws
Exception
{
int
count
=
getSize
(
2
,
10
);
int
count
=
getSize
(
2
,
10
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
Server
server
=
Server
.
createTcpServer
(
new
String
[]{}).
start
();
Server
server
=
Server
.
createTcpServer
(
new
String
[]
{}).
start
();
server
.
stop
();
server
.
stop
();
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-tcpPassword"
,
"abc"
}).
start
();
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-tcpPassword"
,
"abc"
}).
start
();
server
.
stop
();
server
.
stop
();
}
}
}
}
private
void
testScriptRunscript
()
throws
Exception
{
private
void
testScriptRunscript
()
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
Class
.
forName
(
"org.h2.Driver"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
user
=
"sa"
,
password
=
"abc"
;
String
user
=
"sa"
,
password
=
"abc"
;
String
fileName
=
baseDir
+
"/b2.sql"
;
String
fileName
=
baseDir
+
"/b2.sql"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
Connection
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
conn
.
close
();
conn
.
close
();
Script
.
main
(
new
String
[]{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
"nodata"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
Script
.
main
(
new
String
[]
{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
DeleteDbFiles
.
main
(
new
String
[]{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
"nodata"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
RunScript
.
main
(
new
String
[]{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
RunScript
.
main
(
new
String
[]
{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
checkFalse
(
rs
.
next
());
checkFalse
(
rs
.
next
());
conn
.
close
();
conn
.
close
();
}
}
private
void
testBackupRestore
()
throws
Exception
{
private
void
testBackupRestore
()
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
Class
.
forName
(
"org.h2.Driver"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
user
=
"sa"
,
password
=
"abc"
;
String
user
=
"sa"
,
password
=
"abc"
;
String
fileName
=
baseDir
+
"/b2.zip"
;
String
fileName
=
baseDir
+
"/b2.zip"
;
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
Connection
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
Connection
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
conn
.
close
();
conn
.
close
();
Backup
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
Backup
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
Restore
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
Restore
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
check
(
rs
.
next
());
check
(
rs
.
next
());
checkFalse
(
rs
.
next
());
checkFalse
(
rs
.
next
());
conn
.
close
();
conn
.
close
();
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
}
}
private
void
testResourceGenerator
()
throws
Exception
{
private
void
testResourceGenerator
()
throws
Exception
{
Resources
.
main
(
new
String
[]
{
"."
});
Resources
.
main
(
new
String
[]
{
"."
});
}
}
private
void
testChangePassword
()
throws
Exception
{
private
void
testChangePassword
()
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
Class
.
forName
(
"org.h2.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=XTEA;STORAGE=TEXT"
,
"sa"
,
"abc 123"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=XTEA;STORAGE=TEXT"
,
"sa"
,
"abc 123"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
conn
.
close
();
conn
.
close
();
String
[]
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"XTEA"
,
"-decrypt"
,
"abc"
,
"-quiet"
};
String
[]
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"XTEA"
,
"-decrypt"
,
"abc"
,
"-quiet"
};
ChangePassword
.
main
(
args
);
ChangePassword
.
main
(
args
);
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"AES"
,
"-encrypt"
,
"def"
,
"-quiet"
};
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"AES"
,
"-encrypt"
,
"def"
,
"-quiet"
};
ChangePassword
.
main
(
args
);
ChangePassword
.
main
(
args
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=AES"
,
"sa"
,
"def 123"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=AES"
,
"sa"
,
"def 123"
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT * FROM TEST"
);
stat
.
execute
(
"SELECT * FROM TEST"
);
conn
.
close
();
conn
.
close
();
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
};
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
};
DeleteDbFiles
.
main
(
args
);
DeleteDbFiles
.
main
(
args
);
}
}
private
void
testServer
()
throws
Exception
{
private
void
testServer
()
throws
Exception
{
Connection
conn
;
Connection
conn
;
Server
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-ifExists"
,
"false"
,
"-baseDir"
,
baseDir
}).
start
();
Server
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-ifExists"
,
"false"
,
"-baseDir"
,
baseDir
}).
start
();
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
conn
.
close
();
conn
.
close
();
server
.
stop
();
server
.
stop
();
server
=
Server
.
createTcpServer
(
new
String
[]{
"-ifExists"
,
"true"
,
"-tcpPassword"
,
"abc"
,
"-baseDir"
,
baseDir
}).
start
();
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-ifExists"
,
"true"
,
"-tcpPassword"
,
"abc"
,
"-baseDir"
,
baseDir
}).
start
();
try
{
try
{
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test2"
,
"sa"
,
""
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test2"
,
"sa"
,
""
);
error
(
"should not be able to create new db"
);
error
(
"should not be able to create new db"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
checkNotGeneralException
(
e
);
}
}
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
...
@@ -118,7 +126,7 @@ public class TestTools extends TestBase {
...
@@ -118,7 +126,7 @@ public class TestTools extends TestBase {
try
{
try
{
Server
.
shutdownTcpServer
(
"tcp://localhost"
,
""
,
true
);
Server
.
shutdownTcpServer
(
"tcp://localhost"
,
""
,
true
);
error
(
"shouldn't work and should throw an exception"
);
error
(
"shouldn't work and should throw an exception"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
// expected
// expected
}
}
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
...
@@ -127,7 +135,7 @@ public class TestTools extends TestBase {
...
@@ -127,7 +135,7 @@ public class TestTools extends TestBase {
try
{
try
{
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
error
(
"server must have been closed"
);
error
(
"server must have been closed"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
checkNotGeneralException
(
e
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestValueHashMap.java
浏览文件 @
f447a3e4
...
@@ -19,29 +19,29 @@ import org.h2.value.Value;
...
@@ -19,29 +19,29 @@ import org.h2.value.Value;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueInt
;
public
class
TestValueHashMap
extends
TestBase
implements
DataHandler
{
public
class
TestValueHashMap
extends
TestBase
implements
DataHandler
{
CompareMode
compareMode
=
new
CompareMode
(
null
,
null
);
CompareMode
compareMode
=
new
CompareMode
(
null
,
null
);
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
ValueHashMap
map
=
new
ValueHashMap
(
this
);
ValueHashMap
map
=
new
ValueHashMap
(
this
);
HashMap
hash
=
new
HashMap
();
HashMap
hash
=
new
HashMap
();
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
Comparator
vc
=
new
Comparator
()
{
Comparator
vc
=
new
Comparator
()
{
public
int
compare
(
Object
o1
,
Object
o2
)
{
public
int
compare
(
Object
o1
,
Object
o2
)
{
Value
v1
=
(
Value
)
o1
;
Value
v1
=
(
Value
)
o1
;
Value
v2
=
(
Value
)
o2
;
Value
v2
=
(
Value
)
o2
;
try
{
try
{
return
v1
.
compareTo
(
v2
,
compareMode
);
return
v1
.
compareTo
(
v2
,
compareMode
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
throw
new
Error
(
e
);
throw
new
Error
(
e
);
}
}
}
}
};
};
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
int
op
=
random
.
nextInt
(
10
);
int
op
=
random
.
nextInt
(
10
);
Value
key
=
ValueInt
.
get
(
random
.
nextInt
(
100
));
Value
key
=
ValueInt
.
get
(
random
.
nextInt
(
100
));
Value
value
=
ValueInt
.
get
(
random
.
nextInt
(
100
));
Value
value
=
ValueInt
.
get
(
random
.
nextInt
(
100
));
switch
(
op
)
{
switch
(
op
)
{
case
0
:
case
0
:
map
.
put
(
key
,
value
);
map
.
put
(
key
,
value
);
hash
.
put
(
key
,
value
);
hash
.
put
(
key
,
value
);
...
@@ -53,7 +53,7 @@ public class TestValueHashMap extends TestBase implements DataHandler {
...
@@ -53,7 +53,7 @@ public class TestValueHashMap extends TestBase implements DataHandler {
case
2
:
case
2
:
Value
v1
=
(
Value
)
map
.
get
(
key
);
Value
v1
=
(
Value
)
map
.
get
(
key
);
Value
v2
=
(
Value
)
hash
.
get
(
key
);
Value
v2
=
(
Value
)
hash
.
get
(
key
);
check
((
v1
==
null
&&
v2
==
null
)
||
v1
.
compareEqual
(
v2
));
check
((
v1
==
null
&&
v2
==
null
)
||
v1
.
compareEqual
(
v2
));
break
;
break
;
case
3
:
{
case
3
:
{
ObjectArray
a1
=
map
.
keys
();
ObjectArray
a1
=
map
.
keys
();
...
@@ -61,8 +61,8 @@ public class TestValueHashMap extends TestBase implements DataHandler {
...
@@ -61,8 +61,8 @@ public class TestValueHashMap extends TestBase implements DataHandler {
check
(
a1
.
size
(),
a2
.
size
());
check
(
a1
.
size
(),
a2
.
size
());
a1
.
sort
(
vc
);
a1
.
sort
(
vc
);
a2
.
sort
(
vc
);
a2
.
sort
(
vc
);
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
}
}
break
;
break
;
}
}
...
@@ -72,8 +72,8 @@ public class TestValueHashMap extends TestBase implements DataHandler {
...
@@ -72,8 +72,8 @@ public class TestValueHashMap extends TestBase implements DataHandler {
check
(
a1
.
size
(),
a2
.
size
());
check
(
a1
.
size
(),
a2
.
size
());
a1
.
sort
(
vc
);
a1
.
sort
(
vc
);
a2
.
sort
(
vc
);
a2
.
sort
(
vc
);
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
}
}
break
;
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论