Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1dd6fdda
提交
1dd6fdda
authored
9月 21, 2011
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved tests.
上级
413aeb82
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
149 行增加
和
14 行删除
+149
-14
FilePathDisk.java
h2/src/main/org/h2/store/fs/FilePathDisk.java
+12
-11
FilePathMem.java
h2/src/main/org/h2/store/fs/FilePathMem.java
+14
-1
FilePathNio.java
h2/src/main/org/h2/store/fs/FilePathNio.java
+1
-1
FilePathSplit.java
h2/src/main/org/h2/store/fs/FilePathSplit.java
+4
-0
FileUtils.java
h2/src/main/org/h2/store/fs/FileUtils.java
+0
-1
TestFileSystem.java
h2/src/test/org/h2/test/unit/TestFileSystem.java
+118
-0
没有找到文件。
h2/src/main/org/h2/store/fs/FilePathDisk.java
浏览文件 @
1dd6fdda
...
...
@@ -65,9 +65,6 @@ public class FilePathDisk extends FilePath {
* @return the native file name
*/
public
static
String
expandUserHomeDirectory
(
String
fileName
)
{
if
(
fileName
==
null
)
{
return
null
;
}
boolean
prefix
=
false
;
if
(
fileName
.
startsWith
(
"file:"
))
{
prefix
=
true
;
...
...
@@ -236,16 +233,20 @@ public class FilePathDisk extends FilePath {
public
void
createDirectory
()
{
File
f
=
new
File
(
name
);
if
(!
f
.
exists
())
{
File
dir
=
new
File
(
name
);
for
(
int
i
=
0
;
i
<
SysProperties
.
MAX_FILE_RETRY
;
i
++)
{
if
((
dir
.
exists
()
&&
dir
.
isDirectory
())
||
dir
.
mkdir
())
{
return
;
}
wait
(
i
);
if
(
f
.
exists
())
{
if
(
f
.
isDirectory
())
{
return
;
}
throw
DbException
.
get
(
ErrorCode
.
FILE_CREATION_FAILED_1
,
name
);
throw
DbException
.
get
(
ErrorCode
.
FILE_CREATION_FAILED_1
,
name
+
" (a file with this name already exists)"
);
}
File
dir
=
new
File
(
name
);
for
(
int
i
=
0
;
i
<
SysProperties
.
MAX_FILE_RETRY
;
i
++)
{
if
((
dir
.
exists
()
&&
dir
.
isDirectory
())
||
dir
.
mkdir
())
{
return
;
}
wait
(
i
);
}
throw
DbException
.
get
(
ErrorCode
.
FILE_CREATION_FAILED_1
,
name
);
}
public
OutputStream
newOutputStream
(
boolean
append
)
{
...
...
h2/src/main/org/h2/store/fs/FilePathMem.java
浏览文件 @
1dd6fdda
...
...
@@ -18,6 +18,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.TreeMap
;
import
org.h2.compress.CompressLZF
;
import
org.h2.constant.ErrorCode
;
import
org.h2.message.DbException
;
import
org.h2.util.MathUtils
;
import
org.h2.util.New
;
...
...
@@ -105,9 +106,14 @@ public class FilePathMem extends FilePath {
}
public
boolean
isDirectory
()
{
if
(
isRoot
())
{
return
true
;
}
// TODO in memory file system currently
// does not really support directories
return
false
;
synchronized
(
MEMORY_FILES
)
{
return
MEMORY_FILES
.
get
(
name
)
==
null
;
}
}
public
boolean
isAbsolute
()
{
...
...
@@ -124,6 +130,9 @@ public class FilePathMem extends FilePath {
}
public
void
createDirectory
()
{
if
(
exists
()
&&
isDirectory
())
{
throw
DbException
.
get
(
ErrorCode
.
FILE_CREATION_FAILED_1
,
name
+
" (a file with this name already exists)"
);
}
// TODO directories are not really supported
}
...
...
@@ -276,6 +285,10 @@ class FileMem extends FileBase {
return
null
;
}
public
String
toString
()
{
return
data
.
getName
();
}
}
/**
...
...
h2/src/main/org/h2/store/fs/FilePathNio.java
浏览文件 @
1dd6fdda
...
...
@@ -94,7 +94,7 @@ class FileNio extends FileBase {
}
public
String
toString
()
{
return
name
;
return
"nio:"
+
name
;
}
}
h2/src/main/org/h2/store/fs/FilePathSplit.java
浏览文件 @
1dd6fdda
...
...
@@ -374,4 +374,8 @@ class FileSplit extends FileBase {
return
list
[
0
].
tryLock
();
}
public
String
toString
()
{
return
file
.
toString
();
}
}
h2/src/main/org/h2/store/fs/FileUtils.java
浏览文件 @
1dd6fdda
...
...
@@ -363,5 +363,4 @@ public class FileUtils {
}
while
(
src
.
remaining
()
>
0
);
}
}
h2/src/test/org/h2/test/unit/TestFileSystem.java
浏览文件 @
1dd6fdda
...
...
@@ -15,6 +15,7 @@ import java.io.RandomAccessFile;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.nio.channels.FileLock
;
import
java.nio.channels.FileChannel.MapMode
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
...
...
@@ -23,6 +24,7 @@ import java.sql.Statement;
import
java.util.List
;
import
java.util.Random
;
import
org.h2.dev.fs.FilePathCrypt
;
import
org.h2.message.DbException
;
import
org.h2.store.fs.FilePath
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
...
...
@@ -48,6 +50,12 @@ public class TestFileSystem extends TestBase {
}
public
void
test
()
throws
Exception
{
testFileSystem
(
getBaseDir
()
+
"/fs"
);
testAbsoluteRelative
();
testDirectories
(
getBaseDir
());
testMoveTo
(
getBaseDir
());
testUnsupportedFeatures
(
getBaseDir
());
testMemFsDir
();
testClasspath
();
FilePathCrypt
.
register
();
...
...
@@ -85,6 +93,12 @@ public class TestFileSystem extends TestBase {
}
}
private
void
testAbsoluteRelative
()
{
assertTrue
(
FileUtils
.
isAbsolute
(
"/test/abc"
));
assertFalse
(
FileUtils
.
isAbsolute
(
"test/abc"
));
assertTrue
(
FileUtils
.
isAbsolute
(
"~/test/abc"
));
}
private
void
testMemFsDir
()
throws
IOException
{
FileUtils
.
newOutputStream
(
"memFS:data/test/a.txt"
,
false
).
close
();
assertEquals
(
1
,
FileUtils
.
newDirectoryStream
(
"memFS:data/test"
).
size
());
...
...
@@ -216,11 +230,114 @@ public class TestFileSystem extends TestBase {
}
private
void
testFileSystem
(
String
fsBase
)
throws
Exception
{
testSetReadOnly
(
fsBase
);
testParentEventuallyReturnsNull
(
fsBase
);
testSimple
(
fsBase
);
testTempFile
(
fsBase
);
testRandomAccess
(
fsBase
);
}
private
void
testSetReadOnly
(
String
fsBase
)
{
String
fileName
=
fsBase
+
"/testFile"
;
if
(
FileUtils
.
exists
(
fileName
))
{
FileUtils
.
delete
(
fileName
);
}
if
(
FileUtils
.
createFile
(
fileName
))
{
FileUtils
.
setReadOnly
(
fileName
);
assertFalse
(
FileUtils
.
canWrite
(
fileName
));
FileUtils
.
delete
(
fileName
);
}
}
private
void
testDirectories
(
String
fsBase
)
{
final
String
fileName
=
fsBase
+
"/testFile"
;
if
(
FileUtils
.
exists
(
fileName
))
{
FileUtils
.
delete
(
fileName
);
}
if
(
FileUtils
.
createFile
(
fileName
))
{
new
AssertThrows
(
DbException
.
class
)
{
public
void
test
()
{
FileUtils
.
createDirectory
(
fileName
);
}};
new
AssertThrows
(
DbException
.
class
)
{
public
void
test
()
{
FileUtils
.
createDirectories
(
fileName
+
"/test"
);
}};
FileUtils
.
delete
(
fileName
);
}
}
private
void
testMoveTo
(
String
fsBase
)
{
final
String
fileName
=
fsBase
+
"/testFile"
;
final
String
fileName2
=
fsBase
+
"/testFile2"
;
if
(
FileUtils
.
exists
(
fileName
))
{
FileUtils
.
delete
(
fileName
);
}
if
(
FileUtils
.
createFile
(
fileName
))
{
FileUtils
.
moveTo
(
fileName
,
fileName2
);
FileUtils
.
createFile
(
fileName
);
new
AssertThrows
(
DbException
.
class
)
{
public
void
test
()
{
FileUtils
.
moveTo
(
fileName2
,
fileName
);
}};
FileUtils
.
delete
(
fileName
);
FileUtils
.
delete
(
fileName2
);
new
AssertThrows
(
DbException
.
class
)
{
public
void
test
()
{
FileUtils
.
moveTo
(
fileName
,
fileName2
);
}};
}
}
private
void
testUnsupportedFeatures
(
String
fsBase
)
throws
IOException
{
final
String
fileName
=
fsBase
+
"/testFile"
;
if
(
FileUtils
.
exists
(
fileName
))
{
FileUtils
.
delete
(
fileName
);
}
if
(
FileUtils
.
createFile
(
fileName
))
{
final
FileChannel
channel
=
FileUtils
.
open
(
fileName
,
"rw"
);
new
AssertThrows
(
UnsupportedOperationException
.
class
)
{
public
void
test
()
throws
IOException
{
channel
.
map
(
MapMode
.
PRIVATE
,
0
,
channel
.
size
());
}};
new
AssertThrows
(
UnsupportedOperationException
.
class
)
{
public
void
test
()
throws
IOException
{
channel
.
read
(
ByteBuffer
.
allocate
(
10
),
0
);
}};
new
AssertThrows
(
UnsupportedOperationException
.
class
)
{
public
void
test
()
throws
IOException
{
channel
.
read
(
new
ByteBuffer
[]{
ByteBuffer
.
allocate
(
10
)},
0
,
0
);
}};
new
AssertThrows
(
UnsupportedOperationException
.
class
)
{
public
void
test
()
throws
IOException
{
channel
.
write
(
ByteBuffer
.
allocate
(
10
),
0
);
}};
new
AssertThrows
(
UnsupportedOperationException
.
class
)
{
public
void
test
()
throws
IOException
{
channel
.
write
(
new
ByteBuffer
[]{
ByteBuffer
.
allocate
(
10
)},
0
,
0
);
}};
new
AssertThrows
(
UnsupportedOperationException
.
class
)
{
public
void
test
()
throws
IOException
{
channel
.
transferFrom
(
channel
,
0
,
0
);
}};
new
AssertThrows
(
UnsupportedOperationException
.
class
)
{
public
void
test
()
throws
IOException
{
channel
.
transferTo
(
0
,
0
,
channel
);
}};
channel
.
close
();
FileUtils
.
delete
(
fileName
);
}
}
private
void
testParentEventuallyReturnsNull
(
String
fsBase
)
{
FilePath
p
=
FilePath
.
get
(
fsBase
+
"/testFile"
);
assertTrue
(
p
.
getScheme
().
length
()
>
0
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
if
(
p
==
null
)
{
return
;
}
p
=
p
.
getParent
();
}
fail
(
"Parent is not null: "
+
p
);
String
path
=
fsBase
+
"/testFile"
;
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
if
(
path
==
null
)
{
return
;
}
path
=
FileUtils
.
getParent
(
path
);
}
fail
(
"Parent is not null: "
+
path
);
}
private
void
testSimple
(
final
String
fsBase
)
throws
Exception
{
long
time
=
System
.
currentTimeMillis
();
for
(
String
s
:
FileUtils
.
newDirectoryStream
(
fsBase
))
{
...
...
@@ -326,6 +443,7 @@ public class TestFileSystem extends TestBase {
RandomAccessFile
ra
=
new
RandomAccessFile
(
file
,
"rw"
);
FileUtils
.
delete
(
s
);
FileChannel
f
=
FileUtils
.
open
(
s
,
"rw"
);
assertEquals
(
s
,
f
.
toString
());
assertEquals
(-
1
,
f
.
read
(
ByteBuffer
.
wrap
(
new
byte
[
1
])));
f
.
force
(
true
);
Random
random
=
new
Random
(
seed
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论