1 /* |
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* @test |
|
25 * @bug 8026028 |
|
26 * @summary Tests no leak of internal info |
|
27 * @author Shanliang JIANG |
|
28 * @run clean NoInfoLeakTest |
|
29 * @run build NoInfoLeakTest |
|
30 * @run main NoInfoLeakTest |
|
31 */ |
|
32 |
|
33 import com.sun.jmx.snmp.SnmpString; |
|
34 import com.sun.jmx.snmp.agent.SnmpMib; |
|
35 import com.sun.jmx.snmp.agent.SnmpMibTable; |
|
36 import com.sun.jmx.snmp.daemon.CommunicatorServer; |
|
37 import com.sun.jmx.snmp.daemon.SnmpAdaptorServer; |
|
38 import javax.management.MBeanNotificationInfo; |
|
39 import javax.management.MBeanServer; |
|
40 import javax.management.ObjectName; |
|
41 |
|
42 public class NoInfoLeakTest { |
|
43 public static void main(String[] args) throws Exception { |
|
44 boolean ok = true; |
|
45 ok &= snmpStringTest(); |
|
46 ok &= snmpMibTest(); |
|
47 ok &= communicatorServerTest(); |
|
48 |
|
49 if (!ok) { |
|
50 throw new RuntimeException("Some tests are failed!"); |
|
51 } |
|
52 } |
|
53 |
|
54 private static boolean snmpStringTest() { |
|
55 System.out.println("\n---NoInfoLeakTest-snmpStringTest: testing the method byteValue()..."); |
|
56 boolean passed = true; |
|
57 |
|
58 byte[] mine = new byte[]{1,1,1,}; |
|
59 SnmpString ss = new SnmpString(mine); |
|
60 byte[] got = ss.byteValue(); |
|
61 got[0]=0; |
|
62 |
|
63 if (ss.byteValue()[0] == 0) { |
|
64 System.err.println("Failed: SnmpString.byteValue() returns an internal mutable object value"); |
|
65 passed = false; |
|
66 } else { |
|
67 System.out.println("---NoInfoLeakTest-snmpStringTest done."); |
|
68 } |
|
69 return passed; |
|
70 } |
|
71 |
|
72 private static boolean snmpMibTest() { |
|
73 boolean passed = true; |
|
74 System.out.println("\n---NoInfoLeakTest-snmpMibTest: testing the method " |
|
75 + "SnmpMib.getRootOid()..."); |
|
76 SnmpMib mib = new MySnmpMib(); |
|
77 |
|
78 if (mib.getRootOid() == mib.getRootOid()) { |
|
79 System.err.println("Failed: SnmpMib.getRootOid() returns an internal" |
|
80 + " mutable object value "+mib.getRootOid()); |
|
81 } else { |
|
82 System.out.println("---NoInfoLeakTest-snmpMibTest done."); |
|
83 } |
|
84 return passed; |
|
85 } |
|
86 |
|
87 private static boolean communicatorServerTest() { |
|
88 boolean passed = true; |
|
89 System.out.println("\n---NoInfoLeakTest-communicatorServerTest: testing the method CommunicatorServer.getNotificationInfo()..."); |
|
90 CommunicatorServer server = new SnmpAdaptorServer(); |
|
91 MBeanNotificationInfo[] notifs = server.getNotificationInfo(); |
|
92 |
|
93 assert notifs.length > 0 && notifs[0] != null; // the current implementation ensures this |
|
94 notifs[0] = null; |
|
95 if (server.getNotificationInfo()[0] == null) { |
|
96 System.err.println("Failed: CommunicatorServer.getNotificationInfo()" |
|
97 + " returns an internal mutable object value"); |
|
98 passed = false; |
|
99 } else { |
|
100 System.out.println("---NoInfoLeakTest-communicatorServerTest done."); |
|
101 } |
|
102 return passed; |
|
103 } |
|
104 |
|
105 private static class MySnmpMib extends SnmpMib { |
|
106 @Override |
|
107 public void registerTableMeta(String name, SnmpMibTable table) { |
|
108 throw new UnsupportedOperationException("Not supported yet."); |
|
109 } |
|
110 |
|
111 @Override |
|
112 public SnmpMibTable getRegisteredTableMeta(String name) { |
|
113 throw new UnsupportedOperationException("Not supported yet."); |
|
114 } |
|
115 |
|
116 @Override |
|
117 public void init() throws IllegalAccessException { |
|
118 throw new UnsupportedOperationException("Not supported yet."); |
|
119 } |
|
120 |
|
121 @Override |
|
122 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { |
|
123 throw new UnsupportedOperationException("Not supported yet."); |
|
124 } |
|
125 } |
|
126 } |
|