Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/management/jdp/JdpOnTestCase.java
38841 views
/*1* Copyright (c) 2013, 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;3334public class JdpOnTestCase extends JdpTestCase {3536private int receivedJDPpackets = 0;3738public JdpOnTestCase(ClientConnection connection) {39super(connection);40}4142/**43* Subclasses: JdpOnTestCase and JdpOffTestCase have different messages.44*/45@Override46protected String initialLogMessage() {47return "Waiting for 3 packets with jdp.name=" + connection.instanceName;48}4950/**51* This method is executed after a correct Jdp packet (coming from this VM) has been received.52*53* @param payload A dictionary containing the data if the received Jdp packet.54*/55protected void packetFromThisVMReceived(Map<String, String> payload) {56receivedJDPpackets++;57final String jdpName = payload.get("INSTANCE_NAME");58log.fine("Received correct JDP packet #" + String.valueOf(receivedJDPpackets) +59", jdp.name=" + jdpName);60}6162/**63* The socket should not timeout.64* It is set to wait for 10 times the defined pause between Jdp packet. See JdpOnTestCase.TIME_OUT_FACTOR.65*/66@Override67protected void onSocketTimeOut(SocketTimeoutException e) throws Exception {68String message = "Timed out waiting for JDP packet. Should arrive within " +69connection.pauseInSeconds + " seconds, but waited for " +70timeOut + " seconds.";71log.severe(message);72throw new Exception(message, e);73}7475/**76* After receiving three Jdp packets the test should end.77*/78@Override79protected boolean shouldContinue() {80return receivedJDPpackets < 3;81}8283/**84* To run this test manually you might need the following VM options:85* <p/>86* -Dcom.sun.management.jmxremote.authenticate=false87* -Dcom.sun.management.jmxremote.ssl=false88* -Dcom.sun.management.jmxremote.port=4711 (or some other port number)89* -Dcom.sun.management.jmxremote=true90* -Dcom.sun.management.jmxremote.autodiscovery=true91* -Dcom.sun.management.jdp.pause=192* -Dcom.sun.management.jdp.name=alex (or some other string to identify this VM)93* <p/>94* Recommended for nice output:95* -Djava.util.logging.SimpleFormatter.format="%1$tF %1$tT %4$-7s %5$s %n"96*97* @param args98* @throws Exception99*/100public static void main(String[] args) throws Exception {101JdpTestCase client = new JdpOnTestCase(new ClientConnection());102client.run();103}104105}106107108