harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r495839 [4/7] - in /harmony/enhanced/classlib/trunk/modules/lang-management: ./ META-INF/ make/ src/main/java/com/ src/main/java/com/ibm/ src/main/java/com/ibm/lang/ src/main/java/com/ibm/lang/management/ src/main/java/java/lang/management/...
Date Sat, 13 Jan 2007 05:08:52 GMT
Modified: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/ManagementFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/ManagementFactory.java?view=diff&rev=495839&r1=495838&r2=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/ManagementFactory.java (original)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/ManagementFactory.java Fri Jan 12 21:08:48 2007
@@ -18,13 +18,32 @@
 package java.lang.management;
 
 import java.io.IOException;
-import java.util.Collections;
+import java.lang.reflect.Proxy;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.LogManager;
 
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.MBeanRegistrationException;
 import javax.management.MBeanServer;
 import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerFactory;
+import javax.management.MBeanServerPermission;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.NotificationEmitter;
 import javax.management.ObjectName;
 
+import com.ibm.lang.management.ManagementUtils;
+import com.ibm.lang.management.MemoryManagerMXBeanImpl;
+import com.ibm.lang.management.OpenTypeMappingIHandler;
+
 /**
  * <p>
  * The factory for retrieving all managed object for the JVM as well as the
@@ -100,51 +119,416 @@
      */
     public static final String THREAD_MXBEAN_NAME = "java.lang:type=Threading";
 
+    /**
+     * Reference to the MBean server. In addition to playing the role of an
+     * MBean registry, the MBean server also provides a way for management
+     * systems to find and utilise registered MBeans.
+     */
+    private static MBeanServer platformServer;
+
+    private static Map<String, String> interfaceNameLookupTable;
+
+    private static Set<String> multiInstanceBeanNames;
+
+    static {
+        interfaceNameLookupTable = new HashMap<String, String>();
+        // Public API types
+        interfaceNameLookupTable.put("java.lang.management.ClassLoadingMXBean",
+                CLASS_LOADING_MXBEAN_NAME);
+        interfaceNameLookupTable.put("java.lang.management.MemoryMXBean",
+                MEMORY_MXBEAN_NAME);
+        interfaceNameLookupTable.put("java.lang.management.ThreadMXBean",
+                THREAD_MXBEAN_NAME);
+        interfaceNameLookupTable.put("java.lang.management.RuntimeMXBean",
+                RUNTIME_MXBEAN_NAME);
+        interfaceNameLookupTable.put(
+                "java.lang.management.OperatingSystemMXBean",
+                OPERATING_SYSTEM_MXBEAN_NAME);
+        interfaceNameLookupTable.put("java.lang.management.CompilationMXBean",
+                COMPILATION_MXBEAN_NAME);
+        interfaceNameLookupTable.put(
+                "java.lang.management.GarbageCollectorMXBean",
+                GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE);
+        interfaceNameLookupTable.put(
+                "java.lang.management.MemoryManagerMXBean",
+                MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE);
+        interfaceNameLookupTable.put("java.lang.management.MemoryPoolMXBean",
+                MEMORY_POOL_MXBEAN_DOMAIN_TYPE);
+
+        multiInstanceBeanNames = new HashSet<String>();
+        multiInstanceBeanNames
+                .add("java.lang.management.GarbageCollectorMXBean");
+        multiInstanceBeanNames.add("java.lang.management.MemoryManagerMXBean");
+        multiInstanceBeanNames.add("java.lang.management.MemoryPoolMXBean");
+    }
+
+    /**
+     * Private constructor ensures that this class cannot be instantiated by
+     * users.
+     */
+    private ManagementFactory() {
+        // NO OP
+    }
+
+    /**
+     * Returns the singleton <code>MXBean</code> for the virtual machine's
+     * class loading system.
+     * 
+     * @return the virtual machine's {@link ClassLoadingMXBean}
+     */
     public static ClassLoadingMXBean getClassLoadingMXBean() {
-        return null;
+        return ManagementUtils.getClassLoadingBean();
     }
 
+    /**
+     * Returns the singleton <code>MXBean</code> for the virtual machine's
+     * compilation system <i>if and only if the virtual machine has a
+     * compilation system enabled </i>. If no compilation exists for this
+     * virtual machine, a <code>null</code> is returned.
+     * 
+     * @return the virtual machine's {@link CompilationMXBean}or
+     *         <code>null</code> if there is no compilation system for this
+     *         virtual machine.
+     */
     public static CompilationMXBean getCompilationMXBean() {
-        return null;
+        return ManagementUtils.getCompliationBean();
     }
 
+    /**
+     * Returns a list of all of the instances of {@link GarbageCollectorMXBean}
+     * in this virtual machine. Owing to the dynamic nature of this kind of
+     * <code>MXBean</code>, it is possible that instances may be created or
+     * destroyed between the invocation and return of this method.
+     * 
+     * @return a list of all known <code>GarbageCollectorMXBean</code> s in
+     *         this virtual machine.
+     */
     public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
-        return Collections.emptyList();
+        return ManagementUtils.getGarbageCollectorMXBeans();
     }
 
+    /**
+     * Returns a list of all of the instances of {@link MemoryManagerMXBean}in
+     * this virtual machine. Owing to the dynamic nature of this kind of
+     * <code>MXBean</code>, it is possible that instances may be created or
+     * destroyed between the invocation and return of this method.
+     * <p>
+     * Note that the list of <code>MemoryManagerMXBean</code> instances will
+     * include instances of <code>MemoryManagerMXBean</code> sub-types such as
+     * <code>GarbageCollectorMXBean</code>.
+     * </p>
+     * 
+     * @return a list of all known <code>MemoryManagerMXBean</code> s in this
+     *         virtual machine.
+     */
     public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
-        return Collections.emptyList();
+        return ManagementUtils.getMemoryManagerMXBeans();
     }
 
+    /**
+     * Returns the singleton <code>MXBean</code> for the virtual machine's
+     * memory system.
+     * 
+     * @return the virtual machine's {@link MemoryMXBean}
+     */
     public static MemoryMXBean getMemoryMXBean() {
-        return null;
+        return ManagementUtils.getMemoryBean();
     }
 
+    /**
+     * Returns a list of all of the instances of {@link MemoryPoolMXBean}in
+     * this virtual machine. Owing to the dynamic nature of this kind of
+     * <code>MXBean</code>, it is possible that instances may be created or
+     * destroyed between the invocation and return of this method.
+     * 
+     * @return a list of all known <code>MemoryPoolMXBean</code> s in this
+     *         virtual machine.
+     */
     public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
-        return null;
+        return ManagementUtils.getMemoryPoolMXBeans();
     }
 
+    /**
+     * Returns the singleton <code>MXBean</code> for the operating system
+     * which the virtual machine runs on.
+     * 
+     * @return the virtual machine's {@link OperatingSystemMXBean}
+     */
     public static OperatingSystemMXBean getOperatingSystemMXBean() {
-        return null;
+        return ManagementUtils.getOperatingSystemBean();
     }
 
+    /**
+     * Returns a reference to the virtual machine's platform
+     * <code>MBeanServer</code>. This <code>MBeanServer</code> will have
+     * all of the platform <code>MXBean</code> s registered with it including
+     * any dynamic <code>MXBean</code> s (e.g. instances of
+     * {@link GarbageCollectorMXBean}that may be unregistered and destroyed at
+     * a later time.
+     * <p>
+     * In order to simplify the process of distribution and discovery of managed
+     * beans it is good practice to register all managed beans (in addition to
+     * the platform <code>MXBean</code>s) with this server.
+     * </p>
+     * <p>
+     * A custom <code>MBeanServer</code> can be created by this method if the
+     * System property <code>javax.management.builder.initial</code> has been
+     * set with the fully qualified name of a subclass of
+     * {@link javax.management.MBeanServerBuilder}.
+     * </p>
+     * 
+     * @return the platform <code>MBeanServer</code>.
+     * @throws SecurityException
+     *             if there is a Java security manager in operation and the
+     *             caller of this method does not have
+     *             &quot;createMBeanServer&quot;
+     *             <code>MBeanServerPermission</code>.
+     * @see MBeanServer
+     * @see javax.management.MBeanServerPermission
+     */
     public static MBeanServer getPlatformMBeanServer() {
-        return null;
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            security.checkPermission(new MBeanServerPermission(
+                    "createMBeanServer"));
+        }
+
+        synchronized (ManagementFactory.class) {
+            if (platformServer == null) {
+                platformServer = MBeanServerFactory.createMBeanServer();
+
+                AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                    public Object run() {
+                        registerPlatformBeans(platformServer);
+                        return null;
+                    }// end method run
+                });
+            }
+        }// end synchronized
+        return platformServer;
     }
 
