Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
3d1e902f
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看板
提交
3d1e902f
编写于
12月 13, 2018
作者:
E
egahlin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8215362: JFR GTest JfrTestNetworkUtilization fails
Reviewed-by: mgronlun
上级
a0166f4d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
39 deletion
+37
-39
test/jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java
test/jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java
+37
-39
未找到文件。
test/jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java
浏览文件 @
3d1e902f
...
@@ -25,6 +25,13 @@
...
@@ -25,6 +25,13 @@
package
jdk.jfr.event.runtime
;
package
jdk.jfr.event.runtime
;
import
java.net.DatagramPacket
;
import
java.net.DatagramSocket
;
import
java.net.InetAddress
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
jdk.jfr.Recording
;
import
jdk.jfr.Recording
;
import
jdk.jfr.consumer.RecordedEvent
;
import
jdk.jfr.consumer.RecordedEvent
;
import
jdk.test.lib.Asserts
;
import
jdk.test.lib.Asserts
;
...
@@ -32,17 +39,6 @@ import jdk.test.lib.Platform;
...
@@ -32,17 +39,6 @@ import jdk.test.lib.Platform;
import
jdk.test.lib.jfr.EventNames
;
import
jdk.test.lib.jfr.EventNames
;
import
jdk.test.lib.jfr.Events
;
import
jdk.test.lib.jfr.Events
;
import
java.net.DatagramPacket
;
import
java.net.DatagramSocket
;
import
java.net.InetAddress
;
import
java.time.Duration
;
import
java.time.Instant
;
import
java.util.List
;
import
java.util.Map
;
import
static
java
.
util
.
stream
.
Collectors
.
averagingLong
;
import
static
java
.
util
.
stream
.
Collectors
.
groupingBy
;
/**
/**
* @test
* @test
* @key jfr
* @key jfr
...
@@ -56,21 +52,17 @@ public class TestNetworkUtilizationEvent {
...
@@ -56,21 +52,17 @@ public class TestNetworkUtilizationEvent {
private
static
final
long
packetSendCount
=
100
;
private
static
final
long
packetSendCount
=
100
;
public
static
void
main
(
String
[]
args
)
throws
Throwable
{
public
static
void
main
(
String
[]
args
)
throws
Throwable
{
testSimple
();
}
static
void
testSimple
()
throws
Throwable
{
Instant
start
=
Instant
.
now
();
Recording
recording
=
new
Recording
();
Recording
recording
=
new
Recording
();
recording
.
enable
(
EventNames
.
NetworkUtilization
);
recording
.
enable
(
EventNames
.
NetworkUtilization
)
.
with
(
"period"
,
"endChunk"
)
;
recording
.
start
();
recording
.
start
();
DatagramSocket
socket
=
new
DatagramSocket
();
DatagramSocket
socket
=
new
DatagramSocket
();
String
msg
=
"hello!"
;
String
msg
=
"hello!"
;
byte
[]
buf
=
msg
.
getBytes
();
byte
[]
buf
=
msg
.
getBytes
();
forceEndChunk
();
// Send a few packets both to the loopback address as well to an external
// Send a few packets both to the loopback address as well to an
// external
DatagramPacket
packet
=
new
DatagramPacket
(
buf
,
buf
.
length
,
InetAddress
.
getLoopbackAddress
(),
12345
);
DatagramPacket
packet
=
new
DatagramPacket
(
buf
,
buf
.
length
,
InetAddress
.
getLoopbackAddress
(),
12345
);
for
(
int
i
=
0
;
i
<
packetSendCount
;
++
i
)
{
for
(
int
i
=
0
;
i
<
packetSendCount
;
++
i
)
{
socket
.
send
(
packet
);
socket
.
send
(
packet
);
...
@@ -80,31 +72,37 @@ public class TestNetworkUtilizationEvent {
...
@@ -80,31 +72,37 @@ public class TestNetworkUtilizationEvent {
socket
.
send
(
packet
);
socket
.
send
(
packet
);
}
}
// Now there should have been traffic on at least two different interfaces
forceEndChunk
();
socket
.
close
();
// Now there should have been traffic on at least two different
// interfaces
recording
.
stop
();
recording
.
stop
();
Duration
runtime
=
Duration
.
between
(
start
,
Instant
.
now
()
);
Set
<
String
>
networkInterfaces
=
new
HashSet
<>(
);
List
<
RecordedEvent
>
events
=
Events
.
fromRecording
(
recording
);
List
<
RecordedEvent
>
events
=
Events
.
fromRecording
(
recording
);
Events
.
hasEvents
(
events
);
// Calculate the average write rate for each interface
for
(
RecordedEvent
event
:
events
)
{
Map
<
String
,
Double
>
writeRates
=
events
.
stream
()
System
.
out
.
println
(
event
);
.
collect
(
groupingBy
(
e
->
Events
.
assertField
(
e
,
"networkInterface"
).
getValue
(),
Events
.
assertField
(
event
,
"writeRate"
).
atLeast
(
0L
).
atMost
(
1000L
*
Integer
.
MAX_VALUE
);
averagingLong
(
e
->
Events
.
assertField
(
e
,
"writeRate"
).
getValue
())));
Events
.
assertField
(
event
,
"readRate"
).
atLeast
(
0L
).
atMost
(
1000L
*
Integer
.
MAX_VALUE
);
Events
.
assertField
(
event
,
"networkInterface"
).
notNull
();
// Our test packets should have generated at least this much traffic per second
if
(
event
.
getLong
(
"writeRate"
)
>
0
)
{
long
expectedTraffic
=
(
buf
.
length
*
packetSendCount
)
/
Math
.
max
((
long
)
1
,
runtime
.
getSeconds
());
networkInterfaces
.
add
(
event
.
getString
(
"networkInterface"
));
}
// Count the number of interfaces that have seen at least our test traffic
}
long
interfacesWithTraffic
=
writeRates
.
values
().
stream
()
.
filter
(
d
->
d
>=
expectedTraffic
)
.
count
();
if
(
Platform
.
isWindows
()
||
Platform
.
isSolaris
())
{
if
(
Platform
.
isWindows
()
||
Platform
.
isSolaris
())
{
// Windows and Solaris do not track statistics for the loopback
interface
// Windows and Solaris do not track statistics for the loopback
Asserts
.
assertGreaterThanOrEqual
(
writeRates
.
size
(),
1
);
// interface
Asserts
.
assertGreaterThanOrEqual
(
interfacesWithTraffic
,
Long
.
valueOf
(
1
)
);
Asserts
.
assertGreaterThanOrEqual
(
networkInterfaces
.
size
(),
1
);
}
else
{
}
else
{
Asserts
.
assertGreaterThanOrEqual
(
writeRates
.
size
(),
2
);
Asserts
.
assertGreaterThanOrEqual
(
networkInterfaces
.
size
(),
2
);
Asserts
.
assertGreaterThanOrEqual
(
interfacesWithTraffic
,
Long
.
valueOf
(
2
));
}
}
private
static
void
forceEndChunk
()
{
try
(
Recording
r
=
new
Recording
())
{
r
.
start
();
r
.
stop
();
}
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录