Path: blob/master/test/jdk/sun/management/jdp/JdpOnTestCase.java
41149 views
/*1* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* A JVM with JDP on should send multicast JDP packets regularly.25*26* See main for more information on running this test manually.27* See Launcher classes for automated runs.28*29*/3031import java.net.SocketTimeoutException;32import java.util.Map;33import static jdk.test.lib.Asserts.assertNotEquals;3435public class JdpOnTestCase extends JdpTestCase {3637private int receivedJDPpackets = 0;3839public JdpOnTestCase(ClientConnection connection) {40super(connection);41}4243/**44* Subclasses: JdpOnTestCase and JdpOffTestCase have different messages.45*/46@Override47protected String initialLogMessage() {48return "Waiting for 3 packets with jdp.name=" + connection.instanceName;49}5051/**52* This method is executed after a correct Jdp packet (coming from this VM) has been received.53*54* @param payload A dictionary containing the data if the received Jdp packet.55*/56protected void packetFromThisVMReceived(Map<String, String> payload) {57receivedJDPpackets++;58final String jdpName = payload.get("INSTANCE_NAME");59log.fine("Received correct JDP packet #" + String.valueOf(receivedJDPpackets) +60", jdp.name=" + jdpName);61assertNotEquals(null, payload.get("PROCESS_ID"), "Expected payload.get(\"PROCESS_ID\") to be not null.");62}6364/**65* The socket should not timeout.66* It is set to wait for 10 times the defined pause between Jdp packet. See JdpOnTestCase.TIME_OUT_FACTOR.67*/68@Override69protected void onSocketTimeOut(SocketTimeoutException e) throws Exception {70String message = "Timed out waiting for JDP packet. Should arrive within " +71connection.pauseInSeconds + " seconds, but waited for " +72timeOut + " seconds.";73log.severe(message);74throw new Exception(message, e);75}7677/**78* After receiving three Jdp packets the test should end.79*/80@Override81protected boolean shouldContinue() {82return receivedJDPpackets < 3;83}8485/**86* To run this test manually you might need the following VM options:87* <p/>88* -Dcom.sun.management.jmxremote.authenticate=false89* -Dcom.sun.management.jmxremote.ssl=false90* -Dcom.sun.management.jmxremote.port=4711 (or some other port number)91* -Dcom.sun.management.jmxremote=true92* -Dcom.sun.management.jmxremote.autodiscovery=true93* -Dcom.sun.management.jdp.pause=194* -Dcom.sun.management.jdp.name=alex (or some other string to identify this VM)95* <p/>96* Recommended for nice output:97* -Djava.util.logging.SimpleFormatter.format="%1$tF %1$tT %4$-7s %5$s %n"98*99* @param args100* @throws Exception101*/102public static void main(String[] args) throws Exception {103JdpTestCase client = new JdpOnTestCase(new ClientConnection());104client.run();105}106107}108109110