Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/management/jdp/JdpUnitTest.java
38840 views
/*1* Copyright (c) 2012, 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*/2223import java.io.IOException;24import java.net.InetAddress;25import java.util.UUID;2627import sun.management.jdp.JdpController;28import sun.management.jdp.JdpPacket;29import sun.management.jdp.JdpJmxPacket;30import sun.management.jdp.JdpException;3132public class JdpUnitTest {333435static byte[] russian_name = {(byte) 0xd0, (byte) 0xbf, (byte) 0xd1, (byte) 0x80, (byte) 0xd0, (byte) 0xbe, (byte) 0xd0, (byte) 0xb2,36(byte) 0xd0, (byte) 0xb5, (byte) 0xd1, (byte) 0x80, (byte) 0xd0, (byte) 0xba, (byte) 0xd0, (byte) 0xb0,37(byte) 0x20, (byte) 0xd1, (byte) 0x81, (byte) 0xd0, (byte) 0xb2, (byte) 0xd1, (byte) 0x8f, (byte) 0xd0,38(byte) 0xb7, (byte) 0xd0, (byte) 0xb8, (byte) 0x0a};3940/**41* This test tests that complete packet is build correctly42*/43public static void PacketBuilderTest()44throws IOException, JdpException {4546/* Complete packet test */47{48JdpJmxPacket p1 = new JdpJmxPacket(UUID.randomUUID(), "fake://unit-test");49p1.setMainClass("FakeUnitTest");50p1.setInstanceName(new String(russian_name, "UTF-8"));51byte[] b = p1.getPacketData();5253JdpJmxPacket p2 = new JdpJmxPacket(b);54JdpDoSomething.printJdpPacket(p1);55JdpDoSomething.compaireJdpPacketEx(p1, p2);56}5758/*Missed field packet test*/59{60JdpJmxPacket p1 = new JdpJmxPacket(UUID.randomUUID(), "fake://unit-test");61p1.setMainClass("FakeUnitTest");62p1.setInstanceName(null);63byte[] b = p1.getPacketData();6465JdpJmxPacket p2 = new JdpJmxPacket(b);66JdpDoSomething.printJdpPacket(p1);67JdpDoSomething.compaireJdpPacketEx(p1, p2);68}6970System.out.println("OK: Test passed");7172}7374public static void startFakeDiscoveryService()75throws IOException, JdpException {7677String discoveryPort = System.getProperty("com.sun.management.jdp.port");78String discoveryAddress = System.getProperty("com.sun.management.jdp.address");79InetAddress address = InetAddress.getByName(discoveryAddress);80int port = Integer.parseInt(discoveryPort);81JdpController.startDiscoveryService(address, port, "FakeDiscovery", "fake://unit-test");82}8384public static void main(String[] args) {85try {86PacketBuilderTest();87startFakeDiscoveryService();88JdpDoSomething.doSomething();8990} catch (Throwable e) {91e.printStackTrace();92System.out.println("Test failed. unexpected error " + e);93}94}95}969798