Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b063c9cf
提交
b063c9cf
authored
5月 07, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test need to clean up the file system after running.
上级
43fde846
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
557 行增加
和
116 行删除
+557
-116
TestAutoReconnect.java
h2/src/test/org/h2/test/unit/TestAutoReconnect.java
+2
-2
TestExit.java
h2/src/test/org/h2/test/unit/TestExit.java
+6
-3
TestFileLock.java
h2/src/test/org/h2/test/unit/TestFileLock.java
+14
-8
TestFileLockSerialized.java
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
+23
-19
TestFileSystem.java
h2/src/test/org/h2/test/unit/TestFileSystem.java
+25
-14
TestFtp.java
h2/src/test/org/h2/test/unit/TestFtp.java
+6
-1
TestPageStore.java
h2/src/test/org/h2/test/unit/TestPageStore.java
+8
-3
TestPageStoreCoverage.java
h2/src/test/org/h2/test/unit/TestPageStoreCoverage.java
+238
-0
TestPgServer.java
h2/src/test/org/h2/test/unit/TestPgServer.java
+1
-1
TestRecovery.java
h2/src/test/org/h2/test/unit/TestRecovery.java
+13
-5
TestReopen.java
h2/src/test/org/h2/test/unit/TestReopen.java
+140
-0
TestSampleApps.java
h2/src/test/org/h2/test/unit/TestSampleApps.java
+8
-4
TestServlet.java
h2/src/test/org/h2/test/unit/TestServlet.java
+4
-2
TestStreams.java
h2/src/test/org/h2/test/unit/TestStreams.java
+4
-1
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+64
-52
TestValueMemory.java
h2/src/test/org/h2/test/unit/TestValueMemory.java
+1
-1
没有找到文件。
h2/src/test/org/h2/test/unit/TestAutoReconnect.java
浏览文件 @
b063c9cf
...
...
@@ -61,13 +61,13 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
private
void
testReconnect
()
throws
Exception
{
deleteDb
(
"autoReconnect"
);
if
(
autoServer
)
{
url
=
"jdbc:h2:"
+
baseDir
+
"/autoReconnect;"
+
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/autoReconnect;"
+
"FILE_LOCK=SOCKET;"
+
"AUTO_SERVER=TRUE;OPEN_NEW=TRUE"
;
restart
();
}
else
{
server
=
Server
.
createTcpServer
(
"-tcpPort"
,
"8181"
).
start
();
url
=
"jdbc:h2:tcp://localhost:8181/"
+
baseDir
+
"/autoReconnect;"
+
url
=
"jdbc:h2:tcp://localhost:8181/"
+
getBaseDir
()
+
"/autoReconnect;"
+
"FILE_LOCK=SOCKET;AUTO_RECONNECT=TRUE"
;
}
...
...
h2/src/test/org/h2/test/unit/TestExit.java
浏览文件 @
b063c9cf
...
...
@@ -30,6 +30,9 @@ public class TestExit extends TestBase implements DatabaseEventListener {
if
(
config
.
codeCoverage
||
config
.
networked
)
{
return
;
}
if
(
getBaseDir
().
indexOf
(
':'
)
>
0
)
{
return
;
}
deleteDb
(
"exit"
);
String
selfDestruct
=
SelfDestructor
.
getPropertyString
(
60
);
String
[]
procDef
=
{
"java"
,
selfDestruct
,
...
...
@@ -88,11 +91,11 @@ public class TestExit extends TestBase implements DatabaseEventListener {
String
url
=
""
;
switch
(
action
)
{
case
OPEN_WITH_CLOSE_ON_EXIT:
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=true"
;
break
;
case
OPEN_WITHOUT_CLOSE_ON_EXIT:
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=false"
;
break
;
default
:
...
...
@@ -124,7 +127,7 @@ public class TestExit extends TestBase implements DatabaseEventListener {
}
private
static
File
getClosedFile
()
{
return
new
File
(
baseDir
+
"/closed.txt"
);
return
new
File
(
TestBase
.
BASE_TEST_DIR
+
"/closed.txt"
);
}
public
void
setProgress
(
int
state
,
String
name
,
int
x
,
int
max
)
{
...
...
h2/src/test/org/h2/test/unit/TestFileLock.java
浏览文件 @
b063c9cf
...
...
@@ -18,7 +18,6 @@ import org.h2.test.TestBase;
*/
public
class
TestFileLock
extends
TestBase
implements
Runnable
{
private
static
final
String
FILE
=
baseDir
+
"/test.lock"
;
private
static
volatile
int
locks
;
private
static
volatile
boolean
stop
;
private
TestBase
base
;
...
...
@@ -34,6 +33,10 @@ public class TestFileLock extends TestBase implements Runnable {
this
.
allowSockets
=
allowSockets
;
}
private
String
getFile
()
{
return
getBaseDir
()
+
"/test.lock"
;
}
/**
* Run just this test.
*
...
...
@@ -44,6 +47,9 @@ public class TestFileLock extends TestBase implements Runnable {
}
public
void
test
()
throws
Exception
{
if
(!
getFile
().
startsWith
(
TestBase
.
BASE_TEST_DIR
))
{
return
;
}
testFutureModificationDate
();
testSimple
();
test
(
false
);
...
...
@@ -51,18 +57,18 @@ public class TestFileLock extends TestBase implements Runnable {
}
private
void
testFutureModificationDate
()
throws
Exception
{
File
f
=
new
File
(
FILE
);
File
f
=
new
File
(
getFile
()
);
f
.
delete
();
f
.
createNewFile
();
f
.
setLastModified
(
System
.
currentTimeMillis
()
+
10000
);
FileLock
lock
=
new
FileLock
(
new
TraceSystem
(
null
),
FILE
,
Constants
.
LOCK_SLEEP
);
FileLock
lock
=
new
FileLock
(
new
TraceSystem
(
null
),
getFile
()
,
Constants
.
LOCK_SLEEP
);
lock
.
lock
(
FileLock
.
LOCK_FILE
);
lock
.
unlock
();
}
private
void
testSimple
()
{
FileLock
lock1
=
new
FileLock
(
new
TraceSystem
(
null
),
FILE
,
Constants
.
LOCK_SLEEP
);
FileLock
lock2
=
new
FileLock
(
new
TraceSystem
(
null
),
FILE
,
Constants
.
LOCK_SLEEP
);
FileLock
lock1
=
new
FileLock
(
new
TraceSystem
(
null
),
getFile
()
,
Constants
.
LOCK_SLEEP
);
FileLock
lock2
=
new
FileLock
(
new
TraceSystem
(
null
),
getFile
()
,
Constants
.
LOCK_SLEEP
);
lock1
.
lock
(
FileLock
.
LOCK_FILE
);
try
{
lock2
.
lock
(
FileLock
.
LOCK_FILE
);
...
...
@@ -71,7 +77,7 @@ public class TestFileLock extends TestBase implements Runnable {
// expected
}
lock1
.
unlock
();
lock2
=
new
FileLock
(
new
TraceSystem
(
null
),
FILE
,
Constants
.
LOCK_SLEEP
);
lock2
=
new
FileLock
(
new
TraceSystem
(
null
),
getFile
()
,
Constants
.
LOCK_SLEEP
);
lock2
.
lock
(
FileLock
.
LOCK_FILE
);
lock2
.
unlock
();
}
...
...
@@ -80,7 +86,7 @@ public class TestFileLock extends TestBase implements Runnable {
int
threadCount
=
getSize
(
3
,
5
);
wait
=
getSize
(
20
,
200
);
Thread
[]
threads
=
new
Thread
[
threadCount
];
new
File
(
FILE
).
delete
();
new
File
(
getFile
()
).
delete
();
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
threads
[
i
]
=
new
Thread
(
new
TestFileLock
(
this
,
allowSocketsLock
));
threads
[
i
].
start
();
...
...
@@ -99,7 +105,7 @@ public class TestFileLock extends TestBase implements Runnable {
public
void
run
()
{
FileLock
lock
=
null
;
while
(!
stop
)
{
lock
=
new
FileLock
(
new
TraceSystem
(
null
),
FILE
,
100
);
lock
=
new
FileLock
(
new
TraceSystem
(
null
),
getFile
()
,
100
);
try
{
lock
.
lock
(
allowSockets
?
FileLock
.
LOCK_SOCKET
:
FileLock
.
LOCK_FILE
);
base
.
trace
(
lock
+
" locked"
);
...
...
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
浏览文件 @
b063c9cf
...
...
@@ -6,7 +6,6 @@
*/
package
org
.
h2
.
test
.
unit
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.OutputStream
;
import
java.sql.Connection
;
...
...
@@ -18,6 +17,7 @@ import java.sql.Statement;
import
java.util.Arrays
;
import
java.util.List
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.util.SortedProperties
;
...
...
@@ -68,11 +68,12 @@ public class TestFileLockSerialized extends TestBase {
testKillWriter
();
println
(
"testConcurrentReadWrite"
);
testConcurrentReadWrite
();
deleteDb
(
"fileLockSerialized"
);
}
private
void
testSequenceFlush
()
throws
Exception
{
deleteDb
(
"fileLockSerialized"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE"
;
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE"
;
ResultSet
rs
;
Connection
conn1
=
DriverManager
.
getConnection
(
url
);
Statement
stat1
=
conn1
.
createStatement
();
...
...
@@ -92,7 +93,7 @@ public class TestFileLockSerialized extends TestBase {
private
void
testThreeMostlyReaders
(
final
boolean
write
)
throws
Exception
{
boolean
longRun
=
false
;
deleteDb
(
"fileLockSerialized"
);
final
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE"
;
final
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
);
conn
.
createStatement
().
execute
(
"create table test(id int) as select 1"
);
...
...
@@ -145,7 +146,7 @@ public class TestFileLockSerialized extends TestBase {
private
void
testTwoReaders
()
throws
Exception
{
deleteDb
(
"fileLockSerialized"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE"
;
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE"
;
Connection
conn1
=
DriverManager
.
getConnection
(
url
);
conn1
.
createStatement
().
execute
(
"create table test(id int)"
);
Connection
conn2
=
DriverManager
.
getConnection
(
url
);
...
...
@@ -159,7 +160,7 @@ public class TestFileLockSerialized extends TestBase {
private
void
testTwoWriters
()
throws
Exception
{
deleteDb
(
"fileLockSerialized"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized"
;
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized"
;
final
String
writeUrl
=
url
+
";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE"
;
final
boolean
[]
stop
=
{
false
};
Connection
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
...
...
@@ -197,14 +198,14 @@ public class TestFileLockSerialized extends TestBase {
private
void
testPendingWrite
()
throws
Exception
{
deleteDb
(
"fileLockSerialized"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized"
;
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized"
;
String
writeUrl
=
url
+
";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;WRITE_DELAY=0"
;
Connection
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key)"
);
Thread
.
sleep
(
100
);
String
propFile
=
baseDir
+
"/fileLockSerialized.lock.db"
;
String
propFile
=
getBaseDir
()
+
"/fileLockSerialized.lock.db"
;
SortedProperties
p
=
SortedProperties
.
loadProperties
(
propFile
);
p
.
setProperty
(
"changePending"
,
"true"
);
p
.
setProperty
(
"modificationDataId"
,
"1000"
);
...
...
@@ -221,7 +222,7 @@ public class TestFileLockSerialized extends TestBase {
private
void
testKillWriter
()
throws
Exception
{
deleteDb
(
"fileLockSerialized"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized"
;
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized"
;
String
writeUrl
=
url
+
";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;WRITE_DELAY=0"
;
Connection
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
...
...
@@ -252,7 +253,7 @@ public class TestFileLockSerialized extends TestBase {
private
void
testConcurrentReadWrite
()
throws
Exception
{
deleteDb
(
"fileLockSerialized"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized"
;
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized"
;
String
writeUrl
=
url
+
";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE"
;
// ;TRACE_LEVEL_SYSTEM_OUT=3
// String readUrl = writeUrl + ";ACCESS_MODE_DATA=R";
...
...
@@ -326,7 +327,7 @@ public class TestFileLockSerialized extends TestBase {
private
void
testAutoIncrement
(
final
int
waitTime
,
int
howManyThreads
,
int
runTime
)
throws
Exception
{
println
(
"testAutoIncrement waitTime: "
+
waitTime
+
" howManyThreads: "
+
howManyThreads
+
" runTime: "
+
runTime
);
deleteDb
(
"fileLockSerialized"
);
final
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;"
+
final
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;"
+
"AUTO_RECONNECT=TRUE;MAX_LENGTH_INPLACE_LOB=8192;COMPRESS_LOB=DEFLATE;CACHE_SIZE=65536"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
);
...
...
@@ -393,7 +394,7 @@ public class TestFileLockSerialized extends TestBase {
private
void
testConcurrentUpdates
(
final
int
waitTime
,
int
howManyThreads
,
int
runTime
)
throws
Exception
{
println
(
"testConcurrentUpdates waitTime: "
+
waitTime
+
" howManyThreads: "
+
howManyThreads
+
" runTime: "
+
runTime
);
deleteDb
(
"fileLockSerialized"
);
final
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;"
+
final
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;"
+
"AUTO_RECONNECT=TRUE;MAX_LENGTH_INPLACE_LOB=8192;COMPRESS_LOB=DEFLATE;CACHE_SIZE=65536"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
);
...
...
@@ -464,7 +465,7 @@ public class TestFileLockSerialized extends TestBase {
private
void
testCheckpointInUpdateRaceCondition
()
throws
Exception
{
boolean
longRun
=
false
;
deleteDb
(
"fileLockSerialized"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE"
;
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
);
conn
.
createStatement
().
execute
(
"create table test(id int)"
);
...
...
@@ -484,7 +485,7 @@ public class TestFileLockSerialized extends TestBase {
private
void
testCache
()
throws
Exception
{
deleteDb
(
"fileLockSerialized"
);
String
urlShared
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED"
;
String
urlShared
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED"
;
Connection
connShared1
=
DriverManager
.
getConnection
(
urlShared
);
Statement
statement1
=
connShared1
.
createStatement
();
...
...
@@ -515,7 +516,7 @@ public class TestFileLockSerialized extends TestBase {
private
void
testWrongDatabaseInstanceOnReconnect
()
throws
Exception
{
deleteDb
(
"fileLockSerialized"
);
String
urlShared
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED"
;
String
urlShared
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED"
;
String
urlForNew
=
urlShared
+
";OPEN_NEW=TRUE"
;
Connection
connShared1
=
DriverManager
.
getConnection
(
urlShared
);
...
...
@@ -535,7 +536,7 @@ public class TestFileLockSerialized extends TestBase {
deleteDb
(
"fileLockSerialized"
);
int
cacheSizeKb
=
withCache
?
5000
:
0
;
final
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;CACHE_SIZE="
+
cacheSizeKb
;
final
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;CACHE_SIZE="
+
cacheSizeKb
;
final
boolean
[]
importFinished
=
{
false
};
final
Exception
[]
ex
=
{
null
};
final
Thread
importUpdate
=
new
Thread
()
{
...
...
@@ -599,17 +600,20 @@ public class TestFileLockSerialized extends TestBase {
// without serialized
String
url
;
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized"
;
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int)"
);
stat
.
execute
(
"insert into test values(0)"
);
conn
.
close
();
List
<
String
>
filesWithoutSerialized
=
Arrays
.
asList
(
new
File
(
baseDir
).
list
());
FileSystem
fs
=
FileSystem
.
getInstance
(
getBaseDir
());
List
<
String
>
filesWithoutSerialized
=
Arrays
.
asList
(
fs
.
listFiles
(
getBaseDir
()));
deleteDb
(
"fileLockSerialized"
);
// with serialized
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED"
;
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fileLockSerialized;FILE_LOCK=SERIALIZED"
;
conn
=
DriverManager
.
getConnection
(
url
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int)"
);
...
...
@@ -617,7 +621,7 @@ public class TestFileLockSerialized extends TestBase {
stat
.
execute
(
"insert into test values(0)"
);
conn
.
close
();
List
<
String
>
filesWithSerialized
=
Arrays
.
asList
(
new
File
(
baseDir
).
list
(
));
List
<
String
>
filesWithSerialized
=
Arrays
.
asList
(
fs
.
listFiles
(
getBaseDir
()
));
if
(
filesWithoutSerialized
.
size
()
!=
filesWithSerialized
.
size
())
{
for
(
int
i
=
0
;
i
<
filesWithoutSerialized
.
size
();
i
++)
{
if
(!
filesWithSerialized
.
contains
(
filesWithoutSerialized
.
get
(
i
)))
{
...
...
h2/src/test/org/h2/test/unit/TestFileSystem.java
浏览文件 @
b063c9cf
...
...
@@ -22,6 +22,7 @@ import org.h2.store.fs.FileObject;
import
org.h2.store.fs.FileSystem
;
import
org.h2.store.fs.FileSystemMemory
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
/**
* Tests various file system.
...
...
@@ -41,9 +42,9 @@ public class TestFileSystem extends TestBase {
testDatabaseInMemFileSys
();
testDatabaseInJar
();
// set default part size to 1 << 10
FileSystem
.
getInstance
(
"split:10:"
+
baseDir
+
"/fs"
);
testFileSystem
(
"split:"
+
baseDir
+
"/fs"
);
testFileSystem
(
baseDir
+
"/fs"
);
FileSystem
.
getInstance
(
"split:10:"
+
getBaseDir
()
+
"/fs"
);
testFileSystem
(
"split:"
+
getBaseDir
()
+
"/fs"
);
testFileSystem
(
getBaseDir
()
+
"/fs"
);
testFileSystem
(
FileSystemMemory
.
PREFIX
);
FileSystemDatabase
fs
=
FileSystemDatabase
.
register
(
"jdbc:h2:mem:fs"
);
// testFileSystem("jdbc:h2:mem:fs;TRACE_LEVEL_FILE=3");
...
...
@@ -51,29 +52,35 @@ public class TestFileSystem extends TestBase {
testFileSystem
(
FileSystemMemory
.
PREFIX_LZF
);
testUserHome
();
fs
.
unregister
();
IOUtils
.
delete
(
getBaseDir
()
+
"/fs"
);
}
private
void
testDatabaseInMemFileSys
()
throws
SQLException
{
org
.
h2
.
Driver
.
load
();
deleteDb
(
"fsMem"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fsMem"
;
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fsMem"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
,
"sa"
,
"sa"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST AS SELECT * FROM DUAL"
);
conn
.
createStatement
().
execute
(
"BACKUP TO '"
+
baseDir
+
"/fsMem.zip'"
);
conn
.
createStatement
().
execute
(
"BACKUP TO '"
+
getBaseDir
()
+
"/fsMem.zip'"
);
conn
.
close
();
org
.
h2
.
tools
.
Restore
.
main
(
"-file"
,
baseDir
+
"/fsMem.zip"
,
"-dir"
,
"memFS:"
);
org
.
h2
.
tools
.
Restore
.
main
(
"-file"
,
getBaseDir
()
+
"/fsMem.zip"
,
"-dir"
,
"memFS:"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:memFS:fsMem"
,
"sa"
,
"sa"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
rs
.
close
();
conn
.
close
();
deleteDb
(
"fsMem"
);
IOUtils
.
delete
(
getBaseDir
()
+
"/fsMem.zip"
);
}
private
void
testDatabaseInJar
()
throws
SQLException
{
if
(
getBaseDir
().
indexOf
(
':'
)
>
0
)
{
return
;
}
if
(
config
.
networked
)
{
return
;
}
org
.
h2
.
Driver
.
load
();
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fsJar"
;
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/fsJar"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar, b blob, c clob)"
);
...
...
@@ -86,18 +93,18 @@ public class TestFileSystem extends TestBase {
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
url
,
"sa"
,
"sa"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"backup to '"
+
baseDir
+
"/fsJar.zip'"
);
stat
.
execute
(
"backup to '"
+
getBaseDir
()
+
"/fsJar.zip'"
);
conn
.
close
();
deleteDb
(
"fsJar"
);
FileSystem
fs
=
FileSystem
.
getInstance
(
"zip:"
+
baseDir
+
"/fsJar.zip"
);
for
(
String
f
:
fs
.
listFiles
(
"zip:"
+
baseDir
+
"/fsJar.zip"
))
{
FileSystem
fs
=
FileSystem
.
getInstance
(
"zip:"
+
getBaseDir
()
+
"/fsJar.zip"
);
for
(
String
f
:
fs
.
listFiles
(
"zip:"
+
getBaseDir
()
+
"/fsJar.zip"
))
{
assertTrue
(
fs
.
isAbsolute
(
f
));
assertTrue
(!
fs
.
isDirectory
(
f
));
assertTrue
(
fs
.
length
(
f
)
>
0
);
assertTrue
(
f
.
endsWith
(
fs
.
getFileName
(
f
)));
}
String
urlJar
=
"jdbc:h2:zip:"
+
baseDir
+
"/fsJar.zip!/fsJar"
;
String
urlJar
=
"jdbc:h2:zip:"
+
getBaseDir
()
+
"/fsJar.zip!/fsJar"
;
conn
=
DriverManager
.
getConnection
(
urlJar
,
"sa"
,
"sa"
);
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
"select * from test"
);
...
...
@@ -112,6 +119,7 @@ public class TestFileSystem extends TestBase {
assertEquals
(
s1
,
s2
);
assertFalse
(
rs
.
next
());
conn
.
close
();
IOUtils
.
delete
(
getBaseDir
()
+
"/fsJar.zip"
);
}
private
void
testUserHome
()
{
...
...
@@ -176,7 +184,7 @@ public class TestFileSystem extends TestBase {
assertTrue
(
fs
.
tryDelete
(
fsBase
+
"/test2"
));
fs
.
delete
(
fsBase
+
"/test"
);
if
(
!
fsBase
.
startsWith
(
FileSystemMemory
.
PREFIX
)
&&
!
fsBase
.
startsWith
(
FileSystemMemory
.
PREFIX_LZF
)
)
{
if
(
fsBase
.
indexOf
(
FileSystemMemory
.
PREFIX
)
<
0
&&
fsBase
.
indexOf
(
FileSystemMemory
.
PREFIX_LZF
)
<
0
)
{
fs
.
createDirs
(
fsBase
+
"/testDir/test"
);
assertTrue
(
fs
.
isDirectory
(
fsBase
+
"/testDir"
));
if
(!
fsBase
.
startsWith
(
"jdbc:"
))
{
...
...
@@ -189,7 +197,8 @@ public class TestFileSystem extends TestBase {
private
void
testRandomAccess
(
String
fsBase
)
throws
Exception
{
FileSystem
fs
=
FileSystem
.
getInstance
(
fsBase
);
String
s
=
fs
.
createTempFile
(
fsBase
+
"/temp"
,
".tmp"
,
false
,
false
);
File
file
=
new
File
(
baseDir
+
"/temp"
);
File
file
=
new
File
(
TestBase
.
BASE_TEST_DIR
+
"/temp"
);
file
.
getParentFile
().
mkdirs
();
file
.
delete
();
RandomAccessFile
ra
=
new
RandomAccessFile
(
file
,
"rw"
);
fs
.
delete
(
s
);
...
...
@@ -266,6 +275,8 @@ public class TestFileSystem extends TestBase {
}
f
.
close
();
ra
.
close
();
file
.
delete
();
fs
.
delete
(
s
);
}
private
void
testTempFile
(
String
fsBase
)
throws
Exception
{
...
...
@@ -286,7 +297,7 @@ public class TestFileSystem extends TestBase {
assertEquals
(-
1
,
in
.
read
());
in
.
close
();
out
.
close
();
fs
.
delete
(
s
);
}
}
h2/src/test/org/h2/test/unit/TestFtp.java
浏览文件 @
b063c9cf
...
...
@@ -12,6 +12,7 @@ import org.h2.dev.ftp.server.FtpEventListener;
import
org.h2.dev.ftp.server.FtpServer
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Server
;
import
org.h2.util.IOUtils
;
/**
* Tests the FTP server tool.
...
...
@@ -30,7 +31,11 @@ public class TestFtp extends TestBase implements FtpEventListener {
}
public
void
test
()
throws
Exception
{
test
(
baseDir
);
if
(
getBaseDir
().
indexOf
(
':'
)
>
0
)
{
return
;
}
test
(
getBaseDir
());
IOUtils
.
delete
(
getBaseDir
()
+
"/test"
);
}
private
void
test
(
String
dir
)
throws
Exception
{
...
...
h2/src/test/org/h2/test/unit/TestPageStore.java
浏览文件 @
b063c9cf
...
...
@@ -17,6 +17,7 @@ import java.util.Set;
import
java.util.TreeSet
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
/**
* Test the page store.
...
...
@@ -57,6 +58,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
testUniqueIndex
();
testCreateIndexLater
();
testFuzzOperations
();
deleteDb
(
"pageStore"
);
}
private
void
testCheckpoint
()
throws
SQLException
{
...
...
@@ -73,7 +75,9 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
stat
.
execute
(
"select nextval('SEQ') from system_range(1, 100000)"
);
long
after
=
System
.
currentTimeMillis
();
// it's hard to test - basically it shouldn't checkpoint too often
assertTrue
(
after
-
before
<
10000
);
if
(
after
-
before
>
10000
)
{
fail
(
"Checkpoint took "
+
(
after
-
before
)
+
" ms"
);
}
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"drop sequence seq"
);
conn
.
close
();
...
...
@@ -317,7 +321,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
Connection
conn
;
deleteDb
(
"pageStore"
);
String
url
;
url
=
"jdbc:h2:"
+
baseDir
+
"/pageStore"
;
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/pageStore"
;
conn
=
DriverManager
.
getConnection
(
url
);
conn
.
createStatement
().
execute
(
"create table test(id int) as select 1"
);
conn
.
close
();
...
...
@@ -396,8 +400,9 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
url
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"script to '"
+
baseDir
+
"/pageStore.sql'"
);
stat
.
execute
(
"script to '"
+
getBaseDir
()
+
"/pageStore.sql'"
);
conn
.
close
();
IOUtils
.
delete
(
getBaseDir
()
+
"/pageStore.sql"
);
}
catch
(
Exception
e
)
{
try
{
stat
.
execute
(
"shutdown immediately"
);
...
...
h2/src/test/org/h2/test/unit/TestPageStoreCoverage.java
0 → 100644
浏览文件 @
b063c9cf
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
unit
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FileObject
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Restore
;
import
org.h2.util.IOUtils
;
/**
* Test the page store.
*/
public
class
TestPageStoreCoverage
extends
TestBase
{
private
static
final
String
URL
=
"pageStore;PAGE_SIZE=64;CACHE_SIZE=16;MAX_LOG_SIZE=1"
;
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
// TODO mvcc, 2-phase commit
if
(
config
.
memory
)
{
return
;
}
deleteDb
(
"pageStore"
);
// testMoveRoot();
// testBasic();
// testReadOnly();
// testIncompleteCreate();
// testBackupRestore();
testTrim
();
testLongTransaction
();
testRecoverTemp
();
deleteDb
(
"pageStore"
);
}
private
void
testMoveRoot
()
throws
SQLException
{
Connection
conn
;
conn
=
getConnection
(
URL
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key) as select x from system_range(1, 100)"
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
stat
.
execute
(
"create table test"
+
i
+
"(id int primary key) as select x from system_range(1, 2)"
);
}
stat
.
execute
(
"drop table test"
);
conn
.
close
();
conn
=
getConnection
(
URL
);
stat
=
conn
.
createStatement
();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test"
+
i
);
while
(
rs
.
next
())
{
// ignore
}
}
stat
.
execute
(
"drop all objects delete files"
);
conn
.
close
();
}
private
void
testRecoverTemp
()
throws
SQLException
{
Connection
conn
;
conn
=
getConnection
(
URL
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create cached temporary table test(id identity, name varchar)"
);
stat
.
execute
(
"create index idx_test_name on test(name)"
);
stat
.
execute
(
"create index idx_test_name2 on test(name, id)"
);
stat
.
execute
(
"create table test2(id identity, name varchar)"
);
stat
.
execute
(
"create index idx_test2_name on test2(name desc)"
);
stat
.
execute
(
"create index idx_test2_name2 on test2(name, id)"
);
stat
.
execute
(
"insert into test2 select null, space(10) from system_range(1, 10)"
);
stat
.
execute
(
"create table test3(id identity, name varchar)"
);
stat
.
execute
(
"checkpoint"
);
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"create table test4(id identity, name varchar)"
);
stat
.
execute
(
"create index idx_test4_name2 on test(name, id)"
);
stat
.
execute
(
"insert into test select null, space(10) from system_range(1, 10)"
);
stat
.
execute
(
"insert into test3 select null, space(10) from system_range(1, 10)"
);
stat
.
execute
(
"insert into test4 select null, space(10) from system_range(1, 10)"
);
stat
.
execute
(
"truncate table test2"
);
stat
.
execute
(
"drop index idx_test_name"
);
stat
.
execute
(
"drop index idx_test2_name"
);
stat
.
execute
(
"drop table test2"
);
stat
.
execute
(
"insert into test select null, space(10) from system_range(1, 10)"
);
stat
.
execute
(
"shutdown immediately"
);
try
{
conn
.
close
();
fail
();
}
catch
(
SQLException
e
)
{
// ignore
}
conn
=
getConnection
(
URL
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop all objects"
);
// re-allocate index root pages
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
stat
.
execute
(
"create table test"
+
i
+
"(id identity, name varchar)"
);
}
stat
.
execute
(
"checkpoint"
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
stat
.
execute
(
"drop table test"
+
i
);
}
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
stat
.
execute
(
"create table test"
+
i
+
"(id identity, name varchar)"
);
}
stat
.
execute
(
"shutdown immediately"
);
try
{
conn
.
close
();
fail
();
}
catch
(
SQLException
e
)
{
// ignore
}
conn
=
getConnection
(
URL
);
conn
.
createStatement
().
execute
(
"drop all objects"
);
conn
.
close
();
}
private
void
testLongTransaction
()
throws
SQLException
{
Connection
conn
;
conn
=
getConnection
(
URL
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id identity, name varchar)"
);
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"insert into test select null, space(10) from system_range(1, 10)"
);
Connection
conn2
;
conn2
=
getConnection
(
URL
);
Statement
stat2
=
conn2
.
createStatement
();
stat2
.
execute
(
"checkpoint"
);
// large transaction
stat2
.
execute
(
"create table test2(id identity, name varchar)"
);
stat2
.
execute
(
"create index idx_test2_name on test2(name)"
);
stat2
.
execute
(
"insert into test2 select null, x || space(10000) from system_range(1, 100)"
);
stat2
.
execute
(
"drop table test2"
);
conn2
.
close
();
stat
.
execute
(
"drop table test"
);
conn
.
close
();
}
private
void
testTrim
()
throws
SQLException
{
Connection
conn
;
conn
=
getConnection
(
URL
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"create index idx_name on test(name, id)"
);
stat
.
execute
(
"insert into test select x, x || space(10) from system_range(1, 20)"
);
stat
.
execute
(
"create table test2(id int primary key, name varchar)"
);
stat
.
execute
(
"create index idx_test2_name on test2(name, id)"
);
stat
.
execute
(
"insert into test2 select x, x || space(10) from system_range(1, 20)"
);
stat
.
execute
(
"create table test3(id int primary key, name varchar)"
);
stat
.
execute
(
"create index idx_test3_name on test3(name, id)"
);
stat
.
execute
(
"insert into test3 select x, x || space(3) from system_range(1, 3)"
);
stat
.
execute
(
"delete from test"
);
stat
.
execute
(
"checkpoint"
);
stat
.
execute
(
"checkpoint sync"
);
stat
.
execute
(
"shutdown compact"
);
conn
.
close
();
conn
=
getConnection
(
URL
);
conn
.
createStatement
().
execute
(
"drop all objects"
);
conn
.
close
();
}
private
void
testBasic
()
throws
Exception
{
Connection
conn
;
conn
=
getConnection
(
URL
);
conn
.
close
();
conn
=
getConnection
(
URL
);
conn
.
close
();
}
private
void
testReadOnly
()
throws
Exception
{
Connection
conn
;
conn
=
getConnection
(
URL
);
conn
.
createStatement
().
execute
(
"shutdown compact"
);
conn
.
close
();
conn
=
getConnection
(
URL
+
";access_mode_data=r"
);
conn
.
close
();
}
private
void
testBackupRestore
()
throws
Exception
{
Connection
conn
;
conn
=
getConnection
(
URL
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"create index idx_name on test(name, id)"
);
stat
.
execute
(
"insert into test select x, x || space(200 * x) from system_range(1, 10)"
);
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"delete from test where id > 5"
);
stat
.
execute
(
"backup to '"
+
getBaseDir
()
+
"/backup.zip'"
);
conn
.
rollback
();
Restore
.
execute
(
getBaseDir
()
+
"/backup.zip"
,
getBaseDir
(),
"pageStore2"
,
true
);
Connection
conn2
;
conn2
=
getConnection
(
"pageStore2"
);
Statement
stat2
=
conn2
.
createStatement
();
assertEqualDatabases
(
stat
,
stat2
);
conn
.
createStatement
().
execute
(
"drop table test"
);
conn2
.
close
();
conn
.
close
();
IOUtils
.
delete
(
getBaseDir
()
+
"/backup.zip"
);
deleteDb
(
"pageStore2"
);
}
private
void
testIncompleteCreate
()
throws
Exception
{
deleteDb
(
"pageStore"
);
Connection
conn
;
String
fileName
=
getBaseDir
()
+
"/pageStore"
+
Constants
.
SUFFIX_PAGE_FILE
;
conn
=
getConnection
(
"pageStore"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop table if exists INFORMATION_SCHEMA.LOB_DATA"
);
stat
.
execute
(
"drop table if exists INFORMATION_SCHEMA.LOB_MAP"
);
conn
.
close
();
FileObject
f
=
FileSystem
.
getInstance
(
fileName
).
openFileObject
(
fileName
,
"rw"
);
// create a new database
conn
=
getConnection
(
"pageStore"
);
conn
.
close
();
f
=
FileSystem
.
getInstance
(
fileName
).
openFileObject
(
fileName
,
"rw"
);
f
.
setFileLength
(
16
);
// create a new database
conn
=
getConnection
(
"pageStore"
);
deleteDb
(
"pageStore"
);
}
}
h2/src/test/org/h2/test/unit/TestPgServer.java
浏览文件 @
b063c9cf
...
...
@@ -36,7 +36,7 @@ public class TestPgServer extends TestBase {
public
void
test
()
throws
SQLException
{
deleteDb
(
"test"
);
Server
server
=
Server
.
createPgServer
(
"-baseDir"
,
baseDir
,
"-pgPort"
,
"5535"
);
Server
server
=
Server
.
createPgServer
(
"-baseDir"
,
getBaseDir
()
,
"-pgPort"
,
"5535"
);
server
.
start
();
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
...
...
h2/src/test/org/h2/test/unit/TestRecovery.java
浏览文件 @
b063c9cf
...
...
@@ -11,9 +11,11 @@ import java.io.PrintStream;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.tools.Recover
;
import
org.h2.util.IOUtils
;
/**
* Tests database recovery.
...
...
@@ -34,8 +36,8 @@ public class TestRecovery extends TestBase {
}
private
void
testRunScript
()
throws
SQLException
{
DeleteDbFiles
.
execute
(
baseDir
,
"recovery"
,
true
);
DeleteDbFiles
.
execute
(
baseDir
,
"recovery2"
,
true
);
DeleteDbFiles
.
execute
(
getBaseDir
()
,
"recovery"
,
true
);
DeleteDbFiles
.
execute
(
getBaseDir
()
,
"recovery2"
,
true
);
org
.
h2
.
Driver
.
load
();
Connection
conn
=
getConnection
(
"recovery"
);
Statement
stat
=
conn
.
createStatement
();
...
...
@@ -53,7 +55,7 @@ public class TestRecovery extends TestBase {
Recover
rec
=
new
Recover
();
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
rec
.
setOut
(
new
PrintStream
(
buff
));
rec
.
runTool
(
"-dir"
,
baseDir
,
"-db"
,
"recovery"
,
"-trace"
);
rec
.
runTool
(
"-dir"
,
getBaseDir
()
,
"-db"
,
"recovery"
,
"-trace"
);
String
out
=
new
String
(
buff
.
toByteArray
());
assertTrue
(
out
.
indexOf
(
"Created file"
)
>=
0
);
...
...
@@ -61,7 +63,7 @@ public class TestRecovery extends TestBase {
Statement
stat2
=
conn2
.
createStatement
();
String
name
=
"recovery.h2.sql"
;
stat2
.
execute
(
"runscript from '"
+
baseDir
+
"/"
+
name
+
"'"
);
stat2
.
execute
(
"runscript from '"
+
getBaseDir
()
+
"/"
+
name
+
"'"
);
stat2
.
execute
(
"select * from test"
);
stat2
.
execute
(
"drop user diff"
);
conn2
.
close
();
...
...
@@ -75,7 +77,13 @@ public class TestRecovery extends TestBase {
conn
.
close
();
conn2
.
close
();
Recover
.
execute
(
baseDir
,
"recovery"
);
Recover
.
execute
(
getBaseDir
(),
"recovery"
);
deleteDb
(
"recovery"
);
deleteDb
(
"recovery2"
);
IOUtils
.
delete
(
getBaseDir
()
+
"/recovery.h2.sql"
);
String
dir
=
getBaseDir
()
+
"/recovery.lobs.db"
;
FileSystem
.
getInstance
(
dir
).
deleteRecursive
(
dir
,
false
);
}
...
...
h2/src/test/org/h2/test/unit/TestReopen.java
0 → 100644
浏览文件 @
b063c9cf
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
unit
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.util.HashSet
;
import
java.util.Properties
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.ConnectionInfo
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.test.utils.Recorder
;
import
org.h2.test.utils.RecordingFileSystem
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.New
;
/**
* A test that calls another test, and after each write operation to the
* database file, it copies the file, and tries to reopen it.
*/
public
class
TestReopen
extends
TestBase
implements
Recorder
{
private
String
testDatabase
=
"memFS:"
+
TestBase
.
BASE_TEST_DIR
+
"/reopen"
;
private
long
lastCheck
;
private
int
counter
;
private
int
testEvery
=
1
<<
10
;
private
HashSet
<
String
>
knownErrors
=
New
.
hashSet
();
private
int
max
=
103128
;
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
System
.
setProperty
(
"h2.delayWrongPasswordMin"
,
"0"
);
RecordingFileSystem
.
register
();
RecordingFileSystem
.
setRecorder
(
this
);
config
.
record
=
true
;
long
time
=
System
.
currentTimeMillis
();
// Profiler p = new Profiler();
// p.startCollecting();
new
TestPageStoreCoverage
().
init
(
config
).
test
();
// System.out.println(p.getTop(3));
System
.
out
.
println
(
System
.
currentTimeMillis
()
-
time
);
System
.
out
.
println
(
"counter: "
+
counter
);
}
public
synchronized
void
log
(
int
op
,
String
fileName
,
byte
[]
data
,
long
x
)
{
if
(
op
!=
Recorder
.
WRITE
)
{
return
;
}
if
(!
fileName
.
endsWith
(
Constants
.
SUFFIX_PAGE_FILE
))
{
return
;
}
counter
++;
if
((
counter
&
1023
)
==
0
)
{
long
now
=
System
.
currentTimeMillis
();
if
(
now
>
lastCheck
+
5000
)
{
System
.
out
.
println
(
" at "
+
counter
+
" of "
+
max
+
" "
+
(
100
.
/
max
*
counter
));
//new Exception("currentPosition").printStackTrace(System.out);
lastCheck
=
now
;
}
}
if
((
counter
&
(
testEvery
-
1
))
!=
0
)
{
return
;
}
FileSystem
.
getInstance
(
fileName
).
copy
(
fileName
,
testDatabase
+
Constants
.
SUFFIX_PAGE_FILE
);
try
{
// avoid using the Engine class to avoid deadlocks
Properties
p
=
new
Properties
();
ConnectionInfo
ci
=
new
ConnectionInfo
(
"jdbc:h2:"
+
testDatabase
+
";FILE_LOCK=NO"
,
p
);
Database
database
=
new
Database
(
ci
,
null
);
// close the database
database
.
removeSession
(
null
);
// everything OK - return
return
;
}
catch
(
Exception
e
)
{
// failed
int
errorCode
=
0
;
if
(
e
instanceof
SQLException
)
{
errorCode
=
((
SQLException
)
e
).
getErrorCode
();
}
if
(
errorCode
==
ErrorCode
.
WRONG_USER_OR_PASSWORD
)
{
return
;
}
else
if
(
errorCode
==
ErrorCode
.
FILE_ENCRYPTION_ERROR_1
)
{
return
;
}
e
.
printStackTrace
(
System
.
out
);
}
System
.
out
.
println
(
"begin ------------------------------ "
+
counter
);
testDatabase
+=
"X"
;
FileSystem
.
getInstance
(
fileName
).
copy
(
fileName
,
testDatabase
+
Constants
.
SUFFIX_PAGE_FILE
);
try
{
// avoid using the Engine class to avoid deadlocks
Properties
p
=
new
Properties
();
ConnectionInfo
ci
=
new
ConnectionInfo
(
"jdbc:h2:"
+
testDatabase
+
";FILE_LOCK=NO"
,
p
);
Database
database
=
new
Database
(
ci
,
null
);
// close the database
database
.
removeSession
(
null
);
}
catch
(
Exception
e
)
{
int
errorCode
=
0
;
if
(
e
instanceof
SQLException
)
{
errorCode
=
((
SQLException
)
e
).
getErrorCode
();
}
if
(
errorCode
==
ErrorCode
.
WRONG_USER_OR_PASSWORD
)
{
return
;
}
else
if
(
errorCode
==
ErrorCode
.
FILE_ENCRYPTION_ERROR_1
)
{
return
;
}
StringBuilder
buff
=
new
StringBuilder
();
StackTraceElement
[]
list
=
e
.
getStackTrace
();
for
(
int
i
=
0
;
i
<
10
&&
i
<
list
.
length
;
i
++)
{
buff
.
append
(
list
[
i
].
toString
()).
append
(
'\n'
);
}
String
s
=
buff
.
toString
();
if
(!
knownErrors
.
contains
(
s
))
{
System
.
out
.
println
(
counter
+
" code: "
+
errorCode
+
" "
+
e
.
toString
());
e
.
printStackTrace
(
System
.
out
);
knownErrors
.
add
(
s
);
}
else
{
System
.
out
.
println
(
counter
+
" code: "
+
errorCode
);
}
}
}
}
h2/src/test/org/h2/test/unit/TestSampleApps.java
浏览文件 @
b063c9cf
...
...
@@ -34,14 +34,17 @@ public class TestSampleApps extends TestBase {
}
public
void
test
()
throws
Exception
{
if
(!
getBaseDir
().
startsWith
(
TestBase
.
BASE_TEST_DIR
))
{
return
;
}
deleteDb
(
"optimizations"
);
InputStream
in
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"org/h2/samples/optimizations.sql"
);
new
File
(
baseDir
).
mkdirs
();
FileOutputStream
out
=
new
FileOutputStream
(
baseDir
+
"/optimizations.sql"
);
new
File
(
getBaseDir
()
).
mkdirs
();
FileOutputStream
out
=
new
FileOutputStream
(
getBaseDir
()
+
"/optimizations.sql"
);
IOUtils
.
copyAndClose
(
in
,
out
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/optimizations"
;
String
url
=
"jdbc:h2:"
+
getBaseDir
()
+
"/optimizations"
;
testApp
(
""
,
org
.
h2
.
tools
.
RunScript
.
class
,
"-url"
,
url
,
"-user"
,
"sa"
,
"-password"
,
"sa"
,
"-script"
,
baseDir
+
"/optimizations.sql"
,
"-checkResults"
);
getBaseDir
()
+
"/optimizations.sql"
,
"-checkResults"
);
deleteDb
(
"optimizations"
);
testApp
(
"Compacting...\nDone."
,
org
.
h2
.
samples
.
Compact
.
class
);
testApp
(
"NAME: Bob Meier\n"
+
"EMAIL: bob.meier@abcde.abc\n"
...
...
@@ -65,6 +68,7 @@ public class TestSampleApps extends TestBase {
org
.
h2
.
tools
.
ChangeFileEncryption
.
class
);
testApp
(
"Deletes all files belonging to a database.*"
,
org
.
h2
.
tools
.
DeleteDbFiles
.
class
,
"-help"
);
IOUtils
.
delete
(
getBaseDir
()
+
"/optimizations.sql"
);
}
private
void
testApp
(
String
expected
,
Class
<
?
>
clazz
,
String
...
args
)
throws
Exception
{
...
...
h2/src/test/org/h2/test/unit/TestServlet.java
浏览文件 @
b063c9cf
...
...
@@ -193,7 +193,7 @@ public class TestServlet extends TestBase {
stat1
.
execute
(
"CREATE TABLE T(ID INT)"
);
String
u2
=
url
.
substring
(
url
.
indexOf
(
"servlet"
));
u2
=
"jdbc:h2:tcp://localhost:8888/"
+
baseDir
+
"/"
+
u2
;
u2
=
"jdbc:h2:tcp://localhost:8888/"
+
getBaseDir
()
+
"/"
+
u2
;
Connection
conn2
=
DriverManager
.
getConnection
(
u2
,
getUser
(),
getPassword
());
Statement
stat2
=
conn2
.
createStatement
();
...
...
@@ -213,7 +213,7 @@ public class TestServlet extends TestBase {
// listener must be stopped
try
{
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost:8888/"
+
baseDir
+
"/servlet"
,
getUser
(),
getPassword
());
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost:8888/"
+
getBaseDir
()
+
"/servlet"
,
getUser
(),
getPassword
());
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
...
...
@@ -227,6 +227,8 @@ public class TestServlet extends TestBase {
assertKnownException
(
e
);
}
deleteDb
(
"servlet"
);
}
}
h2/src/test/org/h2/test/unit/TestStreams.java
浏览文件 @
b063c9cf
...
...
@@ -16,6 +16,7 @@ import java.util.Random;
import
org.h2.compress.LZFInputStream
;
import
org.h2.compress.LZFOutputStream
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
/**
* Tests the LZF stream.
...
...
@@ -52,7 +53,8 @@ public class TestStreams extends TestBase {
}
private
void
testLZFStreamClose
()
throws
IOException
{
String
fileName
=
getTestDir
(
""
)
+
"/temp"
;
String
fileName
=
getBaseDir
()
+
"/temp"
;
IOUtils
.
createDirs
(
fileName
);
LZFOutputStream
out
=
new
LZFOutputStream
(
new
FileOutputStream
(
fileName
));
out
.
write
(
"Hello"
.
getBytes
());
out
.
close
();
...
...
@@ -61,6 +63,7 @@ public class TestStreams extends TestBase {
assertEquals
(
5
,
in
.
read
(
buff
));
in
.
read
();
in
.
close
();
IOUtils
.
delete
(
getBaseDir
()
+
"/temp"
);
}
private
void
testLZFStreams
()
throws
IOException
{
...
...
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
b063c9cf
差异被折叠。
点击展开。
h2/src/test/org/h2/test/unit/TestValueMemory.java
浏览文件 @
b063c9cf
...
...
@@ -201,7 +201,7 @@ public class TestValueMemory extends TestBase implements DataHandler {
}
public
String
getDatabasePath
()
{
return
baseDir
+
"/valueMemory"
;
return
getBaseDir
()
+
"/valueMemory"
;
}
public
String
getLobCompressionAlgorithm
(
int
type
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论