author | alexsch |
Thu, 31 Jul 2014 14:28:10 +0400 | |
changeset 26019 | 10a56d28f48d |
parent 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21646
diff
changeset
|
2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
4 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
8 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
13 |
* accompanied this code). |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
14 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
18 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
21 |
* questions. |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
22 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
23 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
24 |
import java.io.IOException; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
25 |
import java.net.InetAddress; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
26 |
import java.util.UUID; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
27 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
28 |
import sun.management.jdp.JdpController; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
29 |
import sun.management.jdp.JdpPacket; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
30 |
import sun.management.jdp.JdpJmxPacket; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
31 |
import sun.management.jdp.JdpException; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
32 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
33 |
public class JdpUnitTest { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
34 |
|
17951
2734e5252a38
8015604: JDP packets containing ideographic characters are broken
dsamersoff
parents:
15531
diff
changeset
|
35 |
|
21646 | 36 |
static byte[] russian_name = {(byte) 0xd0, (byte) 0xbf, (byte) 0xd1, (byte) 0x80, (byte) 0xd0, (byte) 0xbe, (byte) 0xd0, (byte) 0xb2, |
37 |
(byte) 0xd0, (byte) 0xb5, (byte) 0xd1, (byte) 0x80, (byte) 0xd0, (byte) 0xba, (byte) 0xd0, (byte) 0xb0, |
|
38 |
(byte) 0x20, (byte) 0xd1, (byte) 0x81, (byte) 0xd0, (byte) 0xb2, (byte) 0xd1, (byte) 0x8f, (byte) 0xd0, |
|
39 |
(byte) 0xb7, (byte) 0xd0, (byte) 0xb8, (byte) 0x0a}; |
|
17951
2734e5252a38
8015604: JDP packets containing ideographic characters are broken
dsamersoff
parents:
15531
diff
changeset
|
40 |
|
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
41 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
42 |
* This test tests that complete packet is build correctly |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
43 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
44 |
public static void PacketBuilderTest() |
21646 | 45 |
throws IOException, JdpException { |
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
46 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
47 |
/* Complete packet test */ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
48 |
{ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
49 |
JdpJmxPacket p1 = new JdpJmxPacket(UUID.randomUUID(), "fake://unit-test"); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
50 |
p1.setMainClass("FakeUnitTest"); |
21646 | 51 |
p1.setInstanceName(new String(russian_name, "UTF-8")); |
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
52 |
byte[] b = p1.getPacketData(); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
53 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
54 |
JdpJmxPacket p2 = new JdpJmxPacket(b); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
55 |
JdpDoSomething.printJdpPacket(p1); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
56 |
JdpDoSomething.compaireJdpPacketEx(p1, p2); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
57 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
58 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
59 |
/*Missed field packet test*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
60 |
{ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
61 |
JdpJmxPacket p1 = new JdpJmxPacket(UUID.randomUUID(), "fake://unit-test"); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
62 |
p1.setMainClass("FakeUnitTest"); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
63 |
p1.setInstanceName(null); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
64 |
byte[] b = p1.getPacketData(); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
65 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
66 |
JdpJmxPacket p2 = new JdpJmxPacket(b); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
67 |
JdpDoSomething.printJdpPacket(p1); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
68 |
JdpDoSomething.compaireJdpPacketEx(p1, p2); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
69 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
70 |
|
21646 | 71 |
System.out.println("OK: Test passed"); |
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
72 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
73 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
74 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
75 |
public static void startFakeDiscoveryService() |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
76 |
throws IOException, JdpException { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
77 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
78 |
String discoveryPort = System.getProperty("com.sun.management.jdp.port"); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
79 |
String discoveryAddress = System.getProperty("com.sun.management.jdp.address"); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
80 |
InetAddress address = InetAddress.getByName(discoveryAddress); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
81 |
int port = Integer.parseInt(discoveryPort); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
82 |
JdpController.startDiscoveryService(address, port, "FakeDiscovery", "fake://unit-test"); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
83 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
84 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
85 |
public static void main(String[] args) { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
86 |
try { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
87 |
PacketBuilderTest(); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
88 |
startFakeDiscoveryService(); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
89 |
JdpDoSomething.doSomething(); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
90 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
91 |
} catch (Throwable e) { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
92 |
e.printStackTrace(); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
93 |
System.out.println("Test failed. unexpected error " + e); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
94 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
95 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
96 |
} |