+    /**
+     * Returns the singleton <code>MXBean</code> for the virtual machine's
+     * runtime system.
+     * 
+     * @return the virtual machine's {@link RuntimeMXBean}
+     */
     public static RuntimeMXBean getRuntimeMXBean() {
-        return null;
+        return ManagementUtils.getRuntimeBean();
     }
 
+    /**
+     * Returns the singleton <code>MXBean</code> for the virtual machine's
+     * threading system.
+     * 
+     * @return the virtual machine's {@link ThreadMXBean}
+     */
     public static ThreadMXBean getThreadMXBean() {
-        return null;
+        return ManagementUtils.getThreadBean();
     }
 
+    /**
+     * @param <T>
+     * @param connection
+     * @param mxbeanName
+     * @param mxbeanInterface
+     * @return a new proxy object representing the named <code>MXBean</code>.
+     *         All subsequent method invocations on the proxy will be routed
+     *         through the supplied {@link MBeanServerConnection} object.
+     * @throws IOException
+     */
+    @SuppressWarnings("unchecked")
     public static <T> T newPlatformMXBeanProxy(MBeanServerConnection connection,
             String mxbeanName, Class<T> mxbeanInterface) throws IOException {
-        return null;
+        // Check that the named object implements the specified interface
+        verifyNamedMXBean(mxbeanName, mxbeanInterface);
+
+        T result = null;
+        Class[] interfaces = null;
+        if (ManagementUtils.isANotificationEmitter(mxbeanInterface)) {
+            // Proxies of the MemoryMXBean and OperatingSystemMXBean interfaces
+            // must also implement the NotificationEmitter interface.
+            interfaces = new Class[] { mxbeanInterface,
+                    NotificationEmitter.class };
+        } else {
+            interfaces = new Class[] { mxbeanInterface };
+        }
+
+        result = (T) Proxy.newProxyInstance(interfaces[0].getClassLoader(),
+                interfaces, new OpenTypeMappingIHandler(connection,
+                        mxbeanInterface.getName(), mxbeanName));
+        return result;
     }
 
