Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
9a59916c
提交
9a59916c
authored
7月 31, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore: move background exception listener and page size to the builder
上级
f9992a9a
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
56 行增加
和
14 行删除
+56
-14
TestMVStore.java
h2/src/test/org/h2/test/store/TestMVStore.java
+56
-14
没有找到文件。
h2/src/test/org/h2/test/store/TestMVStore.java
浏览文件 @
9a59916c
...
...
@@ -5,6 +5,7 @@
*/
package
org
.
h2
.
test
.
store
;
import
java.beans.ExceptionListener
;
import
java.io.IOException
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
...
...
@@ -12,6 +13,7 @@ import java.util.Iterator;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.TreeMap
;
import
java.util.concurrent.atomic.AtomicReference
;
import
org.h2.mvstore.Cursor
;
import
org.h2.mvstore.DataUtils
;
...
...
@@ -46,6 +48,7 @@ public class TestMVStore extends TestBase {
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
FileUtils
.
createDirectories
(
getBaseDir
());
testBackgroundExceptionListener
();
testOldVersion
();
testAtomicOperations
();
testWriteBuffer
();
...
...
@@ -88,6 +91,42 @@ public class TestMVStore extends TestBase {
testLargerThan2G
();
}
private
void
testBackgroundExceptionListener
()
throws
Exception
{
String
fileName
=
getBaseDir
()
+
"/testBackgroundExceptionListener.h3"
;
FileUtils
.
delete
(
fileName
);
MVStore
s
;
final
AtomicReference
<
Exception
>
exRef
=
new
AtomicReference
<
Exception
>();
s
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
writeDelay
(
2
).
backgroundExceptionListener
(
new
ExceptionListener
()
{
@Override
public
void
exceptionThrown
(
Exception
e
)
{
exRef
.
set
(
e
);
}
}).
open
();
MVMap
<
Integer
,
String
>
m
;
m
=
s
.
openMap
(
"data"
);
s
.
getFile
().
close
();
m
.
put
(
1
,
"Hello"
);
s
.
commit
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
if
(
exRef
.
get
()
!=
null
)
{
break
;
}
Thread
.
sleep
(
1
);
}
Exception
e
=
exRef
.
get
();
assertTrue
(
e
!=
null
);
assertEquals
(
DataUtils
.
ERROR_WRITING_FAILED
,
DataUtils
.
getErrorCode
(
e
.
getMessage
()));
s
.
close
();
FileUtils
.
delete
(
fileName
);
}
private
void
testAtomicOperations
()
{
String
fileName
=
getBaseDir
()
+
"/testAtomicOperations.h3"
;
FileUtils
.
delete
(
fileName
);
...
...
@@ -480,8 +519,7 @@ public class TestMVStore extends TestBase {
}
private
void
testIndexSkip
()
{
MVStore
s
=
openStore
(
null
);
s
.
setPageSize
(
4
);
MVStore
s
=
openStore
(
null
,
4
);
MVMap
<
Integer
,
Integer
>
map
=
s
.
openMap
(
"test"
);
for
(
int
i
=
0
;
i
<
100
;
i
+=
2
)
{
map
.
put
(
i
,
10
*
i
);
...
...
@@ -559,8 +597,7 @@ public class TestMVStore extends TestBase {
assertNull
(
m
.
floorKey
(
null
));
for
(
int
i
=
3
;
i
<
20
;
i
++)
{
s
=
openStore
(
null
);
s
.
setPageSize
(
4
);
s
=
openStore
(
null
,
4
);
map
=
s
.
openMap
(
"test"
);
for
(
int
j
=
3
;
j
<
i
;
j
++)
{
map
.
put
(
j
*
2
,
j
*
20
);
...
...
@@ -858,8 +895,7 @@ public class TestMVStore extends TestBase {
FileUtils
.
delete
(
fileName
);
MVStore
s
;
MVMap
<
Integer
,
String
>
m
;
s
=
openStore
(
fileName
);
s
.
setPageSize
(
700
);
s
=
openStore
(
fileName
,
700
);
m
=
s
.
openMap
(
"data"
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
m
.
put
(
i
,
"Hello World"
);
...
...
@@ -975,9 +1011,8 @@ public class TestMVStore extends TestBase {
private
void
testRollbackInMemory
()
{
String
fileName
=
getBaseDir
()
+
"/testRollback.h3"
;
FileUtils
.
delete
(
fileName
);
MVStore
s
=
openStore
(
fileName
);
MVStore
s
=
openStore
(
fileName
,
5
);
assertEquals
(
0
,
s
.
getCurrentVersion
());
s
.
setPageSize
(
5
);
MVMap
<
String
,
String
>
m
=
s
.
openMap
(
"data"
);
s
.
rollbackTo
(
0
);
assertTrue
(
m
.
isClosed
());
...
...
@@ -1084,9 +1119,7 @@ public class TestMVStore extends TestBase {
int
len
=
1000
;
for
(
int
j
=
0
;
j
<
5
;
j
++)
{
FileUtils
.
delete
(
fileName
);
MVStore
s
=
openStore
(
fileName
);
// s.setCompressor(null);
s
.
setPageSize
(
40
);
MVStore
s
=
openStore
(
fileName
,
40
);
MVMap
<
Integer
,
Object
[]>
m
=
s
.
openMap
(
"data"
,
new
MVMap
.
Builder
<
Integer
,
Object
[]>()
.
valueType
(
new
RowDataType
(
new
DataType
[]
{
...
...
@@ -1437,13 +1470,22 @@ public class TestMVStore extends TestBase {
* @return the store
*/
protected
static
MVStore
openStore
(
String
fileName
)
{
return
openStore
(
fileName
,
1000
);
}
/**
* Open a store for the given file name, using a small page size.
*
* @param fileName the file name (null for in-memory)
* @param pageSize the page size
* @return the store
*/
protected
static
MVStore
openStore
(
String
fileName
,
int
pageSize
)
{
MVStore
store
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
open
();
store
.
setPageSize
(
1000
);
fileName
(
fileName
).
pageSize
(
pageSize
).
open
();
return
store
;
}
/**
* Log the message.
*
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论