/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6610094 7024172
* @summary Basic unit test of ManagementFactory.getPlatformMXBean(s)
* methods and PlatformManagedObject.getObjectName()
* @author Mandy Chung
*
* @run main GetPlatformMXBeans
*/
import javax.management.*;
public class GetPlatformMXBeans {
// singleton platform MXBean
ClassLoadingMXBean.class,
CompilationMXBean.class,
MemoryMXBean.class,
OperatingSystemMXBean.class,
RuntimeMXBean.class,
ThreadMXBean.class,
// the following MXBean can have more than one instances
// check invalid platform MXBean
}
private static <T extends PlatformManagedObject>
throws Exception
{
// getPlatformMXBean may return null if the mxbean is not implemented
throw new RuntimeException("Singleton MXBean returned not matched");
}
throw new RuntimeException("Unmatched number of platform MXBeans "
}
throw new RuntimeException("The list returned by getPlatformMXBeans"
+ " not matched");
}
throw new RuntimeException("Unmatched ObjectName " +
}
}
}
// verify platform MXBeans in the platform MBeanServer
private static <T extends PlatformManagedObject>
Class<T> mxbeanInterface,
throws Exception
{
throw new RuntimeException("Singleton MXBean returned not matched");
}
throw new RuntimeException("Unmatched number of platform MXBeans "
}
throw new RuntimeException("Unmatched ObjectName " +
}
}
throws Exception
{
if (mxbean instanceof GarbageCollectorMXBean) {
} else {
}
throw new RuntimeException("Unmatched ObjectName " +
}
}
}
throws Exception
{
throw new RuntimeException("Unmatched ObjectName " +
}
}
}
throws Exception
{
throw new RuntimeException("Unmatched ObjectName " +
}
}
}
private static <T extends PlatformManagedObject>
throws Exception
{
try {
// mxbeanInterface is not a singleton
} catch (IllegalArgumentException e) {
// expect IAE
}
// verify local list of platform MXBeans
throw new RuntimeException("Unmatched number of platform MXBeans "
}
} else {
throw new RuntimeException(pmo +
" not in the platform MXBean list");
}
}
throw new RuntimeException("The list returned by getPlatformMXBeans"
+ " not matched");
}
// verify platform MXBeans in the platform MBeanServer
throw new RuntimeException("Unmatched number of platform MXBeans "
}
}
try {
getPlatformMXBean(FakeMXBean.class);
// mxbeanInterface is not a singleton
throw new RuntimeException("Expect IllegalArgumentException but not thrown");
} catch (IllegalArgumentException e) {
// expect IAE
}
try {
getPlatformMXBeans(FakeMXBean.class);
// mxbeanInterface is not a singleton
throw new RuntimeException("Expect IllegalArgumentException but not thrown");
} catch (IllegalArgumentException e) {
// expect IAE
}
try {
// mxbeanInterface is not a singleton
throw new RuntimeException("Expect IllegalArgumentException but not thrown");
} catch (IllegalArgumentException e) {
// expect IAE
}
try {
// mxbeanInterface is not a singleton
throw new RuntimeException("Expect IllegalArgumentException but not thrown");
} catch (IllegalArgumentException e) {
// expect IAE
}
}
}