-    private ManagementFactory() {
+    /**
+     * @param mxbeanName
+     * @param mxbeanInterface
+     */
+    private static void verifyNamedMXBean(String mxbeanName,
+            Class<?> mxbeanInterface) {
+        String mxbeanInterfaceName = mxbeanInterface.getName();
+        String expectedObjectName = interfaceNameLookupTable
+                .get(mxbeanInterfaceName);
+        if (multiInstanceBeanNames.contains(mxbeanInterfaceName)) {
+            // partial match is good enough
+            if (!mxbeanName.startsWith(expectedObjectName)) {
+                throw new IllegalArgumentException(mxbeanName
+                        + " is not an instance of interface "
+                        + mxbeanInterfaceName);
+            }
+        } else {
+            // exact match required
+            if (!expectedObjectName.equals(mxbeanName)) {
+                throw new IllegalArgumentException(mxbeanName
+                        + " is not an instance of interface "
+                        + mxbeanInterfaceName);
+            }
+        }
+    }
+
+    /**
+     * Register the singleton platform MXBeans :
+     * <ul>
+     * <li>ClassLoadingMXBean
+     * <li>MemoryMXBean
+     * <li>ThreadMXBean
+     * <li>RuntimeMXBean
+     * <li>OperatingSystemMXBean
+     * <li>CompilationMXBean ( <i>only if the VM has a compilation system </i>)
+     * </ul>
+     * <p>
+     * This method will be called only once in the lifetime of the virtual
+     * machine, at the point where the singleton platform MBean server has been
+     * created.
+     * 
+     * @param platformServer
+     *            the platform <code>MBeanServer</code> for this virtual
+     *            machine.
+     */
+    private static void registerPlatformBeans(MBeanServer platformServer) {
+        try {
+            ObjectName oName = new ObjectName(CLASS_LOADING_MXBEAN_NAME);
+            if (!platformServer.isRegistered(oName)) {
+                platformServer.registerMBean(ManagementUtils
+                        .getClassLoadingBean(), oName);
+            }
+
+            oName = new ObjectName(LogManager.LOGGING_MXBEAN_NAME);
+            if (!platformServer.isRegistered(oName)) {
+                platformServer.registerMBean(ManagementUtils.getLoggingBean(),
+                        oName);
+            }
+
+            oName = new ObjectName(MEMORY_MXBEAN_NAME);
+            if (!platformServer.isRegistered(oName)) {
+                platformServer.registerMBean(ManagementUtils.getMemoryBean(),
+                        oName);
+            }
+
+            oName = new ObjectName(THREAD_MXBEAN_NAME);
+            if (!platformServer.isRegistered(oName)) {
+                platformServer.registerMBean(ManagementUtils.getThreadBean(),
+                        oName);
+            }
+
+            oName = new ObjectName(RUNTIME_MXBEAN_NAME);
+            if (!platformServer.isRegistered(oName)) {
+                platformServer.registerMBean(ManagementUtils.getRuntimeBean(),
+                        oName);
+            }
+
+            oName = new ObjectName(OPERATING_SYSTEM_MXBEAN_NAME);
+            if (!platformServer.isRegistered(oName)) {
+                platformServer.registerMBean(ManagementUtils
+                        .getOperatingSystemBean(), oName);
+            }
+
+            // If there is no JIT compiler available, there will be no
+            // compilation MXBean.
+            CompilationMXBean cBean = ManagementUtils.getCompliationBean();
+            if (cBean != null) {
+                oName = new ObjectName(COMPILATION_MXBEAN_NAME);
+                if (!platformServer.isRegistered(oName)) {
+                    platformServer.registerMBean(cBean, oName);
+                }
+            }// end if compilation bean is not null
+
+            // Carry out the initial registration of Dynamic MXBeans.
+            List<MemoryPoolMXBean> mpBeanList = ManagementUtils
+                    .getMemoryPoolMXBeans();
+            if (mpBeanList != null) {
+                Iterator<MemoryPoolMXBean> mpIt = mpBeanList.iterator();
+                while (mpIt.hasNext()) {
+                    MemoryPoolMXBean mpBean = mpIt.next();
+                    oName = new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE
+                            + ",name=" + mpBean.getName());
+                    if (!platformServer.isRegistered(oName)) {
+                        platformServer.registerMBean(mpBean, oName);
+                    }
+                }// end while
+            }
+
+            List<GarbageCollectorMXBean> gcBeanList = ManagementUtils
+                    .getGarbageCollectorMXBeans();
+            if (gcBeanList != null) {
+                Iterator<GarbageCollectorMXBean> gcIt = gcBeanList.iterator();
+                while (gcIt.hasNext()) {
+                    GarbageCollectorMXBean gcBean = gcIt.next();
+                    oName = new ObjectName(GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
+                            + ",name=" + gcBean.getName());
+                    if (!platformServer.isRegistered(oName)) {
+                        platformServer.registerMBean(gcBean, oName);
+                    }
+                }// end while
+            }
+
+            // Careful ! The getMemoryManagerMXBeans call returns objects that
+            // are memory managers (with the MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
+            // prefix in their object name) *and* garbage collectors (with the
+            // GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE prefix in their object
+            // name).
+            // This is because garbage collector platform beans extend
+            // memory manager platform beans and so qualify for inclusion in
+            // the list of memory manager beans.
+            List<MemoryManagerMXBean> mmBeanList = ManagementUtils
+                    .getMemoryManagerMXBeans();
+            if (mmBeanList != null) {
+                Iterator<MemoryManagerMXBean> mmIt = mmBeanList.iterator();
+                while (mmIt.hasNext()) {
+                    MemoryManagerMXBean mmBean = mmIt.next();
+                    // Test the bean's runtime class. Only register this bean
+                    // if it's runtime type is MemoryManagerMXBeanImpl.
+                    if (mmBean.getClass().equals(MemoryManagerMXBeanImpl.class)) {
+                        oName = new ObjectName(
+                                MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE + ",name="
+                                        + mmBean.getName());
+                        if (!platformServer.isRegistered(oName)) {
+                            platformServer.registerMBean(mmBean, oName);
+                        }
+                    }
+                }// end while
+            }
+        } catch (InstanceAlreadyExistsException e) {
+            if (ManagementUtils.VERBOSE_MODE) {
+                e.printStackTrace(System.err);
+            }// end if
+        } catch (MBeanRegistrationException e) {
+            if (ManagementUtils.VERBOSE_MODE) {
+                e.printStackTrace(System.err);
+            }// end if
+        } catch (NotCompliantMBeanException e) {
+            if (ManagementUtils.VERBOSE_MODE) {
+                e.printStackTrace(System.err);
+            }// end if
+        } catch (MalformedObjectNameException e) {
+            if (ManagementUtils.VERBOSE_MODE) {
+                e.printStackTrace(System.err);
+            }// end if
+        } catch (NullPointerException e) {
+            if (ManagementUtils.VERBOSE_MODE) {
+                e.printStackTrace(System.err);
+            }// end if
+        }
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryType.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryType.java?view=diff&rev=495839&r1=495838&r2=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryType.java (original)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryType.java Fri Jan 12 21:08:48 2007
@@ -36,5 +36,19 @@
      * Non-heap memory type.
      * </p>
      */
-    NON_HEAP
+    NON_HEAP;
+
+    @Override
+    public String toString() {
+        String result = null;
+        switch (this) {
+            case HEAP:
+                result = "Heap memory";
+                break;
+            case NON_HEAP:
+                result = "Non-heap memory";
+                break;
+        }
+        return result;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/ThreadInfo.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/ThreadInfo.java?view=diff&rev=495839&r1=495838&r2=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/ThreadInfo.java (original)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/ThreadInfo.java Fri Jan 12 21:08:48 2007
@@ -19,6 +19,8 @@
 
 import javax.management.openmbean.CompositeData;
 
+import com.ibm.lang.management.ManagementUtils;
+
 /**
  * <p>
  * Thread information.
@@ -28,68 +30,452 @@
  */
 public class ThreadInfo {
 
+    /**
+     * Receives a {@link CompositeData}representing a <code>ThreadInfo</code>
+     * object and attempts to return the root <code>ThreadInfo</code>
+     * instance.
+     * 
+     * @param cd
+     *            a <code>CompositeDate</code> that represents a
+     *            <code>ThreadInfo</code>.
+     * @return if <code>cd</code> is non- <code>null</code>, returns a new
+     *         instance of <code>ThreadInfo</code>. If <code>cd</code> is
+     *         <code>null</code>, returns <code>null</code>.
+     * @throws IllegalArgumentException
+     *             if argument <code>cd</code> does not correspond to a
+     *             <code>ThreadInfo</code> with the following attributes:
+     *             <ul>
+     *             <li><code>threadId</code>(<code>java.lang.Long</code>)
+     *             <li><code>threadName</code>(
+     *             <code>java.lang.String</code>)
+     *             <li><code>threadState</code>(
+     *             <code>java.lang.String</code>)
+     *             <li><code>suspended</code>(
+     *             <code>java.lang.Boolean</code>)
+     *             <li><code>inNative</code>(<code>java.lang.Boolean</code>)
+     *             <li><code>blockedCount</code>(
+     *             <code>java.lang.Long</code>)
+     *             <li><code>blockedTime</code>(<code>java.lang.Long</code>)
+     *             <li><code>waitedCount</code>(<code>java.lang.Long</code>)
+     *             <li><code>waitedTime<code> (<code>java.lang.Long</code>)
+     *             <li><code>lockName</code> (<code>java.lang.String</code>)
+     *             <li><code>lockOwnerId</code> (<code>java.lang.Long</code>)
+     *             <li><code>lockOwnerName</code> (<code>java.lang.String</code>)
+     *             <li><code>stackTrace</code> (<code>javax.management.openmbean.CompositeData[]</code>)
+     *             </ul>
+     *             Each element of the <code>stackTrace</code> array must 
+     *             correspond to a <code>java.lang.StackTraceElement</code>
+     *             and have the following attributes :
+     *             <ul>
+     *             <li><code>className</code> (<code>java.lang.String</code>)
+     *             <li><code>methodName</code> (<code>java.lang.String</code>)
+     *             <li><code>fileName</code> (<code>java.lang.String</code>)
+     *             <li><code>lineNumber</code> (<code>java.lang.Integer</code>)
+     *             <li><code>nativeMethod</code> (<code>java.lang.Boolean</code>)
+     *             </ul>
+     */
     public static ThreadInfo from(CompositeData cd) {
-        return null;
-    }
+        ThreadInfo result = null;
 
-    ThreadInfo() {
+        if (cd != null) {
+            // Does cd meet the necessary criteria to create a new
+            // ThreadInfo ? If not then exit on an IllegalArgumentException
+            ManagementUtils.verifyFieldNumber(cd, 13);
+            String[] attributeNames = { "threadId", "threadName",
+                    "threadState", "suspended", "inNative", "blockedCount",
+                    "blockedTime", "waitedCount", "waitedTime", "lockName",
+                    "lockOwnerId", "lockOwnerName", "stackTrace" };
+            ManagementUtils.verifyFieldNames(cd, attributeNames);
+            String[] attributeTypes = { "java.lang.Long", "java.lang.String",
+                    "java.lang.String", "java.lang.Boolean",
+                    "java.lang.Boolean", "java.lang.Long", "java.lang.Long",
+                    "java.lang.Long", "java.lang.Long", "java.lang.String",
+                    "java.lang.Long", "java.lang.String",
+                    (new CompositeData[0]).getClass().getName() };
+            ManagementUtils
+                    .verifyFieldTypes(cd, attributeNames, attributeTypes);
+
+            // Extract the values of the attributes and use them to construct
+            // a new ThreadInfo.
+            Object[] attributeVals = cd.getAll(attributeNames);
+            long threadIdVal = ((Long) attributeVals[0]).longValue();
+            String threadNameVal = (String) attributeVals[1];
+            String threadStateStringVal = (String) attributeVals[2];
+
+            // Verify that threadStateStringVal contains a string that can be
+            // successfully used to create a Thread.State.
+            Thread.State threadStateVal = null;
+            try {
+                threadStateVal = Thread.State.valueOf(threadStateStringVal);
+            } catch (IllegalArgumentException e) {
+                throw new IllegalArgumentException(
+                        "CompositeData contains an unexpected threadState value.",
+                        e);
+            }
+
+            boolean suspendedVal = ((Boolean) attributeVals[3]).booleanValue();
+            boolean inNativeVal = ((Boolean) attributeVals[4]).booleanValue();
+            long blockedCountVal = ((Long) attributeVals[5]).longValue();
+            long blockedTimeVal = ((Long) attributeVals[6]).longValue();
+            long waitedCountVal = ((Long) attributeVals[7]).longValue();
+            long waitedTimeVal = ((Long) attributeVals[8]).longValue();
+            String lockNameVal = attributeVals[9] != null ? (String) attributeVals[9]
+                    : null;
+            long lockOwnerIdVal = ((Long) attributeVals[10]).longValue();
+            String lockOwnerNameVal = attributeVals[11] != null ? (String) attributeVals[11]
+                    : null;
+            CompositeData[] stackTraceDataVal = (CompositeData[]) attributeVals[12];
+            StackTraceElement[] stackTraceVals = getStackTracesFromCompositeData(stackTraceDataVal);
+
+            result = new ThreadInfo(threadIdVal, threadNameVal, threadStateVal,
+                    suspendedVal, inNativeVal, blockedCountVal, blockedTimeVal,
+                    waitedCountVal, waitedTimeVal, lockNameVal, lockOwnerIdVal,
+                    lockOwnerNameVal, stackTraceVals);
+        }// end if cd is not null
+
+        return result;
+    }
+
+    /**
+     * Returns an array of {@link StackTraceElement}whose elements have been
+     * created from the corresponding elements of the
+     * <code>stackTraceDataVal</code> argument.
+     * 
+     * @param stackTraceDataVal
+     *            an array of {@link CompositeData}objects, each one
+     *            representing a <code>StackTraceElement</code>.
+     * @return an array of <code>StackTraceElement</code> objects built using
+     *         the data discovered in the corresponding elements of
+     *         <code>stackTraceDataVal</code>.
+     * @throws IllegalArgumentException
+     *             if any of the elements of <code>stackTraceDataVal</code> do
+     *             not correspond to a <code>StackTraceElement</code> with the
+     *             following attributes:
+     *             <ul>
+     *             <li><code>className</code>(<code>java.lang.String</code>)
+     *             <li><code>methodName</code>(
+     *             <code>java.lang.String</code>)
+     *             <li><code>fileName</code>(<code>java.lang.String</code>)
+     *             <li><code>lineNumbercode> (<code>java.lang.Integer</code>)
+     *             <li><code>nativeMethod</code> (<code>java.lang.Boolean</code>)
+     *             </ul>
+     */
+    private static StackTraceElement[] getStackTracesFromCompositeData(
+            CompositeData[] stackTraceDataVal) {
+        StackTraceElement[] result = new StackTraceElement[stackTraceDataVal.length];
+
+        for (int i = 0; i < stackTraceDataVal.length; i++) {
+            CompositeData data = stackTraceDataVal[i];
+
+            // Verify the element
+            ManagementUtils.verifyFieldNumber(data, 5);
+            String[] attributeNames = { "className", "methodName",
+                    "fileName", "lineNumber", "nativeMethod" };
+            ManagementUtils.verifyFieldNames(data, attributeNames);
+            String[] attributeTypes = { "java.lang.String", "java.lang.String",
+                    "java.lang.String", "java.lang.Integer",
+                    "java.lang.Boolean" };
+            ManagementUtils.verifyFieldTypes(data, attributeNames,
+                    attributeTypes);
+
+            // Get hold of the values from the data object to use in the
+            // creation of a new StackTraceElement.
+            Object[] attributeVals = data.getAll(attributeNames);
+            String classNameVal = (String) attributeVals[0];
+            String methodNameVal = (String) attributeVals[1];
+            String fileNameVal = (String) attributeVals[2];
+            int lineNumberVal = ((Integer) attributeVals[3]).intValue();
+            boolean nativeMethodVal = ((Boolean) attributeVals[4])
+                    .booleanValue();
+            StackTraceElement element = new StackTraceElement(classNameVal,
+                    methodNameVal, fileNameVal, lineNumberVal);
+            result[i] = element;
+        }
+
+        return result;
+    }
+
+    private long threadId;
+
+    private String threadName;
+
+    private Thread.State threadState;
+
+    private boolean suspended;
+
+    private boolean inNative;
+
+    private long blockedCount;
+
+    private long blockedTime;
+
+    private long waitedCount;
+
+    private long waitedTime;
+
+    private String lockName;
+
+    private long lockOwnerId;
+
+    private String lockOwnerName;
+
+    private StackTraceElement[] stackTraces = new StackTraceElement[0];
+
+    private String TOSTRING_VALUE;
+
+    /**
+     * Creates a new <code>ThreadInfo</code> instance.
+     * 
+     * @param threadIdVal
+     * @param threadNameVal
+     * @param threadStateVal
+     * @param suspendedVal
+     * @param inNativeVal
+     * @param blockedCountVal
+     * @param blockedTimeVal
+     * @param waitedCountVal
+     * @param waitedTimeVal
+     * @param lockNameVal
+     * @param lockOwnerIdVal
+     * @param lockOwnerNameVal
+     * @param stackTraceVal
+     */
+    private ThreadInfo(long threadIdVal, String threadNameVal,
+            Thread.State threadStateVal, boolean suspendedVal,
+            boolean inNativeVal, long blockedCountVal, long blockedTimeVal,
+            long waitedCountVal, long waitedTimeVal, String lockNameVal,
+            long lockOwnerIdVal, String lockOwnerNameVal,
+            StackTraceElement[] stackTraceVal) {
         super();
-    }
-
+        this.threadId = threadIdVal;
+        this.threadName = threadNameVal;
+        this.threadState = threadStateVal;
+        this.suspended = suspendedVal;
+        this.inNative = inNativeVal;
+        this.blockedCount = blockedCountVal;
+        this.blockedTime = blockedTimeVal;
+        this.waitedCount = waitedCountVal;
+        this.waitedTime = waitedTimeVal;
+        this.lockName = lockNameVal;
+        this.lockOwnerId = lockOwnerIdVal;
+        this.lockOwnerName = lockOwnerNameVal;
+        this.stackTraces = stackTraceVal;
+    }
+
+    /**
+     * Returns the number of times that the thread represented by this
+     * <code>ThreadInfo</code> has been blocked on any monitor objects. The
+     * count is from the start of the thread's life.
+     * 
+     * @return the number of times the corresponding thread has been blocked on
+     *         a monitor.
+     */
     public long getBlockedCount() {
-        return -1;
+        return this.blockedCount;
     }
 
+    /**
+     * If thread contention monitoring is supported and enabled, returns the
+     * total amount of time that the thread represented by this
+     * <code>ThreadInfo</code> has spent blocked on any monitor objects. The
+     * time is measued in milliseconds and will be measured over the time period
+     * since thread contention was most recently enabled.
+     * 
+     * @return if thread contention monitoring is currently enabled, the number
+     *         of milliseconds that the thread associated with this
+     *         <code>ThreadInfo</code> has spent blocked on any monitors. If
+     *         thread contention monitoring is supported but currently disabled,
+     *         <code>-1</code>.
+     * @throws UnsupportedOperationException
+     *             if the virtual machine does not support thread contention
+     *             monitoring.
+     * @see ThreadMXBean#isThreadContentionMonitoringSupported()
+     * @see ThreadMXBean#isThreadContentionMonitoringEnabled()
+     */
     public long getBlockedTime() {
-        return -1;
+        return this.blockedTime;
     }
 
+    /**
+     * If the thread represented by this <code>ThreadInfo</code> is currently
+     * blocked on or waiting on a monitor object, returns a string
+     * representation of that monitor object.
+     * <p>
+     * The monitor's string representation is comprised of the following
+     * component parts:
+     * <ul>
+     * <li><code>monitor</code> class name
+     * <li><code>@</code>
+     * <li><code>Integer.toHexString(System.identityHashCode(monitor))</code>
+     * </ul>
+     * </p>
+     * @return if blocked or waiting on a monitor, a string representation of
+     *         the monitor object. Otherwise, <code>null</code>.
+     * @see Integer#toHexString(int)
+     * @see System#identityHashCode(java.lang.Object)
+     */
     public String getLockName() {
-        return null;
+        return this.lockName;
     }
 
+    /**
+     * If the thread represented by this <code>ThreadInfo</code> is currently
+     * blocked on or waiting on a monitor object, returns the thread identifier
+     * of the thread which owns the monitor.
+     * 
+     * @return the thread identifier of the other thread which holds the monitor
+     *         that the thread associated with this <code>ThreadInfo</code> is
+     *         blocked or waiting on. If this <code>ThreadInfo</code>'s
+     *         associated thread is currently not blocked or waiting, or there
+     *         is no other thread holding the monitor, returns a <code>-1</code>.
+     */
     public long getLockOwnerId() {
-        return -1;
+        return this.lockOwnerId;
     }
 
+    /**
+     * If the thread represented by this <code>ThreadInfo</code> is currently
+     * blocked on or waiting on a monitor object, returns the name of the thread
+     * which owns the monitor.
+     * 
+     * @return the name of the other thread which holds the monitor that the
+     *         thread associated with this <code>ThreadInfo</code> is blocked
+     *         or waiting on. If this <code>ThreadInfo</code>'s associated
+     *         thread is currently not blocked or waiting, or there is no other
+     *         thread holding the monitor, returns a <code>null</code>
+     *         reference.
+     */
     public String getLockOwnerName() {
-        return null;
+        return lockOwnerName;
     }
 
+    /**
+     * If available, returns the stack trace for the thread represented by this
+     * <code>ThreadInfo</code> instance. The stack trace is returned in an
+     * array of {@link StackTraceElement}objects with the &quot;top&quot of the
+     * stack encapsulated in the first array element and the &quot;bottom&quot;
+     * of the stack in the last array element.
+     * <p>
+     * If this <code>ThreadInfo</code> was created without any stack trace
+     * information (e.g. by a call to {@link ThreadMXBean#getThreadInfo(long)})
+     * then the returned array will have a length of zero.
+     * </p>
+     * 
+     * @return the stack trace for the thread represented by this
+     *         <code>ThreadInfo</code>.
+     */
     public StackTraceElement[] getStackTrace() {
-        return null;
+        return this.stackTraces;
     }
 
+    /**
+     * Returns the thread identifier of the thread represented by this
+     * <code>ThreadInfo</code>.
+     * 
+     * @return the identifer of the thread corresponding to this
+     *         <code>ThreadInfo</code>.
+     */
     public long getThreadId() {
-        return -1;
+        return this.threadId;
     }
 
+    /**
+     * Returns the name of the thread represented by this
+     * <code>ThreadInfo</code>.
+     * 
+     * @return the name of the thread corresponding to this
+     *         <code>ThreadInfo</code>.
+     */
     public String getThreadName() {
-        return null;
+        return this.threadName;
     }
 
+    /**
+     * Returns the thread state value of the thread represented by this
+     * <code>ThreadInfo</code>.
+     * 
+     * @return the thread state of the thread corresponding to this
+     *         <code>ThreadInfo</code>.
+     * @see Thread#getState()
+     */
     public Thread.State getThreadState() {
-        return null;
+        return this.threadState;
     }
 
+    /**
+     * The number of times that the thread represented by this
+     * <code>ThreadInfo</code> has gone to the &quot;wait&quot; or &quot;timed
+     * wait&quot; state.
+     * 
+     * @return the numer of times the corresponding thread has been in the
+     *         &quot;wait&quot; or &quot;timed wait&quot; state.
+     */
     public long getWaitedCount() {
-        return -1;
+        return this.waitedCount;
     }
 
+    /**
+     * If thread contention monitoring is supported and enabled, returns the
+     * total amount of time that the thread represented by this
+     * <code>ThreadInfo</code> has spent waiting for notifications. The time
+     * is measued in milliseconds and will be measured over the time period
+     * since thread contention was most recently enabled.
+     * 
+     * @return if thread contention monitoring is currently enabled, the number
+     *         of milliseconds that the thread associated with this
+     *         <code>ThreadInfo</code> has spent waiting notifications. If
+     *         thread contention monitoring is supported but currently disabled,
+     *         <code>-1</code>.
+     * @throws UnsupportedOperationException
+     *             if the virtual machine does not support thread contention
+     *             monitoring.
+     * @see ThreadMXBean#isThreadContentionMonitoringSupported()
+     * @see ThreadMXBean#isThreadContentionMonitoringEnabled()
+     */
     public long getWaitedTime() {
-        return -1;
+        return this.waitedTime;
     }
 
+    /**
+     * Returns a <code>boolean</code> indication of whether or not the thread
+     * represented by this <code>ThreadInfo</code> is currently in a native
+     * method.
+     * 
+     * @return if the corresponding thread <i>is </i> executing a native method
+     *         then <code>true</code>, otherwise <code>false</code>.
+     */
     public boolean isInNative() {
-        return false;
+        return this.inNative;
     }
 
+    /**
+     * Returns a <code>boolean</code> indication of whether or not the thread
+     * represented by this <code>ThreadInfo</code> is currently suspended.
+     * 
+     * @return if the corresponding thread <i>is </i> suspened then
+     *         <code>true</code>, otherwise <code>false</code>.
+     */
     public boolean isSuspended() {
-        return false;
+        return this.suspended;
     }
 
     @Override
     public String toString() {
-        return super.toString();
+        // Since ThreadInfos are immutable the string value need only be
+        // calculated the one time
+        if (TOSTRING_VALUE == null) {
+            StringBuilder buff = new StringBuilder();
+            buff.append("Thread ");
+            buff.append(threadName);
+            buff.append(" (Id = ");
+            buff.append(threadId);
+            buff.append(") ");
+            buff.append(threadState.toString());
+            if (lockName != null) {
+                buff.append(" " + lockName);
+            }
+            TOSTRING_VALUE = buff.toString().trim();
+        }
+        return TOSTRING_VALUE;
     }
 }

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ClassLoadingMXBeanTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ClassLoadingMXBeanTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ClassLoadingMXBeanTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ClassLoadingMXBeanTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.ClassLoadingMXBean;
+import java.lang.management.ManagementFactory;
+
+import junit.framework.TestCase;
+
+public class ClassLoadingMXBeanTest extends TestCase {
+
+    ClassLoadingMXBean mb;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mb = ManagementFactory.getClassLoadingMXBean();
+        assertNotNull(mb);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ClassLoadingMXBean.getLoadedClassCount()'
+     */
+    public void testGetLoadedClassCount() {
+        assertTrue(mb.getLoadedClassCount() > -1);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ClassLoadingMXBean.getTotalLoadedClassCount()'
+     */
+    public void testGetTotalLoadedClassCount() {
+        assertTrue(mb.getTotalLoadedClassCount() > -1);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ClassLoadingMXBean.getUnloadedClassCount()'
+     */
+    public void testGetUnloadedClassCount() {
+        assertTrue(mb.getUnloadedClassCount() > -1);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ClassLoadingMXBean.setVerbose(boolean)'
+     */
+    public void testSetVerbose() {
+        boolean initialVal = mb.isVerbose();
+        mb.setVerbose(!initialVal);
+        assertTrue(mb.isVerbose() != initialVal);
+        mb.setVerbose(initialVal);
+        assertTrue(mb.isVerbose() == initialVal);
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ClassLoadingMXBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/CompilationMXBeanTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/CompilationMXBeanTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/CompilationMXBeanTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/CompilationMXBeanTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.CompilationMXBean;
+import java.lang.management.ManagementFactory;
+
+import junit.framework.TestCase;
+
+public class CompilationMXBeanTest extends TestCase {
+
+    CompilationMXBean mb;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mb = ManagementFactory.getCompilationMXBean();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for 'java.lang.management.CompilationMXBean.getName()'
+     */
+    public void testGetName() throws Exception {
+        assertNotNull(mb.getName());
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.CompilationMXBean.getTotalCompilationTime()'
+     */
+    public void testGetTotalCompilationTime() throws Exception {
+        if (mb.isCompilationTimeMonitoringSupported()) {
+            assertTrue(mb.getTotalCompilationTime() > -1);
+        } else {
+            try {
+                long tmp = mb.getTotalCompilationTime();
+                fail("Should have thrown unsupported operation exception!");
+            } catch (UnsupportedOperationException e) {
+                // ignore
+            }
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/CompilationMXBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/GarbageCollectorMXBeanTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/GarbageCollectorMXBeanTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/GarbageCollectorMXBeanTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/GarbageCollectorMXBeanTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class GarbageCollectorMXBeanTest extends TestCase {
+
+    private List<GarbageCollectorMXBean> allBeans;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        allBeans = ManagementFactory.getGarbageCollectorMXBeans();
+        assertNotNull(allBeans);
+        for (GarbageCollectorMXBean mb : allBeans) {
+            assertNotNull(mb);
+        }
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.GarbageCollectorMXBean.getCollectionCount()'
+     */
+    public void testGetCollectionCount() {
+        for (GarbageCollectorMXBean mb : allBeans) {
+            // spec says that the collection count value may be -1 if it is
+            // undefined for a given garbage collector
+            assertTrue(mb.getCollectionCount() > -2);
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.GarbageCollectorMXBean.getCollectionTime()'
+     */
+    public void testGetCollectionTime() {
+        for (GarbageCollectorMXBean mb : allBeans) {
+            // spec says that the collection time value may be -1 if it is
+            // undefined for a given garbage collector
+            assertTrue(mb.getCollectionTime() > -2);
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryManagerMXBean.getMemoryPoolNames()'
+     */
+    public void testGetMemoryPoolNames() {
+        for (GarbageCollectorMXBean mb : allBeans) {
+            String[] managedPools = mb.getMemoryPoolNames();
+            assertNotNull(managedPools);
+            for (String poolName : managedPools) {
+                assertNotNull(poolName);
+                assertTrue(poolName.length() > 0);
+            }// end for all managed pools
+        }// end for all garbage collector beans
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryManagerMXBean.getName()'
+     */
+    public void testGetName() {
+        for (GarbageCollectorMXBean mb : allBeans) {
+            String name = mb.getName();
+            assertNotNull(name);
+            assertTrue(name.length() > 0);
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/GarbageCollectorMXBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/LoggingMXBeanTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/LoggingMXBeanTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/LoggingMXBeanTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/LoggingMXBeanTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.util.Enumeration;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+import java.util.logging.LoggingMXBean;
+
+import junit.framework.TestCase;
+
+public class LoggingMXBeanTest extends TestCase {
+
+    LoggingMXBean lmb;
+
+    Enumeration<String> loggerNamesFromMgr;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        lmb = LogManager.getLoggingMXBean();
+
+        // Logger names from the log manager...
+        loggerNamesFromMgr = LogManager.getLogManager().getLoggerNames();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for 'java.util.logging.LoggingMXBean.getLoggerLevel(String)'
+     */
+    public void testGetLoggerLevel() throws Exception {
+        // Verify we get something sensible back for the known loggers...
+        while (loggerNamesFromMgr.hasMoreElements()) {
+            String logName = (String) loggerNamesFromMgr.nextElement();
+            String level = lmb.getLoggerLevel(logName);
+            assertNotNull(level);
+            if (level.length() > 0) {
+                Level.parse(level);
+            }// end if not an empty string
+        }// end while
+
+        // Ensure we get a null back if the named Logger is fictional...
+        assertNull(lmb.getLoggerLevel("made up name"));
+    }
+
+    /*
+     * Test method for 'java.util.logging.LoggingMXBean.getLoggerNames()'
+     */
+    public void testGetLoggerNames() throws Exception {
+        // Logger names from the bean...
+        List<String> namesFromBean = lmb.getLoggerNames();
+        assertNotNull(namesFromBean);
+        while (loggerNamesFromMgr.hasMoreElements()) {
+            String mgrName = loggerNamesFromMgr.nextElement();
+            assertTrue(namesFromBean.contains(mgrName));
+        }// end while
+    }
+
+    /*
+     * Test method for
+     * 'java.util.logging.LoggingMXBean.getParentLoggerName(String)'
+     */
+    public void testGetParentLoggerName() throws Exception {
+        // Verify we get something sensible back for the known loggers...
+        while (loggerNamesFromMgr.hasMoreElements()) {
+            String logName = (String) loggerNamesFromMgr.nextElement();
+            Logger logger = LogManager.getLogManager().getLogger(logName);
+            Logger parent = logger.getParent();
+            if (parent != null) {
+                // The logger is not the root logger
+                String parentName = logger.getParent().getName();
+                assertEquals(parentName, lmb.getParentLoggerName(logName));
+            } else {
+                // The logger is the root logger and has no parent.
+                assertTrue(lmb.getParentLoggerName(logName).equals(""));
+            }
+        }// end while
+
+        // Ensure we get a null back if the named Logger is fictional...
+        assertNull(lmb.getParentLoggerName("made up name"));
+    }
+
+    /*
+     * Test method for 'java.util.logging.LoggingMXBean.setLoggerLevel(String,
+     * String)'
+     */
+    public void testSetLoggerLevel() throws Exception {
+        String logName = null;
+        while (loggerNamesFromMgr.hasMoreElements()) {
+            logName = (String) loggerNamesFromMgr.nextElement();
+
+            // Store the logger's current log level.
+            Logger logger = LogManager.getLogManager().getLogger(logName);
+            if (levelNotSevere(logger.getLevel())) {
+                // Set the logger to have a new level.
+                lmb.setLoggerLevel(logName, Level.SEVERE.getName());
+
+                // Verify the set worked
+                assertEquals(Level.SEVERE.getName(), logger.getLevel()
+                        .getName());
+            }
+        }// end while
+
+        // Verify that we get an IllegalArgumentException if we supply a
+        // bogus loggerName.
+        try {
+            lmb.setLoggerLevel("Ella Fitzgerald", Level.SEVERE.getName());
+            fail("Should have thrown IllegalArgumentException for a bogus log name!");
+        } catch (IllegalArgumentException e) {
+            // ignored
+        }
+
+        // Verify that we get an IllegalArgumentException if we supply a
+        // bogus log level value.
+        try {
+            lmb.setLoggerLevel(logName, "Scott Walker");
+            fail("Should have thrown IllegalArgumentException for a bogus log level!");
+        } catch (IllegalArgumentException e) {
+            // ignored
+        }
+    }
+
+    private boolean levelNotSevere(Level level) {
+        if (level == null) {
+            return true;
+        }
+        if (level.equals(Level.SEVERE)) {
+            return true;
+        }
+        return false;
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/LoggingMXBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ManagementFactoryTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ManagementFactoryTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ManagementFactoryTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ManagementFactoryTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,516 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.ClassLoadingMXBean;
+import java.lang.management.CompilationMXBean;
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryManagerMXBean;
+import java.lang.management.MemoryPoolMXBean;
+import java.lang.management.MemoryUsage;
+import java.lang.management.OperatingSystemMXBean;
+import java.lang.management.RuntimeMXBean;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+import java.util.List;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+public class ManagementFactoryTest extends TestCase {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.getClassLoadingMXBean()'
+     */
+    public void testGetClassLoadingMXBean() {
+        ClassLoadingMXBean mb = ManagementFactory.getClassLoadingMXBean();
+        assertNotNull(mb);
+
+        // Verify that there is only instance of the class loading bean
+        ClassLoadingMXBean mb2 = ManagementFactory.getClassLoadingMXBean();
+        assertNotNull(mb2);
+        assertSame(mb, mb2);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.getCompilationMXBean()'
+     */
+    public void testGetCompilationMXBean() {
+        CompilationMXBean mb = ManagementFactory.getCompilationMXBean();
+        assertNotNull(mb);
+
+        // Verify that there is only instance of this bean
+        CompilationMXBean mb2 = ManagementFactory.getCompilationMXBean();
+        assertNotNull(mb2);
+        assertSame(mb, mb2);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.getGarbageCollectorMXBeans()'
+     */
+    public void testGetGarbageCollectorMXBeans() {
+        List<GarbageCollectorMXBean> allBeans = ManagementFactory
+                .getGarbageCollectorMXBeans();
+        assertNotNull(allBeans);
+        assertTrue(allBeans.size() > 0);
+        for (GarbageCollectorMXBean mb : allBeans) {
+            assertNotNull(mb);
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.getMemoryManagerMXBeans()'
+     */
+    public void testGetMemoryManagerMXBeans() {
+        List<MemoryManagerMXBean> allBeans = ManagementFactory
+                .getMemoryManagerMXBeans();
+        assertNotNull(allBeans);
+        assertTrue(allBeans.size() > 0);
+        for (MemoryManagerMXBean mb : allBeans) {
+            assertNotNull(mb);
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.getMemoryMXBean()'
+     */
+    public void testGetMemoryMXBean() {
+        MemoryMXBean mb = ManagementFactory.getMemoryMXBean();
+        assertNotNull(mb);
+
+        // Verify that there is only instance of this bean
+        MemoryMXBean mb2 = ManagementFactory.getMemoryMXBean();
+        assertNotNull(mb2);
+        assertSame(mb, mb2);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.getMemoryPoolMXBeans()'
+     */
+    public void testGetMemoryPoolMXBeans() {
+        List<MemoryPoolMXBean> allBeans = ManagementFactory
+                .getMemoryPoolMXBeans();
+        assertNotNull(allBeans);
+        assertTrue(allBeans.size() > 0);
+        for (MemoryPoolMXBean mb : allBeans) {
+            assertNotNull(mb);
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.getOperatingSystemMXBean()'
+     */
+    public void testGetOperatingSystemMXBean() {
+        OperatingSystemMXBean mb = ManagementFactory.getOperatingSystemMXBean();
+        assertNotNull(mb);
+
+        // Verify that there is only instance of this bean
+        OperatingSystemMXBean mb2 = ManagementFactory
+                .getOperatingSystemMXBean();
+        assertNotNull(mb2);
+        assertSame(mb, mb2);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.getPlatformMBeanServer()'
+     */
+    public void testGetPlatformMBeanServer() {
+        MBeanServer pServer = ManagementFactory.getPlatformMBeanServer();
+        assertNotNull(pServer);
+
+        // Verify that subsequent calls always return the same server object.
+        MBeanServer pServer2 = ManagementFactory.getPlatformMBeanServer();
+        assertNotNull(pServer2);
+        assertSame(pServer, pServer2);
+
+        // Verify the default domain is "DefaultDomain"
+        assertEquals("DefaultDomain", pServer.getDefaultDomain());
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.getRuntimeMXBean()'
+     */
+    public void testGetRuntimeMXBean() {
+        RuntimeMXBean mb = ManagementFactory.getRuntimeMXBean();
+        assertNotNull(mb);
+
+        // Verify that there is only instance of this bean
+        RuntimeMXBean mb2 = ManagementFactory.getRuntimeMXBean();
+        assertNotNull(mb2);
+        assertSame(mb, mb2);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.getThreadMXBean()'
+     */
+    public void testGetThreadMXBean() {
+        ThreadMXBean mb = ManagementFactory.getThreadMXBean();
+        assertNotNull(mb);
+
+        // Verify that there is only instance of this bean
+        ThreadMXBean mb2 = ManagementFactory.getThreadMXBean();
+        assertNotNull(mb2);
+        assertSame(mb, mb2);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
+     * String, Class<T>) <T>'
+     */
+    public void testNewPlatformMXBeanProxy() throws Exception {
+        // Test that the general case fails as expected..
+
+        // MXBean name deliberately in wrong format
+        try {
+            ClassLoadingMXBean proxy = ManagementFactory
+                    .newPlatformMXBeanProxy(ManagementFactory
+                            .getPlatformMBeanServer(),
+                            "java,lang:type=ClassLoading",
+                            ClassLoadingMXBean.class);
+            fail("should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // MXBean name in correct format but deliberately bogus
+        try {
+            ClassLoadingMXBean proxy = ManagementFactory
+                    .newPlatformMXBeanProxy(ManagementFactory
+                            .getPlatformMBeanServer(),
+                            "java.lang:type=ClassStroking",
+                            ClassLoadingMXBean.class);
+            fail("should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // Named MXBean does not implement the supplied MXBean interface
+        try {
+            ClassLoadingMXBean proxy = ManagementFactory
+                    .newPlatformMXBeanProxy(ManagementFactory
+                            .getPlatformMBeanServer(), "java.lang:type=Memory",
+                            ClassLoadingMXBean.class);
+            fail("should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // Named MXBean does not implement the supplied MXBean interface
+        List<MemoryPoolMXBean> allMPoolBeans = ManagementFactory
+                .getMemoryPoolMXBeans();
+        for (MemoryPoolMXBean bean : allMPoolBeans) {
+            try {
+                ClassLoadingMXBean proxy = ManagementFactory
+                        .newPlatformMXBeanProxy(ManagementFactory
+                                .getPlatformMBeanServer(), bean.getName(),
+                                ClassLoadingMXBean.class);
+                fail("should have thrown IllegalArgumentException");
+            } catch (IllegalArgumentException ignore) {
+            }
+        }// end for
+
+        // Named MXBean does not implement the supplied MXBean interface
+        List<GarbageCollectorMXBean> allGCBeans = ManagementFactory
+                .getGarbageCollectorMXBeans();
+        for (GarbageCollectorMXBean bean : allGCBeans) {
+            try {
+                ThreadMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
+                        ManagementFactory.getPlatformMBeanServer(), bean
+                                .getName(), ThreadMXBean.class);
+                fail("should have thrown IllegalArgumentException");
+            } catch (IllegalArgumentException ignore) {
+            }
+        }// end for
+
+        // Named MXBean does not implement the supplied MXBean interface
+        List<MemoryManagerMXBean> allMMBeans = ManagementFactory
+                .getMemoryManagerMXBeans();
+        for (MemoryManagerMXBean bean : allMMBeans) {
+            try {
+                ThreadMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
+                        ManagementFactory.getPlatformMBeanServer(), bean
+                                .getName(), ThreadMXBean.class);
+                fail("should have thrown IllegalArgumentException");
+            } catch (IllegalArgumentException ignore) {
+            }
+        }// end for 
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
+     * String, Class<T>) <T>'
+     */
+    public void testNewPlatformMXBeanProxy_ClassLoadingMXBean()
+            throws Exception {
+        ClassLoadingMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
+                ManagementFactory.getPlatformMBeanServer(),
+                "java.lang:type=ClassLoading", ClassLoadingMXBean.class);
+        assertNotNull(proxy);
+        ClassLoadingMXBean classLoadingMXBean = ManagementFactory
+                .getClassLoadingMXBean();
+        assertEquals(proxy.getLoadedClassCount(), classLoadingMXBean
+                .getLoadedClassCount());
+        assertEquals(proxy.getTotalLoadedClassCount(), classLoadingMXBean
+                .getTotalLoadedClassCount());
+        assertEquals(proxy.getUnloadedClassCount(), classLoadingMXBean
+                .getUnloadedClassCount());
+        assertEquals(proxy.isVerbose(), classLoadingMXBean.isVerbose());
+
+        boolean initialVal = proxy.isVerbose();
+        proxy.setVerbose(!initialVal);
+        assertTrue(proxy.isVerbose() != initialVal);
+        proxy.setVerbose(initialVal);
+        assertEquals(initialVal, proxy.isVerbose());
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
+     * String, Class<T>) <T>'
+     */
+    public void testNewPlatformMXBeanProxy_CompilationMXBean() throws Exception {
+        CompilationMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
+                ManagementFactory.getPlatformMBeanServer(),
+                "java.lang:type=Compilation", CompilationMXBean.class);
+        assertNotNull(proxy);
+        CompilationMXBean mb = ManagementFactory.getCompilationMXBean();
+        assertEquals(mb.getName(), proxy.getName());
+        assertEquals(mb.isCompilationTimeMonitoringSupported(), proxy
+                .isCompilationTimeMonitoringSupported());
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
+     * String, Class<T>) <T>'
+     */
+    public void testNewPlatformMXBeanProxy_GarbageCollectorMXBean()
+            throws Exception {
+        List<GarbageCollectorMXBean> allBeans = ManagementFactory
+                .getGarbageCollectorMXBeans();
+        for (GarbageCollectorMXBean mb : allBeans) {
+            GarbageCollectorMXBean proxy = ManagementFactory
+                    .newPlatformMXBeanProxy(ManagementFactory
+                            .getPlatformMBeanServer(),
+                            "java.lang:type=GarbageCollector,name="
+                                    + mb.getName(),
+                            GarbageCollectorMXBean.class);
+            assertEquals(mb.getName(), proxy.getName());
+            assertEquals(mb.isValid(), proxy.isValid());
+            assertEquals(mb.getCollectionCount(), proxy.getCollectionCount());
+            String[] poolNames1 = mb.getMemoryPoolNames();
+            String[] poolNames2 = proxy.getMemoryPoolNames();
+            assertEquals(poolNames1.length, poolNames2.length);
+            for (int i = 0; i < poolNames1.length; i++) {
+                String string = poolNames1[i];
+                assertEquals(poolNames1[i], poolNames2[i]);
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
+     * String, Class<T>) <T>'
+     */
+    public void testNewPlatformMXBeanProxy_MemoryManagerMXBean()
+            throws Exception {
+        List<MemoryManagerMXBean> allBeans = ManagementFactory
+                .getMemoryManagerMXBeans();
+        for (MemoryManagerMXBean mb : allBeans) {
+            // Not every memory manager will be registered with the server
+            // connection. Only test those that are...
+            if (ManagementFactory.getPlatformMBeanServer().isRegistered(
+                    new ObjectName("java.lang:type=MemoryManager,name="
+                            + mb.getName()))) {
+                MemoryManagerMXBean proxy = ManagementFactory
+                        .newPlatformMXBeanProxy(ManagementFactory
+                                .getPlatformMBeanServer(),
+                                "java.lang:type=MemoryManager,name="
+                                        + mb.getName(),
+                                MemoryManagerMXBean.class);
+                assertEquals(mb.getName(), proxy.getName());
+                assertEquals(mb.isValid(), proxy.isValid());
+                String[] poolNames1 = mb.getMemoryPoolNames();
+                String[] poolNames2 = proxy.getMemoryPoolNames();
+                assertEquals(poolNames1.length, poolNames2.length);
+                for (int i = 0; i < poolNames1.length; i++) {
+                    String string = poolNames1[i];
+                    assertEquals(poolNames1[i], poolNames2[i]);
+                }
+            }// end if memory manager is registered with server connection
+        }// end for all known memory manager beans
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
+     * String, Class<T>) <T>'
+     */
+    public void testNewPlatformMXBeanProxy_MemoryMXBean() throws Exception {
+        MemoryMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
+                ManagementFactory.getPlatformMBeanServer(),
+                "java.lang:type=Memory", MemoryMXBean.class);
+        assertNotNull(proxy);
+        MemoryMXBean mb = ManagementFactory.getMemoryMXBean();
+        // RI's MemoryUsage does not appear to override equals() so we have to
+        // go the long way round to check that the answers match...
+        MemoryUsage mu1 = mb.getHeapMemoryUsage();
+        MemoryUsage mu2 = proxy.getHeapMemoryUsage();
+        assertEquals(mu1.getInit(), mu2.getInit());
+        assertEquals(mu1.getMax(), mu2.getMax());
+
+        mu1 = mb.getNonHeapMemoryUsage();
+        mu2 = proxy.getNonHeapMemoryUsage();
+        assertEquals(mu1.getInit(), mu2.getInit());
+        assertEquals(mu1.getMax(), mu2.getMax());
+
+        assertEquals(mb.isVerbose(), proxy.isVerbose());
+        // changes made to proxy should be seen in the "real bean" and
+        // vice versa
+        boolean initialValue = proxy.isVerbose();
+        mb.setVerbose(!initialValue);
+        assertEquals(!initialValue, proxy.isVerbose());
+        proxy.setVerbose(initialValue);
+        assertEquals(initialValue, mb.isVerbose());
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
+     * String, Class<T>) <T>'
+     */
+    public void testNewPlatformMXBeanProxy_MemoryPoolMXBean() throws Exception {
+        List<MemoryPoolMXBean> allBeans = ManagementFactory
+                .getMemoryPoolMXBeans();
+        for (MemoryPoolMXBean mb : allBeans) {
+            MemoryPoolMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
+                    ManagementFactory.getPlatformMBeanServer(),
+                    "java.lang:type=MemoryPool,name=" + mb.getName(),
+                    MemoryPoolMXBean.class);
+            // Not doing an exhaustive check on properties...
+            assertEquals(mb.getName(), proxy.getName());
+            assertEquals(mb.isValid(), proxy.isValid());
+            assertEquals(mb.getType(), proxy.getType());
+            assertEquals(mb.isCollectionUsageThresholdSupported(), proxy
+                    .isCollectionUsageThresholdSupported());
+            String[] names1 = mb.getMemoryManagerNames();
+            String[] names2 = mb.getMemoryManagerNames();
+            assertEquals(names1.length, names2.length);
+            for (int i = 0; i < names1.length; i++) {
+                assertEquals(names1[i], names2[i]);
+            }
+        }// end for all known memory manager beans
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
+     * String, Class<T>) <T>'
+     */
+    public void testNewPlatformMXBeanProxy_OperatingSystemMXBean()
+            throws Exception {
+        OperatingSystemMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
+                ManagementFactory.getPlatformMBeanServer(),
+                "java.lang:type=OperatingSystem", OperatingSystemMXBean.class);
+        assertNotNull(proxy);
+        OperatingSystemMXBean mb = ManagementFactory.getOperatingSystemMXBean();
+        assertEquals(mb.getArch(), proxy.getArch());
+        assertEquals(mb.getAvailableProcessors(), proxy
+                .getAvailableProcessors());
+        assertEquals(mb.getVersion(), proxy.getVersion());
+        assertEquals(mb.getName(), proxy.getName());
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
+     * String, Class<T>) <T>'
+     */
+    public void testNewPlatformMXBeanProxy_RuntimeMXBean() throws Exception {
+        RuntimeMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
+                ManagementFactory.getPlatformMBeanServer(),
+                "java.lang:type=Runtime", RuntimeMXBean.class);
+        assertNotNull(proxy);
+        RuntimeMXBean mb = ManagementFactory.getRuntimeMXBean();
+        // Not an exhaustive check...
+        assertEquals(mb.getName(), proxy.getName());
+        assertEquals(mb.getClassPath(), proxy.getClassPath());
+        assertEquals(mb.getStartTime(), proxy.getStartTime());
+        List<String> args1 = mb.getInputArguments();
+        List<String> args2 = proxy.getInputArguments();
+        assertEquals(args1.size(), args2.size());
+        for (String argument : args1) {
+            assertTrue(args2.contains(argument));
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
+     * String, Class<T>) <T>'
+     */
+    public void testNewPlatformMXBeanProxy_ThreadMXBean() throws Exception {
+        ThreadMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
+                ManagementFactory.getPlatformMBeanServer(),
+                "java.lang:type=Threading", ThreadMXBean.class);
+        assertNotNull(proxy);
+        ThreadMXBean mb = ManagementFactory.getThreadMXBean();
+        // Not an exhaustive check...
+        assertEquals(mb.isCurrentThreadCpuTimeSupported(), proxy
+                .isCurrentThreadCpuTimeSupported());
+        assertEquals(mb.isThreadContentionMonitoringSupported(), proxy
+                .isThreadContentionMonitoringSupported());
+        assertEquals(mb.isThreadCpuTimeSupported(), proxy
+                .isThreadCpuTimeSupported());
+        ThreadInfo info1 = mb.getThreadInfo(Thread.currentThread().getId());
+        ThreadInfo info2 = proxy.getThreadInfo(Thread.currentThread().getId());
+        // RI does not appear to override equals() for ThreadInfo so we take
+        // the scenic route to check for equality...
+        assertEquals(info1.getThreadId(), info2.getThreadId());
+        assertEquals(info1.getBlockedCount(), info2.getBlockedCount());
+        assertEquals(info1.getBlockedTime(), info2.getBlockedTime());
+        assertEquals(info1.getThreadName(), info2.getThreadName());
+        assertEquals(info1.getWaitedCount(), info2.getWaitedCount());
+        assertEquals(info1.getLockName(), info2.getLockName());
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ManagementFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ManagementPermissionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ManagementPermissionTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ManagementPermissionTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ManagementPermissionTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.ManagementPermission;
+
+import junit.framework.TestCase;
+
+public class ManagementPermissionTest extends TestCase {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementPermission.ManagementPermission(String)'
+     */
+    public void testManagementPermissionString() {
+        // Normal cases.
+        ManagementPermission mp = new ManagementPermission("monitor");
+        assertNotNull(mp);
+        mp = new ManagementPermission("control");
+        assertNotNull(mp);
+
+        // Bad input - null name
+        try {
+            mp = new ManagementPermission(null);
+            fail("Should have thrown NPE for null name.");
+        } catch (NullPointerException ignore) {
+        }
+
+        // Bad input - unwanted name
+        try {
+            mp = new ManagementPermission("Sunset");
+            fail("Should have thrown IllegalArgumentException for incorrect name.");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // Bad input - correct name but in incorrect type
+        try {
+            mp = new ManagementPermission("Monitor");
+            fail("Should have thrown IllegalArgumentException for upper-case name.");
+        } catch (IllegalArgumentException ignore) {
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ManagementPermission.ManagementPermission(String,
+     * String)'
+     */
+    public void testManagementPermissionStringString() {
+        // Normal cases.
+        ManagementPermission mp = new ManagementPermission("monitor", "");
+        assertNotNull(mp);
+        mp = new ManagementPermission("control", null);
+        assertNotNull(mp);
+
+        // Bad input - null name
+        try {
+            mp = new ManagementPermission(null, null);
+            fail("Should have thrown NPE for null name.");
+        } catch (NullPointerException ignore) {
+        }
+
+        // Bad input - unwanted name
+        try {
+            mp = new ManagementPermission("Sunset", null);
+            fail("Should have thrown IllegalArgumentException for incorrect name.");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // Bad input - correct name but in incorrect type
+        try {
+            mp = new ManagementPermission("Monitor", null);
+            fail("Should have thrown IllegalArgumentException for upper-case name.");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // Bad input - action not one of "" or null
+        try {
+            mp = new ManagementPermission("monitor",
+                    "You broke my heart Fredo.");
+            fail("Should have thrown IllegalArgumentException for bad action.");
+        } catch (IllegalArgumentException ignore) {
+        }
+    }
+
+    /*
+     * Test method for 'java.security.BasicPermission.equals(Object)'
+     */
+    public void testEquals() {
+        ManagementPermission mp1 = new ManagementPermission("monitor");
+        ManagementPermission mp2 = new ManagementPermission("monitor");
+        assertEquals(mp1, mp2);
+
+        mp1 = new ManagementPermission("control", "");
+        mp2 = new ManagementPermission("control", "");
+        assertEquals(mp1, mp2);
+
+        mp1 = new ManagementPermission("monitor", null);
+        mp2 = new ManagementPermission("monitor", null);
+        assertEquals(mp1, mp2);
+        
+        mp1 = new ManagementPermission("monitor");
+        mp2 = new ManagementPermission("control");
+        assertFalse(mp1.equals(mp2));
+    }
+
+    /*
+     * Test method for 'java.security.BasicPermission.implies(Permission)'
+     */
+    public void testImplies() {
+        ManagementPermission mp1 = new ManagementPermission("monitor");
+        ManagementPermission mp2 = new ManagementPermission("control");
+        ManagementPermission mp3 = new ManagementPermission("monitor", "");
+        assertTrue(mp1.implies(mp1));
+        assertTrue(mp1.implies(mp3));
+        assertFalse(mp1.implies(mp2));
+        assertFalse(mp2.implies(mp1));
+    }
+
+    /*
+     * Test method for 'java.security.BasicPermission.getActions()'
+     */
+    public void testGetActions() {
+        ManagementPermission mp1 = new ManagementPermission("monitor");
+        assertEquals("", mp1.getActions());
+        
+        mp1 = new ManagementPermission("control", null);
+        assertEquals("", mp1.getActions());
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ManagementPermissionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message