Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
766288ac
提交
766288ac
authored
2月 10, 2018
作者:
andrei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TestOutOfMemory improvements: propagate OOM from background thread
上级
bc763b82
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
51 行增加
和
38 行删除
+51
-38
TestOutOfMemory.java
h2/src/test/org/h2/test/db/TestOutOfMemory.java
+51
-38
没有找到文件。
h2/src/test/org/h2/test/db/TestOutOfMemory.java
浏览文件 @
766288ac
...
...
@@ -13,6 +13,7 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.concurrent.atomic.AtomicReference
;
import
org.h2.api.ErrorCode
;
import
org.h2.mvstore.MVStore
;
import
org.h2.store.fs.FilePath
;
...
...
@@ -37,10 +38,6 @@ public class TestOutOfMemory extends TestBase {
@Override
public
void
test
()
throws
SQLException
,
InterruptedException
{
if
(
config
.
travis
)
{
// fails regularly under Travis, not sure why
return
;
}
if
(
config
.
vmlens
)
{
// running out of memory will cause the vmlens agent to stop working
return
;
...
...
@@ -60,7 +57,16 @@ public class TestOutOfMemory extends TestBase {
private
void
testMVStoreUsingInMemoryFileSystem
()
{
FilePath
.
register
(
new
FilePathMem
());
String
fileName
=
"memFS:"
+
getTestName
();
MVStore
store
=
MVStore
.
open
(
fileName
);
final
AtomicReference
<
Throwable
>
exRef
=
new
AtomicReference
<>();
MVStore
store
=
new
MVStore
.
Builder
()
.
fileName
(
fileName
)
.
backgroundExceptionHandler
(
new
Thread
.
UncaughtExceptionHandler
()
{
@Override
public
void
uncaughtException
(
Thread
t
,
Throwable
e
)
{
exRef
.
compareAndSet
(
null
,
e
);
}
})
.
open
();
try
{
Map
<
Integer
,
byte
[]>
map
=
store
.
openMap
(
"test"
);
Random
r
=
new
Random
(
1
);
...
...
@@ -70,10 +76,11 @@ public class TestOutOfMemory extends TestBase {
r
.
nextBytes
(
data
);
map
.
put
(
i
,
data
);
}
Throwable
throwable
=
exRef
.
get
();
if
(
throwable
instanceof
OutOfMemoryError
)
throw
(
OutOfMemoryError
)
throwable
;
if
(
throwable
instanceof
IllegalStateException
)
throw
(
IllegalStateException
)
throwable
;
fail
();
}
catch
(
OutOfMemoryError
e
)
{
// expected
}
catch
(
IllegalStateException
e
)
{
}
catch
(
OutOfMemoryError
|
IllegalStateException
e
)
{
// expected
}
try
{
...
...
@@ -83,7 +90,7 @@ public class TestOutOfMemory extends TestBase {
}
store
.
closeImmediately
();
store
=
MVStore
.
open
(
fileName
);
map
=
store
.
openMap
(
"test"
);
store
.
openMap
(
"test"
);
store
.
close
();
}
finally
{
// just in case, otherwise if this test suffers a spurious failure,
...
...
@@ -95,37 +102,43 @@ public class TestOutOfMemory extends TestBase {
private
void
testDatabaseUsingInMemoryFileSystem
()
throws
SQLException
,
InterruptedException
{
String
filename
=
"memFS:"
+
getTestName
();
String
url
=
"jdbc:h2:"
+
filename
;
Connection
conn
=
DriverManager
.
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"create table test(id int, name varchar) as "
+
"select x, space(10000000) from system_range(1, 1000)"
);
fail
();
}
catch
(
SQLException
e
)
{
int
err
=
e
.
getErrorCode
();
assertTrue
(
e
.
getMessage
(),
err
==
ErrorCode
.
GENERAL_ERROR_1
||
err
==
ErrorCode
.
OUT_OF_MEMORY
);
}
String
url
=
"jdbc:h2:"
+
filename
+
"/test"
;
try
{
Connection
conn
=
DriverManager
.
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"create table test(id int, name varchar) as "
+
"select x, space(10000000+x) from system_range(1, 1000)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertTrue
(
"Unexpected error code: "
+
e
.
getErrorCode
(),
ErrorCode
.
OUT_OF_MEMORY
==
e
.
getErrorCode
()
||
ErrorCode
.
FILE_CORRUPTED_1
==
e
.
getErrorCode
()
||
ErrorCode
.
DATABASE_IS_CLOSED
==
e
.
getErrorCode
()
||
ErrorCode
.
GENERAL_ERROR_1
==
e
.
getErrorCode
());
}
try
{
conn
.
close
();
fail
();
}
catch
(
SQLException
e
)
{
assertTrue
(
"Unexpected error code: "
+
e
.
getErrorCode
(),
ErrorCode
.
OUT_OF_MEMORY
==
e
.
getErrorCode
()
||
ErrorCode
.
FILE_CORRUPTED_1
==
e
.
getErrorCode
()
||
ErrorCode
.
DATABASE_IS_CLOSED
==
e
.
getErrorCode
()
||
ErrorCode
.
GENERAL_ERROR_1
==
e
.
getErrorCode
());
}
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
System
.
gc
();
Thread
.
sleep
(
20
);
}
conn
=
DriverManager
.
getConnection
(
url
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT 1"
);
conn
.
close
();
fail
();
}
catch
(
SQLException
e
)
{
int
err
=
e
.
getErrorCode
();
assertTrue
(
e
.
getMessage
(),
err
==
ErrorCode
.
GENERAL_ERROR_1
||
err
==
ErrorCode
.
OUT_OF_MEMORY
||
err
==
ErrorCode
.
DATABASE_IS_CLOSED
);
}
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
System
.
gc
();
Thread
.
sleep
(
20
);
}
finally
{
// release the static data this test generates
FileUtils
.
deleteRecursive
(
filename
,
true
);
}
conn
=
DriverManager
.
getConnection
(
url
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"select 1"
);
conn
.
close
();
// release the static data this test generates
FileUtils
.
delete
(
filename
);
}
private
void
testUpdateWhenNearlyOutOfMemory
()
throws
SQLException
,
InterruptedException
{
...
...
@@ -160,7 +173,7 @@ public class TestOutOfMemory extends TestBase {
}
catch
(
OutOfMemoryError
e
)
{
freeMemory
();
// out of memory not detected
throw
(
Error
)
new
AssertionError
(
"Out of memory not detected"
).
initCause
(
e
);
throw
new
AssertionError
(
"Out of memory not detected"
,
e
);
}
finally
{
freeMemory
();
if
(
conn
!=
null
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论