--- a/test/hotspot/gtest/jfr/test_networkUtilization.cpp Thu Dec 13 11:05:22 2018 -0800
+++ b/test/hotspot/gtest/jfr/test_networkUtilization.cpp Fri Dec 14 01:34:13 2018 +0100
@@ -258,7 +258,7 @@
JfrNetworkUtilization::send_events();
ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size());
MockEventNetworkUtilization& e = MockEventNetworkUtilization::committed[0];
- EXPECT_EQ(5, e.readRate);
+ EXPECT_EQ(40, e.readRate);
EXPECT_EQ(0, e.writeRate);
EXPECT_STREQ("eth0", e.iface.c_str());
}
@@ -282,16 +282,16 @@
const MockEventNetworkUtilization& eth1_event = MockEventNetworkUtilization::get_committed("eth1");
const MockEventNetworkUtilization& ppp0_event = MockEventNetworkUtilization::get_committed("ppp0");
- EXPECT_EQ(5, eth0_event.readRate);
+ EXPECT_EQ(40, eth0_event.readRate);
EXPECT_EQ(0, eth0_event.writeRate);
EXPECT_STREQ("eth0", eth0_event.iface.c_str());
- EXPECT_EQ(50, eth1_event.readRate);
+ EXPECT_EQ(400, eth1_event.readRate);
EXPECT_EQ(0, eth1_event.writeRate);
EXPECT_STREQ("eth1", eth1_event.iface.c_str());
EXPECT_EQ(0, ppp0_event.readRate);
- EXPECT_EQ(25, ppp0_event.writeRate);
+ EXPECT_EQ(200, ppp0_event.writeRate);
EXPECT_STREQ("ppp0", ppp0_event.iface.c_str());
}
@@ -310,11 +310,11 @@
const MockEventNetworkUtilization& eth0_event = MockEventNetworkUtilization::get_committed("eth0");
const MockEventNetworkUtilization& eth1_event = MockEventNetworkUtilization::get_committed("eth1");
- EXPECT_EQ(5, eth0_event.readRate);
+ EXPECT_EQ(40, eth0_event.readRate);
EXPECT_EQ(0, eth0_event.writeRate);
EXPECT_STREQ("eth0", eth0_event.iface.c_str());
- EXPECT_EQ(10, eth1_event.readRate);
+ EXPECT_EQ(80, eth1_event.readRate);
EXPECT_EQ(0, eth1_event.writeRate);
EXPECT_STREQ("eth1", eth1_event.iface.c_str());
@@ -327,7 +327,7 @@
ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size());
const MockEventNetworkUtilization& eth1_event_v2 = MockEventNetworkUtilization::get_committed("eth1");
- EXPECT_EQ(5, eth1_event_v2.readRate);
+ EXPECT_EQ(40, eth1_event_v2.readRate);
EXPECT_EQ(0, eth1_event_v2.writeRate);
EXPECT_STREQ("eth1", eth1_event_v2.iface.c_str());
}
@@ -343,7 +343,7 @@
JfrNetworkUtilization::send_events();
ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size());
const MockEventNetworkUtilization& event = MockEventNetworkUtilization::committed[0];
- EXPECT_EQ(5, event.readRate);
+ EXPECT_EQ(40, event.readRate);
EXPECT_EQ(0, event.writeRate);
EXPECT_STREQ("eth0", event.iface.c_str());
@@ -360,7 +360,7 @@
JfrNetworkUtilization::send_events();
ASSERT_EQ(1u, MockEventNetworkUtilization::committed.size());
const MockEventNetworkUtilization& event_v2 = MockEventNetworkUtilization::committed[0];
- EXPECT_EQ(5, event_v2.readRate);
+ EXPECT_EQ(40, event_v2.readRate);
EXPECT_EQ(0, event_v2.writeRate);
EXPECT_STREQ("eth0", event_v2.iface.c_str());
}
--- a/test/hotspot/jtreg/applications/jcstress/JcstressRunner.java Thu Dec 13 11:05:22 2018 -0800
+++ b/test/hotspot/jtreg/applications/jcstress/JcstressRunner.java Fri Dec 14 01:34:13 2018 +0100
@@ -89,6 +89,11 @@
private static String[] getCmd(String[] args) {
List<String> extraFlags = new ArrayList<>();
+ // java.io.tmpdir is set for both harness and forked VM so temporary files
+ // created like this File.createTempFile("jcstress", "stdout");
+ // don't pollute temporary directories
+ extraFlags.add("-Djava.io.tmpdir=" + System.getProperty("user.dir"));
+
// add jar with jcstress tests and harness to CP
extraFlags.add("-cp");
extraFlags.add(System.getProperty("java.class.path")
@@ -97,16 +102,11 @@
extraFlags.add(MAIN_CLASS);
- String[] javaOpts = Utils.getTestJavaOpts();
- // disable flags auto-detection
- if (0 == javaOpts.length) {
+ extraFlags.add("--jvmArgs");
+ extraFlags.add("-Djava.io.tmpdir=" + System.getProperty("user.dir"));
+ for (String jvmArg : Utils.getTestJavaOpts()) {
extraFlags.add("--jvmArgs");
- extraFlags.add("");
- } else {
- for (String jvmArg : Utils.getTestJavaOpts()) {
- extraFlags.add("--jvmArgs");
- extraFlags.add(jvmArg);
- }
+ extraFlags.add(jvmArg);
}
String[] result = new String[extraFlags.size() + args.length];
--- a/test/jdk/jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java Thu Dec 13 11:05:22 2018 -0800
+++ b/test/jdk/jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java Fri Dec 14 01:34:13 2018 +0100
@@ -25,6 +25,13 @@
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.consumer.RecordedEvent;
import jdk.test.lib.Asserts;
@@ -32,17 +39,6 @@
import jdk.test.lib.jfr.EventNames;
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
* @key jfr
@@ -56,21 +52,17 @@
private static final long packetSendCount = 100;
public static void main(String[] args) throws Throwable {
- testSimple();
- }
- static void testSimple() throws Throwable {
-
- Instant start = Instant.now();
Recording recording = new Recording();
- recording.enable(EventNames.NetworkUtilization);
+ recording.enable(EventNames.NetworkUtilization).with("period", "endChunk");
recording.start();
DatagramSocket socket = new DatagramSocket();
String msg = "hello!";
byte[] buf = msg.getBytes();
-
- // Send a few packets both to the loopback address as well to an external
+ forceEndChunk();
+ // Send a few packets both to the loopback address as well to an
+ // external
DatagramPacket packet = new DatagramPacket(buf, buf.length, InetAddress.getLoopbackAddress(), 12345);
for (int i = 0; i < packetSendCount; ++i) {
socket.send(packet);
@@ -79,32 +71,38 @@
for (int i = 0; i < packetSendCount; ++i) {
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();
- Duration runtime = Duration.between(start, Instant.now());
- List<RecordedEvent> events = Events.fromRecording(recording);
- // Calculate the average write rate for each interface
- Map<String, Double> writeRates = events.stream()
- .collect(groupingBy(e -> Events.assertField(e, "networkInterface").getValue(),
- averagingLong(e -> Events.assertField(e, "writeRate").getValue())));
-
- // Our test packets should have generated at least this much traffic per second
- long expectedTraffic = (buf.length * packetSendCount) / Math.max(1, runtime.toSeconds());
-
- // Count the number of interfaces that have seen at least our test traffic
- long interfacesWithTraffic = writeRates.values().stream()
- .filter(d -> d >= expectedTraffic)
- .count();
+ Set<String> networkInterfaces = new HashSet<>();
+ List<RecordedEvent> events = Events.fromRecording(recording);
+ Events.hasEvents(events);
+ for (RecordedEvent event : events) {
+ System.out.println(event);
+ Events.assertField(event, "writeRate").atLeast(0L).atMost(1000L * Integer.MAX_VALUE);
+ Events.assertField(event, "readRate").atLeast(0L).atMost(1000L * Integer.MAX_VALUE);
+ Events.assertField(event, "networkInterface").notNull();
+ if (event.getLong("writeRate") > 0) {
+ networkInterfaces.add(event.getString("networkInterface"));
+ }
+ }
if (Platform.isWindows() || Platform.isSolaris()) {
- // Windows and Solaris do not track statistics for the loopback interface
- Asserts.assertGreaterThanOrEqual(writeRates.size(), 1);
- Asserts.assertGreaterThanOrEqual(interfacesWithTraffic, Long.valueOf(1));
+ // Windows and Solaris do not track statistics for the loopback
+ // interface
+ Asserts.assertGreaterThanOrEqual(networkInterfaces.size(), 1);
} else {
- Asserts.assertGreaterThanOrEqual(writeRates.size(), 2);
- Asserts.assertGreaterThanOrEqual(interfacesWithTraffic, Long.valueOf(2));
+ Asserts.assertGreaterThanOrEqual(networkInterfaces.size(), 2);
}
}
+
+ private static void forceEndChunk() {
+ try(Recording r = new Recording()) {
+ r.start();
+ r.stop();
+ }
+ }
}