# HG changeset patch # User mbaesken # Date 1569580600 -7200 # Fri Sep 27 12:36:40 2019 +0200 # Node ID 63ba0feab7b335377650d36049dfaf009d2ee7d4 # Parent feff88c680828a75ff1e279b52d9e5e9a874d2eb 8229370: make jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java more stable diff --git a/src/hotspot/share/jfr/periodic/jfrNetworkUtilization.cpp b/src/hotspot/share/jfr/periodic/jfrNetworkUtilization.cpp --- a/src/hotspot/share/jfr/periodic/jfrNetworkUtilization.cpp +++ b/src/hotspot/share/jfr/periodic/jfrNetworkUtilization.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -169,6 +169,8 @@ const uint64_t read_rate = rate_per_second(current_bytes_in, entry.bytes_in, interval); const uint64_t write_rate = rate_per_second(current_bytes_out, entry.bytes_out, interval); if (read_rate > 0 || write_rate > 0) { + log_trace(jfr, event)("found data for NetworkInterface %s (read_rate %llu, write_rate %llu)", cur->get_name(), + (long long unsigned) read_rate, (long long unsigned) write_rate); entry.in_use = true; EventNetworkUtilization event(UNTIMED); event.set_starttime(cur_time); diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -882,7 +882,7 @@ jdk/jfr/event/io/TestInstrumentation.java 8202142 generic-all jdk/jfr/api/recording/event/TestPeriod.java 8215890 generic-all jdk/jfr/event/io/EvilInstrument.java 8221331 generic-all -jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java 8228990,8229370 generic-all +# jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java 8228990,8229370 generic-all jdk/jfr/event/compiler/TestCodeSweeper.java 8225209 generic-all ############################################################################ diff --git a/test/jdk/jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java b/test/jdk/jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java --- a/test/jdk/jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java +++ b/test/jdk/jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,12 +25,15 @@ package jdk.jfr.event.runtime; +import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; +import java.net.NetworkInterface; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Stream; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedEvent; @@ -45,13 +48,14 @@ * @requires vm.hasJFR * @library /test/lib * - * @run main/othervm jdk.jfr.event.runtime.TestNetworkUtilizationEvent + * @run main/othervm -Xlog:jfr+event=trace jdk.jfr.event.runtime.TestNetworkUtilizationEvent */ public class TestNetworkUtilizationEvent { private static final long packetSendCount = 100; public static void main(String[] args) throws Throwable { + Set networkInterfaces = new HashSet<>(); Recording recording = new Recording(); recording.enable(EventNames.NetworkUtilization).with("period", "endChunk"); @@ -61,23 +65,35 @@ String msg = "hello!"; byte[] buf = msg.getBytes(); 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); + // Send a few packets both to the loopback address as well to an external + InetAddress iadr1 = InetAddress.getLoopbackAddress(); + System.out.println("InetAddress.getLoopbackAddress :" + iadr1 + " host address:" + iadr1.getHostAddress()); + + DatagramPacket packet = new DatagramPacket(buf, buf.length, iadr1, 12345); for (int i = 0; i < packetSendCount; ++i) { socket.send(packet); } - packet = new DatagramPacket(buf, buf.length, InetAddress.getByName("10.0.0.0"), 12345); - for (int i = 0; i < packetSendCount; ++i) { - socket.send(packet); - } + + Stream si = NetworkInterface.networkInterfaces().flatMap(NetworkInterface::inetAddresses); + si.forEach(inetAddr->{ + System.out.println("Sending to InetAddress:" + inetAddr); + try { + java.util.concurrent.TimeUnit.SECONDS.sleep(1); + } catch (InterruptedException e) { } + try { + final DatagramPacket packet2 = new DatagramPacket(buf, buf.length, inetAddr, 12345); + for (int i = 0; i < packetSendCount; ++i) { + socket.send(packet2); + } + } catch(IOException ioe) { + } + }); + forceEndChunk(); socket.close(); - // Now there should have been traffic on at least two different - // interfaces + // Now there should have been traffic on at least two different interfaces recording.stop(); - Set networkInterfaces = new HashSet<>(); List events = Events.fromRecording(recording); Events.hasEvents(events); for (RecordedEvent event : events) { @@ -90,12 +106,13 @@ } } + System.out.println("number of network interfaces with positive writeRate found is " + networkInterfaces.size()); + if (Platform.isWindows() || Platform.isSolaris()) { - // Windows and Solaris do not track statistics for the loopback - // interface - Asserts.assertGreaterThanOrEqual(networkInterfaces.size(), 1); + // Windows and Solaris do not track statistics for the loopback interface + Asserts.assertGreaterThanOrEqual(networkInterfaces.size(), 1, "Not enough network interfaces found"); } else { - Asserts.assertGreaterThanOrEqual(networkInterfaces.size(), 2); + Asserts.assertGreaterThanOrEqual(networkInterfaces.size(), 2, "Not enough network interfaces found"); } }