Path: blob/master/test/jdk/sun/management/jdp/JdpJmxRemoteDynamicPortTestCase.java
41149 views
/*1* Copyright (c) 2017, 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*/2223import java.net.SocketTimeoutException;24import java.util.Map;2526public class JdpJmxRemoteDynamicPortTestCase extends JdpTestCase {2728private int receivedJDPpackets = 0;2930public JdpJmxRemoteDynamicPortTestCase(ClientConnection connection) {31super(connection);32}3334@Override35protected String initialLogMessage() {36return "Starting test case JdpJmxRemoteDynamicPortTestCase";37}3839/**40* This method is executed after a correct Jdp packet (coming from this VM) has been received.41*42* @param payload A dictionary containing the Jdp packet data.43*/44protected void packetFromThisVMReceived(Map<String, String> payload) throws Exception {45receivedJDPpackets++;46final String jmxServiceurl = payload.get("JMX_SERVICE_URL");47int lastcolon = jmxServiceurl.lastIndexOf(':');48int nextslash = jmxServiceurl.indexOf('/', lastcolon);49int jmxRemotePort = Integer.parseInt(jmxServiceurl, lastcolon + 1, nextslash, 10);5051log.fine("Received #" + String.valueOf(receivedJDPpackets) +52", jmxStringUrl=" + jmxServiceurl + ", jmxRemotePort=" + jmxRemotePort);5354if (0 == jmxRemotePort) {55throw new Exception("JmxRemotePort value is zero. Test case failed.");56}5758log.fine("Test case passed");59}6061/**62* The socket should not timeout.63* It is set to wait for 10 times the defined pause between Jdp packet. See JdpOnTestCase.TIME_OUT_FACTOR.64*/65@Override66protected void onSocketTimeOut(SocketTimeoutException e) throws Exception {67String message = "Timed out waiting for JDP packet. Should arrive within " +68connection.pauseInSeconds + " seconds, but waited for " +69timeOut + " seconds.";70log.severe(message);71throw new Exception(message, e);72}737475/**76* After receiving one Jdp packets the test should end.77*/78@Override79protected boolean shouldContinue() {80return receivedJDPpackets < 1;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=089* -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 JdpJmxRemoteDynamicPortTestCase(new ClientConnection());102client.run();103}104105}106107108