< prev index next >

test/jdk/jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java

Print this page
rev 56416 : 8229370: make jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java more stable

*** 1,7 **** /* ! * Copyright (c) 2018, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 23,38 **** --- 23,41 ---- * questions. */ 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; import jdk.test.lib.Asserts; import jdk.test.lib.Platform;
*** 43,85 **** * @test * @key jfr * @requires vm.hasJFR * @library /test/lib * ! * @run main/othervm jdk.jfr.event.runtime.TestNetworkUtilizationEvent */ public class TestNetworkUtilizationEvent { private static final long packetSendCount = 100; public static void main(String[] args) throws Throwable { Recording recording = new Recording(); recording.enable(EventNames.NetworkUtilization).with("period", "endChunk"); recording.start(); DatagramSocket socket = new DatagramSocket(); 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); 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); } forceEndChunk(); socket.close(); ! // Now there should have been traffic on at least two different ! // interfaces recording.stop(); - 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); --- 46,101 ---- * @test * @key jfr * @requires vm.hasJFR * @library /test/lib * ! * @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<String> networkInterfaces = new HashSet<>(); Recording recording = new Recording(); recording.enable(EventNames.NetworkUtilization).with("period", "endChunk"); recording.start(); DatagramSocket socket = new DatagramSocket(); String msg = "hello!"; byte[] buf = msg.getBytes(); forceEndChunk(); ! // 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); } ! ! Stream<InetAddress> 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 recording.stop(); 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);
*** 88,103 **** 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(networkInterfaces.size(), 1); } else { ! Asserts.assertGreaterThanOrEqual(networkInterfaces.size(), 2); } } private static void forceEndChunk() { try(Recording r = new Recording()) { --- 104,120 ---- if (event.getLong("writeRate") > 0) { networkInterfaces.add(event.getString("networkInterface")); } } + 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, "Not enough network interfaces found"); } else { ! Asserts.assertGreaterThanOrEqual(networkInterfaces.size(), 2, "Not enough network interfaces found"); } } private static void forceEndChunk() { try(Recording r = new Recording()) {
< prev index next >