Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
00044424
提交
00044424
authored
18 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
7b59a66f
隐藏空白字符变更
内嵌
并排
正在显示
15 个修改的文件
包含
488 行增加
和
72 行删除
+488
-72
ant-build.properties
h2/ant-build.properties
+4
-4
build.xml
h2/build.xml
+0
-6
JdbcUtils.java
h2/src/main/org/h2/util/JdbcUtils.java
+8
-0
NetUtils.java
h2/src/main/org/h2/util/NetUtils.java
+8
-0
SmallLRUCache.java
h2/src/main/org/h2/util/SmallLRUCache.java
+19
-1
StringCache.java
h2/src/main/org/h2/util/StringCache.java
+1
-0
CompareMode.java
h2/src/main/org/h2/value/CompareMode.java
+30
-6
DataType.java
h2/src/main/org/h2/value/DataType.java
+15
-2
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+12
-40
testHalt.task
h2/src/test/org/h2/test/ftp/testHalt.task
+1
-0
TestMetaData.java
h2/src/test/org/h2/test/jdbc/TestMetaData.java
+7
-5
Column.java
h2/src/test/org/h2/test/synth/Column.java
+6
-5
TestHalt.java
h2/src/test/org/h2/test/synth/TestHalt.java
+267
-0
TestHaltApp.java
h2/src/test/org/h2/test/synth/TestHaltApp.java
+105
-0
Value.java
h2/src/test/org/h2/test/synth/Value.java
+5
-3
没有找到文件。
h2/ant-build.properties
浏览文件 @
00044424
# properties for build.xml
#Mon Jan 15 18:29:59 CET 2007
jdk
=
1.4
version.name.maven
=
1.0.20061217
javac
=
javac
javac
=
javac
benchmark.drivers.dir
=
D:/data/java
benchmark.drivers.dir
=
D
\:
/data/java
version.name.maven
=
1.0.20070116
jdk
=
1.4
This diff is collapsed.
Click to expand it.
h2/build.xml
浏览文件 @
00044424
<project
name=
"h2"
default=
"all"
basedir=
"."
>
<project
name=
"h2"
default=
"all"
basedir=
"."
>
<property
file=
"ant-build.properties"
/>
<property
file=
"ant-build.properties"
/>
<!--
<property name="version.name.maven" value="1.0.20061217"/>
<property name="jdk" value="1.4"/>
<property name="javac" value="javac"/>
-->
<path
id=
"benchmark.drivers.path"
>
<path
id=
"benchmark.drivers.path"
>
<!-- jar files required by the benchmark -->
<!-- jar files required by the benchmark -->
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/JdbcUtils.java
浏览文件 @
00044424
...
@@ -40,5 +40,13 @@ public class JdbcUtils {
...
@@ -40,5 +40,13 @@ public class JdbcUtils {
}
}
}
}
}
}
public
static
ResultSet
getGeneratedKeys
(
Statement
stat
)
throws
SQLException
{
ResultSet
rs
=
null
;
//#ifdef JDK14
rs
=
stat
.
getGeneratedKeys
();
//#endif
return
rs
;
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/NetUtils.java
浏览文件 @
00044424
...
@@ -56,4 +56,12 @@ public class NetUtils {
...
@@ -56,4 +56,12 @@ public class NetUtils {
}
}
}
}
public
static
boolean
isLoopbackAddress
(
Socket
socket
)
{
boolean
result
=
true
;
//#ifdef JDK14
result
=
socket
.
getInetAddress
().
isLoopbackAddress
();
//#endif
return
result
;
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/SmallLRUCache.java
浏览文件 @
00044424
...
@@ -4,10 +4,26 @@
...
@@ -4,10 +4,26 @@
*/
*/
package
org
.
h2
.
util
;
package
org
.
h2
.
util
;
//#ifdef JDK14
import
java.util.LinkedHashMap
;
import
java.util.LinkedHashMap
;
//#endif
//#ifdef JDK13
/*
import java.util.HashMap;
*/
//#endif
import
java.util.Map
;
import
java.util.Map
;
public
class
SmallLRUCache
extends
LinkedHashMap
{
public
class
SmallLRUCache
//#ifdef JDK14
extends
LinkedHashMap
//#endif
//#ifdef JDK13
/*
extends HashMap
*/
//#endif
{
private
static
final
long
serialVersionUID
=
3643268440910181829L
;
private
static
final
long
serialVersionUID
=
3643268440910181829L
;
private
int
size
;
private
int
size
;
...
@@ -16,7 +32,9 @@ public class SmallLRUCache extends LinkedHashMap {
...
@@ -16,7 +32,9 @@ public class SmallLRUCache extends LinkedHashMap {
this
.
size
=
size
;
this
.
size
=
size
;
}
}
//#ifdef JDK14
protected
boolean
removeEldestEntry
(
Map
.
Entry
eldest
)
{
protected
boolean
removeEldestEntry
(
Map
.
Entry
eldest
)
{
return
size
()
>
size
;
return
size
()
>
size
;
}
}
//#endif
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/StringCache.java
浏览文件 @
00044424
...
@@ -95,6 +95,7 @@ public class StringCache {
...
@@ -95,6 +95,7 @@ public class StringCache {
return
cached
;
return
cached
;
}
}
}
}
// create a new object that is not shared (to avoid out of memory if it is a substring of a big String)
s
=
new
String
(
s
);
s
=
new
String
(
s
);
cache
[
index
]
=
s
;
cache
[
index
]
=
s
;
return
s
;
return
s
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/CompareMode.java
浏览文件 @
00044424
...
@@ -43,16 +43,40 @@ public class CompareMode {
...
@@ -43,16 +43,40 @@ public class CompareMode {
name
=
StringUtils
.
toUpperEnglish
(
name
.
trim
().
replace
(
' '
,
'_'
));
name
=
StringUtils
.
toUpperEnglish
(
name
.
trim
().
replace
(
' '
,
'_'
));
return
name
;
return
name
;
}
}
private
static
boolean
compareLocaleNames
(
Locale
locale
,
String
name
)
{
return
name
.
equalsIgnoreCase
(
locale
.
toString
())
||
name
.
equalsIgnoreCase
(
getName
(
locale
));
}
public
static
Collator
getCollator
(
String
name
)
{
public
static
Collator
getCollator
(
String
name
)
{
Locale
[]
locales
=
Collator
.
getAvailableLocales
();
Collator
result
=
null
;
for
(
int
i
=
0
;
i
<
locales
.
length
;
i
++)
{
if
(
name
.
length
()
==
2
)
{
Locale
locale
=
locales
[
i
];
Locale
locale
=
new
Locale
(
name
.
toLowerCase
());
if
(
name
.
equalsIgnoreCase
(
locale
.
toString
())
||
name
.
equalsIgnoreCase
(
getName
(
locale
)))
{
if
(
compareLocaleNames
(
locale
,
name
))
{
return
Collator
.
getInstance
(
locale
);
result
=
Collator
.
getInstance
(
locale
);
}
}
else
if
(
name
.
length
()
==
5
)
{
int
idx
=
name
.
indexOf
(
'_'
);
if
(
idx
>=
0
)
{
String
language
=
name
.
substring
(
0
,
idx
).
toLowerCase
();
String
country
=
name
.
substring
(
idx
+
1
);
Locale
locale
=
new
Locale
(
language
,
country
);
if
(
compareLocaleNames
(
locale
,
name
))
{
result
=
Collator
.
getInstance
(
locale
);
}
}
}
if
(
result
==
null
)
{
Locale
[]
locales
=
Collator
.
getAvailableLocales
();
for
(
int
i
=
0
;
i
<
locales
.
length
;
i
++)
{
Locale
locale
=
locales
[
i
];
if
(
compareLocaleNames
(
locale
,
name
))
{
result
=
Collator
.
getInstance
(
locale
);
break
;
}
}
}
}
}
return
null
;
return
result
;
}
}
public
String
getName
()
{
public
String
getName
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/DataType.java
浏览文件 @
00044424
...
@@ -50,13 +50,26 @@ public class DataType {
...
@@ -50,13 +50,26 @@ public class DataType {
public
long
defaultPrecision
;
public
long
defaultPrecision
;
public
int
defaultScale
;
public
int
defaultScale
;
public
boolean
hidden
;
public
boolean
hidden
;
// JDK 1.3 compatibility: Types.BOOLEAN
public
static
final
int
TYPE_BOOLEAN
=
16
;
// JDK 1.3 compatibility: Types.DATALINK
public
static
final
int
TYPE_DATALINK
=
70
;
static
{
static
{
//#ifdef JDK14
if
(
TYPE_BOOLEAN
!=
Types
.
BOOLEAN
)
{
new
Exception
(
"Types.BOOLEAN: "
+
Types
.
BOOLEAN
).
printStackTrace
();
}
if
(
TYPE_DATALINK
!=
Types
.
DATALINK
)
{
new
Exception
(
"Types.DATALINK: "
+
Types
.
DATALINK
).
printStackTrace
();
}
//#endif
add
(
Value
.
NULL
,
Types
.
NULL
,
"Null"
,
add
(
Value
.
NULL
,
Types
.
NULL
,
"Null"
,
new
DataType
(),
new
DataType
(),
new
String
[]{
"NULL"
}
new
String
[]{
"NULL"
}
);
);
add
(
Value
.
BOOLEAN
,
Types
.
BOOLEAN
,
"Boolean"
,
add
(
Value
.
BOOLEAN
,
DataType
.
TYPE_
BOOLEAN
,
"Boolean"
,
createDecimal
(
ValueBoolean
.
PRECISION
,
ValueBoolean
.
PRECISION
,
0
,
false
,
false
),
createDecimal
(
ValueBoolean
.
PRECISION
,
ValueBoolean
.
PRECISION
,
0
,
false
,
false
),
new
String
[]{
"BOOLEAN"
,
"BIT"
,
"BOOL"
}
new
String
[]{
"BOOLEAN"
,
"BIT"
,
"BOOL"
}
);
);
...
@@ -423,7 +436,7 @@ public class DataType {
...
@@ -423,7 +436,7 @@ public class DataType {
case
Types
.
DECIMAL
:
case
Types
.
DECIMAL
:
return
Value
.
DECIMAL
;
return
Value
.
DECIMAL
;
case
Types
.
BIT
:
case
Types
.
BIT
:
case
Types
.
BOOLEAN
:
case
DataType
.
TYPE_
BOOLEAN
:
return
Value
.
BOOLEAN
;
return
Value
.
BOOLEAN
;
case
Types
.
INTEGER
:
case
Types
.
INTEGER
:
return
Value
.
INT
;
return
Value
.
INT
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
00044424
...
@@ -13,6 +13,7 @@ import org.h2.test.db.*;
...
@@ -13,6 +13,7 @@ import org.h2.test.db.*;
import
org.h2.test.server.TestNestedLoop
;
import
org.h2.test.server.TestNestedLoop
;
import
org.h2.test.synth.TestBtreeIndex
;
import
org.h2.test.synth.TestBtreeIndex
;
import
org.h2.test.synth.TestCrashAPI
;
import
org.h2.test.synth.TestCrashAPI
;
import
org.h2.test.synth.TestHaltApp
;
import
org.h2.test.synth.TestJoin
;
import
org.h2.test.synth.TestJoin
;
import
org.h2.test.synth.TestKill
;
import
org.h2.test.synth.TestKill
;
import
org.h2.test.synth.TestMulti
;
import
org.h2.test.synth.TestMulti
;
...
@@ -85,34 +86,16 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
...
@@ -85,34 +86,16 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
TestAll
test
=
new
TestAll
();
TestAll
test
=
new
TestAll
();
test
.
printSystem
();
test
.
printSystem
();
// synth.TestHaltReconnect
// NULL || 'X' should probably return null by default
// change default to read committed transaction isolation
// Hot backup (incremental backup, online backup): backup data, log, index? files
// Cluster: hot deploy (adding a node on runtime)
// system property for base directory (h2.baseDir)
// reclaim empty space without closing the database
// SELECT ... FROM TA, TB, TC WHERE TC.COL3 = TA.COL1 AND TC.COL3=TB.COL2 AND TC.COL4 = 1
// The query implies TA.COL1 = TB.COL2 but does not explicitly set this condition.
// Hot backup (incremental backup, online backup): backup data, log, index? files
// "trace.db" is created in the current directory
// Cluster: hot deploy (adding a node on runtime)
// dataSource.setLogWriter() seems to have no effect?
// add TPC-B style benchmark: download/tpcb_current.pdf
// delay reading the row if data is not required
// document compensations
// eliminate undo log records if stored on disk (just one pointer per block, not per record)
// release checklist:
// add to freshmeat
// add to http://code.google.com/p/h2database/downloads/list
// SELECT ... FROM TA, TB, TC WHERE TC.COL3 = TA.COL1 AND TC.COL3=TB.COL2 AND TC.COL4 = 1
// ...
// The query implies TA.COL1 = TB.COL2 but does not explicitly set this condition.
// analyze hibernate read committed tests that fail
// when? server only? special test with TestAll (only this)
// java.lang.Exception: query was too quick; result: 0 time:1002
// at org.h2.test.TestBase.logError(TestBase.java:219)
// at org.h2.test.db.TestCases$1.run(TestCases.java:158)
// at java.lang.Thread.run(Unknown Source)
// DROP TABLE TEST;
// DROP TABLE TEST;
// CREATE TABLE TEST(C CHAR(10));
// CREATE TABLE TEST(C CHAR(10));
...
@@ -126,10 +109,6 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
...
@@ -126,10 +109,6 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
// -- Oracle, Derby: 10, 11
// -- Oracle, Derby: 10, 11
// -- PostgreSQL, H2, HSQLDB: 1, 2
// -- PostgreSQL, H2, HSQLDB: 1, 2
// maybe use system property for base directory (h2.baseDir)
// feature request: user defined aggregate functions
// auto-upgrade application:
// auto-upgrade application:
// check if new version is available
// check if new version is available
// (option: digital signature)
// (option: digital signature)
...
@@ -143,19 +122,10 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
...
@@ -143,19 +122,10 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
// task to download new version from another HTTP / HTTPS / FTP server
// task to download new version from another HTTP / HTTPS / FTP server
// multi-task
// multi-task
// write a test that calls Runtime.halt at more or less random places (extend TestLob)
// OSGi Bundle (see Forum)
// test with PostgreSQL Version 8.2
// test with PostgreSQL Version 8.2
// http://dev.helma.org/Wiki/RhinoLoader
// http://dev.helma.org/Wiki/RhinoLoader
// Test Hibernate / read committed transaction isolation:
// Data records retrieved by a query are not prevented from modification by some other transaction.
// Non-repeatable reads may occur, meaning data retrieved in a SELECT statement may be modified
// by some other transaction when it commits. In this isolation level, read locks are not acquired on selected data.
// test with garbage at the end of the log file (must be consistently detected as such)
// test with garbage at the end of the log file (must be consistently detected as such)
// test LIKE: compare against other databases
// test LIKE: compare against other databases
// TestRandomSQL is too random; most statements fails
// TestRandomSQL is too random; most statements fails
...
@@ -184,6 +154,8 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
...
@@ -184,6 +154,8 @@ java -Xmx512m -Xrunhprof:cpu=samples,depth=8 org.h2.tools.RunScript -url jdbc:h2
test
.
testCodeCoverage
();
test
.
testCodeCoverage
();
}
else
if
(
"multiThread"
.
equals
(
args
[
0
]))
{
}
else
if
(
"multiThread"
.
equals
(
args
[
0
]))
{
new
TestMulti
().
runTest
(
test
);
new
TestMulti
().
runTest
(
test
);
}
else
if
(
"halt"
.
equals
(
args
[
0
]))
{
new
TestHaltApp
().
runTest
(
test
);
}
}
}
else
{
}
else
{
test
.
runTests
();
test
.
runTests
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/ftp/testHalt.task
0 → 100644
浏览文件 @
00044424
command=java org.h2.test.TestAll halt
\ No newline at end of file
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestMetaData.java
浏览文件 @
00044424
...
@@ -8,6 +8,7 @@ import java.sql.*;
...
@@ -8,6 +8,7 @@ import java.sql.*;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.value.DataType
;
public
class
TestMetaData
extends
TestBase
{
public
class
TestMetaData
extends
TestBase
{
...
@@ -590,7 +591,7 @@ public class TestMetaData extends TestBase {
...
@@ -590,7 +591,7 @@ public class TestMetaData extends TestBase {
"TABLE_NAME"
,
"NON_UNIQUE"
,
"INDEX_QUALIFIER"
,
"INDEX_NAME"
,
"TABLE_NAME"
,
"NON_UNIQUE"
,
"INDEX_QUALIFIER"
,
"INDEX_NAME"
,
"TYPE"
,
"ORDINAL_POSITION"
,
"COLUMN_NAME"
,
"ASC_OR_DESC"
,
"TYPE"
,
"ORDINAL_POSITION"
,
"COLUMN_NAME"
,
"ASC_OR_DESC"
,
"CARDINALITY"
,
"PAGES"
,
"FILTER_CONDITION"
},
new
int
[]
{
"CARDINALITY"
,
"PAGES"
,
"FILTER_CONDITION"
},
new
int
[]
{
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
BOOLEAN
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
DataType
.
TYPE_
BOOLEAN
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
SMALLINT
,
Types
.
SMALLINT
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
SMALLINT
,
Types
.
SMALLINT
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
INTEGER
,
Types
.
INTEGER
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
INTEGER
,
Types
.
INTEGER
,
Types
.
VARCHAR
},
null
,
null
);
Types
.
VARCHAR
},
null
,
null
);
...
@@ -614,7 +615,7 @@ public class TestMetaData extends TestBase {
...
@@ -614,7 +615,7 @@ public class TestMetaData extends TestBase {
"TABLE_NAME"
,
"NON_UNIQUE"
,
"INDEX_QUALIFIER"
,
"INDEX_NAME"
,
"TABLE_NAME"
,
"NON_UNIQUE"
,
"INDEX_QUALIFIER"
,
"INDEX_NAME"
,
"TYPE"
,
"ORDINAL_POSITION"
,
"COLUMN_NAME"
,
"ASC_OR_DESC"
,
"TYPE"
,
"ORDINAL_POSITION"
,
"COLUMN_NAME"
,
"ASC_OR_DESC"
,
"CARDINALITY"
,
"PAGES"
,
"FILTER_CONDITION"
},
new
int
[]
{
"CARDINALITY"
,
"PAGES"
,
"FILTER_CONDITION"
},
new
int
[]
{
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
BOOLEAN
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
DataType
.
TYPE_
BOOLEAN
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
SMALLINT
,
Types
.
SMALLINT
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
SMALLINT
,
Types
.
SMALLINT
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
INTEGER
,
Types
.
INTEGER
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
INTEGER
,
Types
.
INTEGER
,
Types
.
VARCHAR
},
null
,
null
);
Types
.
VARCHAR
},
null
,
null
);
...
@@ -772,7 +773,8 @@ public class TestMetaData extends TestBase {
...
@@ -772,7 +773,8 @@ public class TestMetaData extends TestBase {
rs
=
meta
.
getSchemas
();
rs
=
meta
.
getSchemas
();
testResultSetMeta
(
rs
,
3
,
new
String
[]
{
"TABLE_SCHEM"
,
"TABLE_CATALOG"
,
"IS_DEFAULT"
},
new
int
[]
{
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
BOOLEAN
},
null
,
null
);
testResultSetMeta
(
rs
,
3
,
new
String
[]
{
"TABLE_SCHEM"
,
"TABLE_CATALOG"
,
"IS_DEFAULT"
},
new
int
[]
{
Types
.
VARCHAR
,
Types
.
VARCHAR
,
DataType
.
TYPE_BOOLEAN
},
null
,
null
);
check
(
rs
.
next
());
check
(
rs
.
next
());
check
(
rs
.
getString
(
1
),
"INFORMATION_SCHEMA"
);
check
(
rs
.
getString
(
1
),
"INFORMATION_SCHEMA"
);
check
(
rs
.
next
());
check
(
rs
.
next
());
...
@@ -798,8 +800,8 @@ public class TestMetaData extends TestBase {
...
@@ -798,8 +800,8 @@ public class TestMetaData extends TestBase {
},
},
new
int
[]{
new
int
[]{
Types
.
VARCHAR
,
Types
.
SMALLINT
,
Types
.
INTEGER
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
SMALLINT
,
Types
.
INTEGER
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
SMALLINT
,
Types
.
BOOLEAN
,
Types
.
VARCHAR
,
Types
.
VARCHAR
,
Types
.
SMALLINT
,
DataType
.
TYPE_
BOOLEAN
,
Types
.
SMALLINT
,
Types
.
BOOLEAN
,
Types
.
BOOLEAN
,
Types
.
BOOLEAN
,
Types
.
SMALLINT
,
DataType
.
TYPE_BOOLEAN
,
DataType
.
TYPE_BOOLEAN
,
DataType
.
TYPE_
BOOLEAN
,
Types
.
VARCHAR
,
Types
.
SMALLINT
,
Types
.
SMALLINT
,
Types
.
SMALLINT
,
Types
.
VARCHAR
,
Types
.
SMALLINT
,
Types
.
SMALLINT
,
Types
.
SMALLINT
,
Types
.
INTEGER
,
Types
.
INTEGER
Types
.
INTEGER
,
Types
.
INTEGER
}
,
null
,
null
}
,
null
,
null
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/Column.java
浏览文件 @
00044424
...
@@ -6,6 +6,8 @@ package org.h2.test.synth;
...
@@ -6,6 +6,8 @@ package org.h2.test.synth;
import
java.sql.*
;
import
java.sql.*
;
import
org.h2.value.DataType
;
class
Column
{
class
Column
{
private
TestSynth
config
;
private
TestSynth
config
;
private
String
name
;
private
String
name
;
...
@@ -23,7 +25,7 @@ class Column {
...
@@ -23,7 +25,7 @@ class Column {
Types
.
DATE
,
Types
.
DATE
,
Types
.
TIME
,
Types
.
TIME
,
Types
.
TIMESTAMP
,
Types
.
TIMESTAMP
,
Types
.
BOOLEAN
,
DataType
.
TYPE_
BOOLEAN
,
Types
.
BINARY
,
Types
.
BINARY
,
Types
.
VARBINARY
,
Types
.
VARBINARY
,
Types
.
CLOB
,
Types
.
CLOB
,
...
@@ -32,7 +34,6 @@ class Column {
...
@@ -32,7 +34,6 @@ class Column {
Types
.
BIGINT
,
Types
.
BIGINT
,
Types
.
TIMESTAMP
,
Types
.
TIMESTAMP
,
Types
.
BIT
,
Types
.
BIT
,
Types
.
BOOLEAN
,
};
};
Column
(
TestSynth
config
)
{
Column
(
TestSynth
config
)
{
...
@@ -66,7 +67,7 @@ class Column {
...
@@ -66,7 +67,7 @@ class Column {
case
Types
.
REAL
:
case
Types
.
REAL
:
case
Types
.
OTHER
:
case
Types
.
OTHER
:
case
Types
.
BIT
:
case
Types
.
BIT
:
case
Types
.
BOOLEAN
:
case
DataType
.
TYPE_
BOOLEAN
:
break
;
break
;
default
:
default
:
throw
new
Error
(
"type="
+
type
);
throw
new
Error
(
"type="
+
type
);
...
@@ -90,7 +91,7 @@ class Column {
...
@@ -90,7 +91,7 @@ class Column {
case
Types
.
TIMESTAMP
:
case
Types
.
TIMESTAMP
:
case
Types
.
DOUBLE
:
case
Types
.
DOUBLE
:
case
Types
.
BIGINT
:
case
Types
.
BIGINT
:
case
Types
.
BOOLEAN
:
case
DataType
.
TYPE_
BOOLEAN
:
case
Types
.
BIT
:
case
Types
.
BIT
:
return
true
;
return
true
;
case
Types
.
BINARY
:
case
Types
.
BINARY
:
...
@@ -149,7 +150,7 @@ class Column {
...
@@ -149,7 +150,7 @@ class Column {
return
"DOUBLE"
;
return
"DOUBLE"
;
case
Types
.
BIGINT
:
case
Types
.
BIGINT
:
return
"BIGINT"
;
return
"BIGINT"
;
case
Types
.
BOOLEAN
:
case
DataType
.
TYPE_
BOOLEAN
:
case
Types
.
BIT
:
case
Types
.
BIT
:
return
"BOOLEAN"
;
return
"BOOLEAN"
;
default
:
default
:
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/TestHalt.java
0 → 100644
浏览文件 @
00044424
package
org
.
h2
.
test
.
synth
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.PrintWriter
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.LinkedList
;
import
java.util.Random
;
import
org.h2.test.TestBase
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.util.IOUtils
;
public
abstract
class
TestHalt
extends
TestBase
{
private
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"MM-dd HH:mm:ss "
);
protected
static
final
int
OP_INSERT
=
1
,
OP_DELETE
=
2
,
OP_UPDATE
=
4
,
OP_SELECT
=
8
;
protected
static
final
int
FLAG_NODELAY
=
1
,
FLAG_LOBS
=
2
;
protected
int
operations
,
flags
,
value
;
protected
Connection
conn
;
protected
Random
random
=
new
Random
();
abstract
void
testInit
()
throws
Exception
;
abstract
void
testCheckAfterCrash
()
throws
Exception
;
abstract
void
testWaitAfterAppStart
()
throws
Exception
;
abstract
void
appStart
()
throws
Exception
;
abstract
void
appRun
()
throws
Exception
;
public
void
test
()
throws
Exception
{
for
(
int
i
=
0
;;
i
++)
{
operations
=
OP_INSERT
|
i
;
flags
=
i
>>
4
;
// flags = FLAG_NODELAY | FLAG_LOBS;
try
{
runTest
();
}
catch
(
Throwable
t
)
{
System
.
out
.
println
(
"Error: "
+
t
);
t
.
printStackTrace
();
}
}
}
Connection
getConnection
()
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
return
DriverManager
.
getConnection
(
"jdbc:h2:test"
,
"sa"
,
"sa"
);
}
protected
void
start
(
String
[]
args
)
throws
Exception
{
if
(
args
.
length
==
0
)
{
runTest
();
}
else
{
operations
=
Integer
.
parseInt
(
args
[
0
]);
flags
=
Integer
.
parseInt
(
args
[
1
]);
value
=
Integer
.
parseInt
(
args
[
2
]);
runRandom
();
}
}
private
void
runRandom
()
throws
Exception
{
log
(
"connecting"
,
null
);
connect
();
try
{
log
(
"connected, operations:"
+
operations
+
" flags:"
+
flags
+
" value:"
+
value
,
null
);
appStart
();
System
.
out
.
println
(
"READY"
);
System
.
out
.
println
(
"READY"
);
System
.
out
.
println
(
"READY"
);
appRun
();
log
(
"done"
,
null
);
}
catch
(
Exception
e
)
{
log
(
"run"
,
e
);
}
disconnect
();
}
private
void
connect
()
throws
Exception
{
try
{
conn
=
getConnection
();
}
catch
(
Exception
e
)
{
log
(
"connect"
,
e
);
e
.
printStackTrace
();
throw
e
;
}
}
protected
void
log
(
String
s
,
Exception
e
)
{
FileWriter
writer
=
null
;
try
{
writer
=
new
FileWriter
(
"log.txt"
,
true
);
PrintWriter
w
=
new
PrintWriter
(
writer
);
s
=
dateFormat
.
format
(
new
Date
())
+
": "
+
s
;
w
.
println
(
s
);
if
(
e
!=
null
)
{
e
.
printStackTrace
(
w
);
}
}
catch
(
IOException
e2
)
{
e2
.
printStackTrace
();
}
finally
{
IOUtils
.
closeSilently
(
writer
);
}
}
private
void
runTest
()
throws
Exception
{
DeleteDbFiles
.
execute
(
null
,
"test"
,
true
);
new
File
(
"log.txt"
).
delete
();
connect
();
testInit
();
disconnect
();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
// int operations = OP_INSERT;
// OP_DELETE = 1, OP_UPDATE = 2, OP_SELECT = 4;
// int flags = FLAG_NODELAY;
// FLAG_NODELAY = 1, FLAG_AUTOCOMMIT = 2, FLAG_SMALLCACHE = 4;
int
value
=
random
.
nextInt
(
1000
);
// for Derby and HSQLDB
// String classPath = "-cp .;D:/data/java/hsqldb.jar;D:/data/java/derby.jar";
String
classPath
=
""
;
String
command
=
"java "
+
classPath
+
" "
+
getClass
().
getName
()
+
" "
+
operations
+
" "
+
flags
+
" "
+
value
;
log
(
"start: "
+
command
);
Process
p
=
Runtime
.
getRuntime
().
exec
(
command
);
InputStream
in
=
p
.
getInputStream
();
OutputCatcher
catcher
=
new
OutputCatcher
(
in
);
catcher
.
start
();
String
s
=
catcher
.
readLine
(
5000
);
if
(
s
==
null
)
{
throw
new
IOException
(
"No reply from process"
);
}
else
if
(
s
.
startsWith
(
"READY"
))
{
log
(
"got reply: "
+
s
);
}
testWaitAfterAppStart
();
p
.
destroy
();
connect
();
testCheckAfterCrash
();
disconnect
();
}
}
protected
void
disconnect
()
{
try
{
conn
.
close
();
}
catch
(
Exception
e
)
{
log
(
"disconnect"
,
e
);
}
}
private
void
log
(
String
string
)
{
System
.
out
.
println
(
string
);
}
private
static
class
OutputCatcher
extends
Thread
{
private
InputStream
in
;
private
LinkedList
list
=
new
LinkedList
();
OutputCatcher
(
InputStream
in
)
{
this
.
in
=
in
;
}
private
String
readLine
(
long
wait
)
{
long
start
=
System
.
currentTimeMillis
();
while
(
true
)
{
synchronized
(
list
)
{
if
(
list
.
size
()
>
0
)
{
return
(
String
)
list
.
removeFirst
();
}
try
{
list
.
wait
(
wait
);
}
catch
(
InterruptedException
e
)
{
}
long
time
=
System
.
currentTimeMillis
()
-
start
;
if
(
time
>=
wait
)
{
return
null
;
}
}
}
}
public
void
run
()
{
StringBuffer
buff
=
new
StringBuffer
();
while
(
true
)
{
try
{
int
x
=
in
.
read
();
if
(
x
<
0
)
{
break
;
}
if
(
x
<
' '
)
{
if
(
buff
.
length
()
>
0
)
{
String
s
=
buff
.
toString
();
buff
.
setLength
(
0
);
synchronized
(
list
)
{
list
.
add
(
s
);
list
.
notifyAll
();
}
}
}
else
{
buff
.
append
((
char
)
x
);
}
}
catch
(
IOException
e
)
{
// ignore
}
}
IOUtils
.
closeSilently
(
in
);
}
}
public
Connection
getConnectionHSQLDB
()
throws
Exception
{
File
lock
=
new
File
(
"test.lck"
);
while
(
lock
.
exists
())
{
lock
.
delete
();
System
.
gc
();
}
Class
.
forName
(
"org.hsqldb.jdbcDriver"
);
return
DriverManager
.
getConnection
(
"jdbc:hsqldb:test"
,
"sa"
,
""
);
}
public
Connection
getConnectionDerby
()
throws
Exception
{
File
lock
=
new
File
(
"test3/db.lck"
);
while
(
lock
.
exists
())
{
lock
.
delete
();
System
.
gc
();
}
Class
.
forName
(
"org.apache.derby.jdbc.EmbeddedDriver"
).
newInstance
();
try
{
return
DriverManager
.
getConnection
(
"jdbc:derby:test3;create=true"
,
"sa"
,
"sa"
);
}
catch
(
SQLException
e
)
{
Exception
e2
=
e
;
do
{
e
.
printStackTrace
();
e
=
e
.
getNextException
();
}
while
(
e
!=
null
);
throw
e2
;
}
}
public
void
disconnectHSQLDB
()
{
try
{
conn
.
createStatement
().
execute
(
"SHUTDOWN"
);
}
catch
(
Exception
e
)
{
// ignore
}
// super.disconnect();
}
public
void
disconnectDerby
()
{
// super.disconnect();
try
{
Class
.
forName
(
"org.apache.derby.jdbc.EmbeddedDriver"
);
DriverManager
.
getConnection
(
"jdbc:derby:;shutdown=true"
,
"sa"
,
"sa"
);
}
catch
(
Exception
e
)
{
// ignore
}
}
protected
String
getRandomString
(
int
len
)
{
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
'a'
+
random
.
nextInt
(
20
));
}
return
buff
.
toString
();
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/TestHaltApp.java
0 → 100644
浏览文件 @
00044424
package
org
.
h2
.
test
.
synth
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
TestHaltApp
extends
TestHalt
{
private
int
rowCount
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
TestHaltApp
().
start
(
args
);
}
protected
void
testInit
()
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"DROP TABLE TEST"
);
}
catch
(
SQLException
e
)
{
// ignore
}
// stat.execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR(255))");
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
+
i
);
stat
.
execute
(
"CREATE TABLE TEST"
+
i
+
"(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
}
for
(
int
i
=
0
;
i
<
20
;
i
+=
2
)
{
stat
.
execute
(
"DROP TABLE TEST"
+
i
);
}
stat
.
execute
(
"CREATE TABLE TEST(ID BIGINT GENERATED BY DEFAULT AS IDENTITY, NAME VARCHAR(255), DATA CLOB)"
);
}
protected
void
testWaitAfterAppStart
()
throws
Exception
{
int
sleep
=
10
+
random
.
nextInt
(
300
);
Thread
.
sleep
(
sleep
);
}
protected
void
testCheckAfterCrash
()
throws
Exception
{
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST"
);
rs
.
next
();
int
count
=
rs
.
getInt
(
1
);
System
.
out
.
println
(
"count: "
+
count
);
if
(
count
%
2
==
1
)
{
throw
new
Exception
(
"Unexpected odd row count"
);
}
}
protected
void
appStart
()
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
if
((
flags
&
FLAG_NODELAY
)
!=
0
)
{
stat
.
execute
(
"SET WRITE_DELAY 0"
);
stat
.
execute
(
"SET MAX_LOG_SIZE 1"
);
}
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST"
);
rs
.
next
();
rowCount
=
rs
.
getInt
(
1
);
log
(
"rows: "
+
rowCount
,
null
);
}
protected
void
appRun
()
throws
SQLException
{
conn
.
setAutoCommit
(
false
);
int
rows
=
10000
+
value
;
PreparedStatement
prepInsert
=
conn
.
prepareStatement
(
"INSERT INTO TEST(NAME, DATA) VALUES('Hello World', ?)"
);
PreparedStatement
prepUpdate
=
conn
.
prepareStatement
(
"UPDATE TEST SET NAME = 'Hallo Welt', DATA = ? WHERE ID = ?"
);
for
(
int
i
=
0
;
i
<
rows
;
i
++)
{
Statement
stat
=
conn
.
createStatement
();
if
((
operations
&
OP_INSERT
)
!=
0
)
{
if
((
flags
&
FLAG_LOBS
)
!=
0
)
{
prepInsert
.
setString
(
1
,
getRandomString
(
random
.
nextInt
(
200
)));
prepInsert
.
execute
();
}
else
{
stat
.
execute
(
"INSERT INTO TEST(NAME) VALUES('Hello World')"
);
}
rowCount
++;
}
if
((
operations
&
OP_UPDATE
)
!=
0
)
{
if
((
flags
&
FLAG_LOBS
)
!=
0
)
{
prepUpdate
.
setString
(
1
,
getRandomString
(
random
.
nextInt
(
200
)));
prepUpdate
.
setInt
(
2
,
random
.
nextInt
(
rowCount
+
1
));
prepUpdate
.
execute
();
}
else
{
stat
.
execute
(
"UPDATE TEST SET VALUE = 'Hallo Welt' WHERE ID = "
+
random
.
nextInt
(
rowCount
+
1
));
}
}
if
((
operations
&
OP_DELETE
)
!=
0
)
{
int
uc
=
stat
.
executeUpdate
(
"DELETE FROM TEST WHERE ID = "
+
random
.
nextInt
(
rowCount
+
1
));
rowCount
-=
uc
;
}
log
(
"rows now: "
+
rowCount
,
null
);
if
(
rowCount
%
2
==
0
)
{
conn
.
commit
();
log
(
"committed: "
+
rowCount
,
null
);
}
if
((
flags
&
FLAG_NODELAY
)
!=
0
)
{
if
(
random
.
nextInt
(
100
)
==
0
)
{
stat
.
execute
(
"CHECKPOINT"
);
}
}
}
conn
.
rollback
();
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/Value.java
浏览文件 @
00044424
...
@@ -13,6 +13,8 @@ import java.sql.Time;
...
@@ -13,6 +13,8 @@ import java.sql.Time;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.sql.Types
;
import
org.h2.value.DataType
;
public
class
Value
{
public
class
Value
{
private
int
type
;
private
int
type
;
private
Object
data
;
private
Object
data
;
...
@@ -53,7 +55,7 @@ public class Value {
...
@@ -53,7 +55,7 @@ public class Value {
return
getTimeSQL
((
Time
)
data
);
return
getTimeSQL
((
Time
)
data
);
case
Types
.
TIMESTAMP
:
case
Types
.
TIMESTAMP
:
return
getTimestampSQL
((
Timestamp
)
data
);
return
getTimestampSQL
((
Timestamp
)
data
);
case
Types
.
BOOLEAN
:
case
DataType
.
TYPE_
BOOLEAN
:
case
Types
.
BIT
:
case
Types
.
BIT
:
return
(
String
)
data
;
return
(
String
)
data
;
default
:
default
:
...
@@ -164,7 +166,7 @@ public class Value {
...
@@ -164,7 +166,7 @@ public class Value {
case
Types
.
NULL
:
case
Types
.
NULL
:
data
=
null
;
data
=
null
;
break
;
break
;
case
Types
.
BOOLEAN
:
case
DataType
.
TYPE_
BOOLEAN
:
case
Types
.
BIT
:
case
Types
.
BIT
:
data
=
rs
.
getBoolean
(
index
)
?
"TRUE"
:
"FALSE"
;
data
=
rs
.
getBoolean
(
index
)
?
"TRUE"
:
"FALSE"
;
break
;
break
;
...
@@ -213,7 +215,7 @@ public class Value {
...
@@ -213,7 +215,7 @@ public class Value {
case
Types
.
INTEGER
:
case
Types
.
INTEGER
:
data
=
randomInt
(
config
);
data
=
randomInt
(
config
);
break
;
break
;
case
Types
.
BOOLEAN
:
case
DataType
.
TYPE_
BOOLEAN
:
case
Types
.
BIT
:
case
Types
.
BIT
:
data
=
config
.
random
().
getBoolean
(
50
)
?
"TRUE"
:
"FALSE"
;
data
=
config
.
random
().
getBoolean
(
50
)
?
"TRUE"
:
"FALSE"
;
break
;
break
;
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论