Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
3dd6a453
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3dd6a453
编写于
8月 08, 2012
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
Reviewed-by: alanb Contributed-by: amy.lu@oracle.com
上级
eeb618e0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
137 addition
and
83 deletion
+137
-83
test/java/nio/channels/AsynchronousChannelGroup/AsExecutor.java
...ava/nio/channels/AsynchronousChannelGroup/AsExecutor.java
+6
-0
test/java/nio/channels/AsynchronousChannelGroup/Basic.java
test/java/nio/channels/AsynchronousChannelGroup/Basic.java
+122
-80
test/java/nio/channels/AsynchronousChannelGroup/Restart.java
test/java/nio/channels/AsynchronousChannelGroup/Restart.java
+9
-3
未找到文件。
test/java/nio/channels/AsynchronousChannelGroup/AsExecutor.java
浏览文件 @
3dd6a453
...
...
@@ -37,24 +37,30 @@ public class AsExecutor {
.
withFixedThreadPool
(
5
,
factory
);
AsynchronousChannelGroup
group2
=
AsynchronousChannelGroup
.
withCachedThreadPool
(
Executors
.
newCachedThreadPool
(
factory
),
0
);
AsynchronousChannelGroup
group3
=
AsynchronousChannelGroup
.
withThreadPool
(
Executors
.
newFixedThreadPool
(
10
,
factory
));
try
{
// execute simple tasks
testSimpleTask
(
group1
);
testSimpleTask
(
group2
);
testSimpleTask
(
group3
);
// install security manager and test again
System
.
setSecurityManager
(
new
SecurityManager
()
);
testSimpleTask
(
group1
);
testSimpleTask
(
group2
);
testSimpleTask
(
group3
);
// attempt to execute tasks that run with only frames from boot
// class loader on the stack.
testAttackingTask
(
group1
);
testAttackingTask
(
group2
);
testAttackingTask
(
group3
);
}
finally
{
group1
.
shutdown
();
group2
.
shutdown
();
group3
.
shutdown
();
}
}
...
...
test/java/nio/channels/AsynchronousChannelGroup/Basic.java
浏览文件 @
3dd6a453
...
...
@@ -51,98 +51,135 @@ public class Basic {
miscTests
();
}
static
void
shutdownTests
()
throws
Exception
{
System
.
out
.
println
(
"-- test shutdown --"
);
static
void
testShutdownWithNoChannels
(
ExecutorService
pool
,
AsynchronousChannelGroup
group
)
throws
Exception
{
group
.
shutdown
();
if
(!
group
.
isShutdown
())
throw
new
RuntimeException
(
"Group should be shutdown"
);
// group should terminate quickly
boolean
terminated
=
group
.
awaitTermination
(
3
,
TimeUnit
.
SECONDS
);
if
(!
terminated
)
throw
new
RuntimeException
(
"Group should have terminated"
);
if
(
pool
!=
null
&&
!
pool
.
isTerminated
())
throw
new
RuntimeException
(
"Executor should have terminated"
);
}
// test shutdown with no channels in groups
for
(
int
i
=
0
;
i
<
500
;
i
++)
{
ExecutorService
pool
=
null
;
AsynchronousChannelGroup
group
;
if
(
rand
.
nextBoolean
())
{
pool
=
Executors
.
newCachedThreadPool
();
group
=
AsynchronousChannelGroup
.
withCachedThreadPool
(
pool
,
rand
.
nextInt
(
5
));
}
else
{
int
nThreads
=
1
+
rand
.
nextInt
(
8
);
group
=
AsynchronousChannelGroup
.
withFixedThreadPool
(
nThreads
,
threadFactory
);
}
group
.
shutdown
();
if
(!
group
.
isShutdown
())
throw
new
RuntimeException
(
"Group should be shutdown"
);
// group should terminate quickly
boolean
terminated
=
group
.
awaitTermination
(
3
,
TimeUnit
.
SECONDS
);
if
(!
terminated
)
throw
new
RuntimeException
(
"Group should have terminated"
);
if
(
pool
!=
null
&&
!
pool
.
isTerminated
())
throw
new
RuntimeException
(
"Executor should have terminated"
);
}
// shutdown with channel in group
for
(
int
i
=
0
;
i
<
500
;
i
++)
{
ExecutorService
pool
=
null
;
AsynchronousChannelGroup
group
;
if
(
rand
.
nextBoolean
())
{
pool
=
Executors
.
newCachedThreadPool
();
group
=
AsynchronousChannelGroup
.
withCachedThreadPool
(
pool
,
rand
.
nextInt
(
10
));
}
else
{
int
nThreads
=
1
+
rand
.
nextInt
(
8
);
group
=
AsynchronousChannelGroup
.
withFixedThreadPool
(
nThreads
,
threadFactory
);
}
// create channel that is bound to group
AsynchronousChannel
ch
;
switch
(
rand
.
nextInt
(
2
))
{
case
0
:
ch
=
AsynchronousSocketChannel
.
open
(
group
);
break
;
case
1
:
ch
=
AsynchronousServerSocketChannel
.
open
(
group
);
break
;
default
:
throw
new
AssertionError
();
}
group
.
shutdown
();
if
(!
group
.
isShutdown
())
throw
new
RuntimeException
(
"Group should be shutdown"
);
// last channel so should terminate after this channel is closed
ch
.
close
();
// group should terminate quickly
boolean
terminated
=
group
.
awaitTermination
(
3
,
TimeUnit
.
SECONDS
);
if
(!
terminated
)
throw
new
RuntimeException
(
"Group should have terminated"
);
if
(
pool
!=
null
&&
!
pool
.
isTerminated
())
throw
new
RuntimeException
(
"Executor should have terminated"
);
static
void
testShutdownWithChannels
(
ExecutorService
pool
,
AsynchronousChannelGroup
group
)
throws
Exception
{
// create channel that is bound to group
AsynchronousChannel
ch
;
switch
(
rand
.
nextInt
(
2
))
{
case
0
:
ch
=
AsynchronousSocketChannel
.
open
(
group
);
break
;
case
1
:
ch
=
AsynchronousServerSocketChannel
.
open
(
group
);
break
;
default
:
throw
new
AssertionError
();
}
group
.
shutdown
();
if
(!
group
.
isShutdown
())
throw
new
RuntimeException
(
"Group should be shutdown"
);
// last channel so should terminate after this channel is closed
ch
.
close
();
// group should terminate quickly
boolean
terminated
=
group
.
awaitTermination
(
3
,
TimeUnit
.
SECONDS
);
if
(!
terminated
)
throw
new
RuntimeException
(
"Group should have terminated"
);
if
(
pool
!=
null
&&
!
pool
.
isTerminated
())
throw
new
RuntimeException
(
"Executor should have terminated"
);
}
static
void
shutdown
Now
Tests
()
throws
Exception
{
System
.
out
.
println
(
"-- test shutdown
Now
--"
);
static
void
shutdownTests
()
throws
Exception
{
System
.
out
.
println
(
"-- test shutdown --"
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
ExecutorService
pool
=
null
;
AsynchronousChannelGroup
group
;
if
(
rand
.
nextBoolean
())
{
pool
=
Executors
.
newCachedThreadPool
();
group
=
AsynchronousChannelGroup
// test shutdown with no channels in groups
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
ExecutorService
pool
=
Executors
.
newCachedThreadPool
();
AsynchronousChannelGroup
group
=
AsynchronousChannelGroup
.
withCachedThreadPool
(
pool
,
rand
.
nextInt
(
5
));
}
else
{
int
nThreads
=
1
+
rand
.
nextInt
(
8
);
group
=
AsynchronousChannelGroup
testShutdownWithNoChannels
(
pool
,
group
);
}
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
int
nThreads
=
1
+
rand
.
nextInt
(
8
);
AsynchronousChannelGroup
group
=
AsynchronousChannelGroup
.
withFixedThreadPool
(
nThreads
,
threadFactory
);
testShutdownWithNoChannels
(
null
,
group
);
}
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
ExecutorService
pool
=
Executors
.
newCachedThreadPool
();
AsynchronousChannelGroup
group
=
AsynchronousChannelGroup
.
withThreadPool
(
pool
);
testShutdownWithNoChannels
(
pool
,
group
);
}
// test shutdown with channel in group
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
ExecutorService
pool
=
Executors
.
newCachedThreadPool
();
AsynchronousChannelGroup
group
=
AsynchronousChannelGroup
.
withCachedThreadPool
(
pool
,
rand
.
nextInt
(
10
));
testShutdownWithChannels
(
pool
,
group
);
}
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
int
nThreads
=
1
+
rand
.
nextInt
(
8
);
AsynchronousChannelGroup
group
=
AsynchronousChannelGroup
.
withFixedThreadPool
(
nThreads
,
threadFactory
);
}
testShutdownWithChannels
(
null
,
group
);
}
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
ExecutorService
pool
=
Executors
.
newCachedThreadPool
();
AsynchronousChannelGroup
group
=
AsynchronousChannelGroup
.
withThreadPool
(
pool
);
testShutdownWithChannels
(
pool
,
group
);
}
}
// I/O in progress
AsynchronousServerSocketChannel
ch
=
AsynchronousServerSocketChannel
static
void
testShutdownNow
(
ExecutorService
pool
,
AsynchronousChannelGroup
group
)
throws
Exception
{
// I/O in progress
AsynchronousServerSocketChannel
ch
=
AsynchronousServerSocketChannel
.
open
(
group
).
bind
(
new
InetSocketAddress
(
0
));
ch
.
accept
();
ch
.
accept
();
// forceful shutdown
group
.
shutdownNow
();
// forceful shutdown
group
.
shutdownNow
();
// shutdownNow is required to close all channels
if
(
ch
.
isOpen
())
throw
new
RuntimeException
(
"Channel should be closed"
);
boolean
terminated
=
group
.
awaitTermination
(
3
,
TimeUnit
.
SECONDS
);
if
(!
terminated
)
throw
new
RuntimeException
(
"Group should have terminated"
);
if
(
pool
!=
null
&&
!
pool
.
isTerminated
())
throw
new
RuntimeException
(
"Executor should have terminated"
);
}
// shutdownNow is required to close all channels
if
(
ch
.
isOpen
())
throw
new
RuntimeException
(
"Channel should be closed"
);
static
void
shutdownNowTests
()
throws
Exception
{
System
.
out
.
println
(
"-- test shutdownNow --"
);
boolean
terminated
=
group
.
awaitTermination
(
3
,
TimeUnit
.
SECONDS
);
if
(!
terminated
)
throw
new
RuntimeException
(
"Group should have terminated"
);
if
(
pool
!=
null
&&
!
pool
.
isTerminated
())
throw
new
RuntimeException
(
"Executor should have terminated"
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
ExecutorService
pool
=
pool
=
Executors
.
newCachedThreadPool
();
AsynchronousChannelGroup
group
=
AsynchronousChannelGroup
.
withCachedThreadPool
(
pool
,
rand
.
nextInt
(
5
));
testShutdownNow
(
pool
,
group
);
}
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
int
nThreads
=
1
+
rand
.
nextInt
(
8
);
AsynchronousChannelGroup
group
=
AsynchronousChannelGroup
.
withFixedThreadPool
(
nThreads
,
threadFactory
);
testShutdownNow
(
null
,
group
);
}
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
ExecutorService
pool
=
Executors
.
newCachedThreadPool
();
AsynchronousChannelGroup
group
=
AsynchronousChannelGroup
.
withThreadPool
(
pool
);
testShutdownNow
(
pool
,
group
);
}
}
...
...
@@ -245,5 +282,10 @@ public class Basic {
throw
new
RuntimeException
(
"NPE expected"
);
}
catch
(
NullPointerException
x
)
{
}
try
{
AsynchronousChannelGroup
.
withThreadPool
(
null
);
throw
new
RuntimeException
(
"NPE expected"
);
}
catch
(
NullPointerException
e
)
{
}
}
}
test/java/nio/channels/AsynchronousChannelGroup/Restart.java
浏览文件 @
3dd6a453
...
...
@@ -71,17 +71,23 @@ public class Restart {
testRestart
(
group
,
100
);
group
.
shutdown
();
// group with c
ustom
thread pool
// group with c
ached
thread pool
ExecutorService
pool
=
Executors
.
newCachedThreadPool
(
factory
);
group
=
AsynchronousChannelGroup
.
withCachedThreadPool
(
pool
,
rand
.
nextInt
(
5
));
testRestart
(
group
,
100
);
group
.
shutdown
();
// group with custom thread pool
group
=
AsynchronousChannelGroup
.
withThreadPool
(
Executors
.
newFixedThreadPool
(
1
+
rand
.
nextInt
(
5
),
factory
));
testRestart
(
group
,
100
);
group
.
shutdown
();
// give time for threads to terminate
Thread
.
sleep
(
3000
);
int
actual
=
exceptionCount
.
get
();
if
(
actual
!=
2
00
)
throw
new
RuntimeException
(
actual
+
" exceptions, expected: "
+
2
00
);
if
(
actual
!=
3
00
)
throw
new
RuntimeException
(
actual
+
" exceptions, expected: "
+
3
00
);
}
static
void
testRestart
(
AsynchronousChannelGroup
group
,
int
count
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录