You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2007/01/13 06:08:52 UTC
svn commit: r495839 [6/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/...
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/GarbageCollectorMXBeanImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/GarbageCollectorMXBeanImplTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/GarbageCollectorMXBeanImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/GarbageCollectorMXBeanImplTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,264 @@
+/*
+ * 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 com.ibm.lang.management;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+
+import com.ibm.lang.management.DynamicMXBeanImpl;
+import com.ibm.lang.management.GarbageCollectorMXBeanImpl;
+
+public class GarbageCollectorMXBeanImplTest extends
+ MultiInstanceDynamicMXBeanImplTest {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ List<GarbageCollectorMXBean> allBeans = ManagementFactory
+ .getGarbageCollectorMXBeans();
+ mbList = new ArrayList<DynamicMXBeanImpl>();
+ for (GarbageCollectorMXBean bean : allBeans) {
+ mbList.add((GarbageCollectorMXBeanImpl) bean);
+ }// end for
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // -----------------------------------------------------------------
+ // DynamicMBean behaviour tests follow ....
+ // -----------------------------------------------------------------
+
+ public final void testGetAttributes() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+ AttributeList attributes = mb.getAttributes(attribs.keySet()
+ .toArray(new String[] {}));
+ assertNotNull(attributes);
+ assertTrue(attributes.size() <= attribs.size());
+
+ // Check through the returned values
+ Iterator<?> it = attributes.iterator();
+ while (it.hasNext()) {
+ Attribute element = (Attribute) it.next();
+ assertNotNull(element);
+ String name = element.getName();
+ Object value = element.getValue();
+ if (name.equals("Valid")) {
+ // This could be true or false - just so long as we don't
+ // get an exception raised...
+ boolean validVal = ((Boolean) value).booleanValue();
+ } else if (name.equals("Name")) {
+ assertNotNull(value);
+ assertTrue(value instanceof String);
+ assertTrue(((String) value).length() > 0);
+ } else if (name.equals("MemoryPoolNames")) {
+ assertNotNull(value);
+ assertTrue(value instanceof String[]);
+ String[] strVals = (String[]) value;
+ for (int i = 0; i < strVals.length; i++) {
+ String poolName = strVals[i];
+ assertNotNull(poolName);
+ assertTrue(poolName.length() > 0);
+ }// end for
+ } else if (name.equals("CollectionCount")) {
+ assertNotNull(value);
+ assertTrue(value instanceof Long);
+ // It is possible for this count to be -1 if undefined for
+ // this garbage collector
+ assertTrue((Long) value > -2);
+ } else if (name.equals("CollectionTime")) {
+ assertNotNull(value);
+ assertTrue(value instanceof Long);
+ // It is possible for this time to be -1 if undefined for
+ // this garbage collector
+ assertTrue((Long) value > -2);
+ }
+ }// end while
+ }// end for
+ }
+
+ public final void testSetAttributes() {
+ // No writable attributes for this type
+ for (DynamicMXBeanImpl mb : mbList) {
+ AttributeList badList = new AttributeList();
+ Attribute garbage = new Attribute("Name", "Bez");
+ badList.add(garbage);
+ AttributeList setAttrs = mb.setAttributes(badList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() == 0);
+ }// end for
+ }
+
+ public final void testGetMBeanInfo() {
+ for (DynamicMXBeanImpl mb : mbList) {
+ MBeanInfo mbi = mb.getMBeanInfo();
+ assertNotNull(mbi);
+
+ // Now make sure that what we got back is what we expected.
+
+ // Class name
+ assertTrue(mbi.getClassName().equals(mb.getClass().getName()));
+
+ // No public constructors
+ MBeanConstructorInfo[] constructors = mbi.getConstructors();
+ assertNotNull(constructors);
+ assertTrue(constructors.length == 0);
+
+ // No public operations
+ MBeanOperationInfo[] operations = mbi.getOperations();
+ assertNotNull(operations);
+ assertTrue(operations.length == 0);
+
+ // No notifications
+ MBeanNotificationInfo[] notifications = mbi.getNotifications();
+ assertNotNull(notifications);
+ assertTrue(notifications.length == 0);
+
+ // Description is just the class name
+ assertTrue(mbi.getDescription().equals(mb.getClass().getName()));
+
+ // 5 standard attributes - none is writable.
+ MBeanAttributeInfo[] attributes = mbi.getAttributes();
+ assertNotNull(attributes);
+ assertTrue(attributes.length == 5);
+ for (int i = 0; i < attributes.length; i++) {
+ MBeanAttributeInfo info = attributes[i];
+ assertNotNull(info);
+ validateAttributeInfo(info);
+ }// end for
+ }// end for
+ }
+
+ public final void testGetAttribute() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+ // The good attributes...
+ assertTrue(mb.getAttribute("MemoryPoolNames") instanceof String[]);
+ String[] arr = (String[]) mb.getAttribute("MemoryPoolNames");
+ for (int i = 0; i < arr.length; i++) {
+ String element = arr[i];
+ assertNotNull(element);
+ assertTrue(element.length() > 0);
+ }// end for
+
+ assertTrue(mb.getAttribute("Name") instanceof String);
+ assertTrue(((String) mb.getAttribute("Name")).length() > 0);
+
+ // This could be true or false - just so long as we don't get an
+ // exception raised...
+ boolean validVal = ((Boolean) (mb.getAttribute("Valid")));
+
+ assertTrue(mb.getAttribute("CollectionCount") instanceof Long);
+ // It is possible for this count to be -1 if undefined for
+ // this garbage collector
+ assertTrue(((Long) mb.getAttribute("CollectionCount")) > -2);
+
+ assertTrue(mb.getAttribute("CollectionTime") instanceof Long);
+ // It is possible for this time to be -1 if undefined for
+ // this garbage collector
+ assertTrue(((Long) mb.getAttribute("CollectionTime")) > -2);
+
+ // A nonexistent attribute should throw an
+ // AttributeNotFoundException
+ try {
+ long rpm = ((Long) (mb.getAttribute("RPM")));
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ // Type mismatch should result in a casting exception
+ try {
+ String bad = (String) (mb.getAttribute("CollectionTime"));
+ fail("Should have thrown a ClassCastException");
+ } catch (ClassCastException ignore) {
+ }
+ }// end for
+ }
+
+ public final void testSetAttribute() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+
+ // Let's try and set some non-writable attributes.
+ Attribute attr = new Attribute("Name", "Dando");
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ attr = new Attribute("Valid", new Boolean(true));
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ attr = new Attribute("MemoryPoolNames", new String[] { "X", "Y",
+ "Z" });
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ attr = new Attribute("CollectionCount", new Long(233));
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ attr = new Attribute("CollectionTime", new Long(233));
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+ }// end for
+ }
+
+ @Override
+ protected void populateTestAttributes() {
+ attribs = new Hashtable<String, AttributeData>();
+ attribs.put("MemoryPoolNames", new AttributeData("[Ljava.lang.String;",
+ true, false, false));
+ attribs.put("Name", new AttributeData(String.class.getName(), true,
+ false, false));
+ attribs.put("Valid", new AttributeData(Boolean.TYPE.getName(), true,
+ false, true));
+ attribs.put("CollectionCount", new AttributeData(Long.TYPE.getName(),
+ true, false, false));
+ attribs.put("CollectionTime", new AttributeData(Long.TYPE.getName(),
+ true, false, false));
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/GarbageCollectorMXBeanImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/LoggingMXBeanImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/LoggingMXBeanImplTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/LoggingMXBeanImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/LoggingMXBeanImplTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,237 @@
+/*
+ * 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 com.ibm.lang.management;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+import java.util.logging.LoggingMXBean;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.ReflectionException;
+
+import com.ibm.lang.management.LoggingMXBeanImpl;
+import com.ibm.lang.management.ManagementUtils;
+
+public class LoggingMXBeanImplTest extends SingleInstanceDynamicMXBeanImplTest {
+
+ private Enumeration<String> loggerNames;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mb = (LoggingMXBeanImpl) LogManager.getLoggingMXBean();
+ loggerNames = LogManager.getLogManager().getLoggerNames();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public final void testIsSingleton() {
+ // Verify we always get the same instance
+ LoggingMXBean bean = ManagementUtils.getLoggingBean();
+ assertSame(mb, bean);
+ }
+
+ // -----------------------------------------------------------------
+ // DynamicMBean behaviour tests follow ....
+ // -----------------------------------------------------------------
+
+ public final void testGetAttribute() throws Exception {
+ // Only one readable attribute for this type.
+ assertNotNull(mb.getAttribute("LoggerNames"));
+ assertTrue(mb.getAttribute("LoggerNames") instanceof String[]);
+
+ // A nonexistent attribute should throw an AttributeNotFoundException
+ try {
+ long rpm = ((Long) (mb.getAttribute("RPM")));
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ // Type mismatch should result in a casting exception
+ try {
+ String bad = (String) (mb.getAttribute("LoggerNames"));
+ fail("Should have thrown a ClassCastException");
+ } catch (ClassCastException ignore) {
+ }
+ }
+
+ public final void testSetAttribute() throws Exception {
+ // Nothing is writable for this type
+ Attribute attr = new Attribute("LoggerLevel", "Boris");
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ attr = new Attribute("LoggerNames",
+ new String[] { "Strummer", "Jones" });
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+ }
+
+ public final void testGetAttributes() {
+ AttributeList attributes = mb.getAttributes(attribs.keySet().toArray(
+ new String[] {}));
+ assertNotNull(attributes);
+ assertTrue(attributes.size() == 1);
+
+ // Check the returned value
+ Attribute element = (Attribute) attributes.get(0);
+ assertNotNull(element);
+ assertEquals("LoggerNames", element.getName());
+ Object value = element.getValue();
+ assertNotNull(value);
+ assertTrue(value instanceof String[]);
+ }
+
+ public final void testSetAttributes() {
+ // No writable attributes for this type - should get a failure...
+ AttributeList badList = new AttributeList();
+ Attribute garbage = new Attribute("Name", "City Sickness");
+ Attribute trash = new Attribute("SpecVendor", "Marbles");
+ badList.add(garbage);
+ badList.add(trash);
+ AttributeList setAttrs = mb.setAttributes(badList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() == 0);
+ }
+
+ public final void testInvoke() throws Exception {
+ // 3 different operations that can be invoked on this kind of bean.
+ String logName = null;
+ while (loggerNames.hasMoreElements()) {
+ logName = (String) loggerNames.nextElement();
+ // Store the logger's current log level.
+ Logger logger = LogManager.getLogManager().getLogger(logName);
+ Level originalLevel = logger.getLevel();
+ Logger parentLogger = logger.getParent();
+
+ // Operation #1 --- getLoggerLevel(String)
+ Object retVal = mb.invoke("getLoggerLevel",
+ new Object[] { logName }, new String[] { String.class
+ .getName() });
+ assertNotNull(retVal);
+ assertTrue(retVal instanceof String);
+ if (originalLevel != null) {
+ assertEquals(originalLevel.getName(), (String) retVal);
+ } else {
+ assertEquals("", (String) retVal);
+ }
+
+ // Operation #2 --- getParentLoggerName(String)
+ retVal = mb.invoke("getParentLoggerName", new Object[] { logName },
+ new String[] { String.class.getName() });
+ assertNotNull(retVal);
+ assertTrue(retVal instanceof String);
+ if (parentLogger != null) {
+ assertEquals(parentLogger.getName(), (String) retVal);
+ } else {
+ assertEquals("", (String) retVal);
+ }
+
+ // Call getParentLoggerName(String) again with a bad argument type.
+ try {
+ retVal = mb.invoke("getParentLoggerName",
+ new Object[] { new Long(311) },
+ new String[] { Long.TYPE.getName() });
+ fail("Should have thrown ReflectionException !!");
+ } catch (ReflectionException ignore) {
+ }
+
+ // Operation #3 --- setLoggerLevel(String, String)
+ retVal = mb.invoke("setLoggerLevel", new Object[] { logName,
+ Level.SEVERE.getName() }, new String[] {
+ String.class.getName(), String.class.getName() });
+ // Verify the set worked
+ assertEquals(Level.SEVERE.getName(), logger.getLevel().getName());
+ }// end while
+
+ // Try invoking a bogus operation ...
+ try {
+ Object retVal = mb.invoke("GetUpStandUp", new Object[] {
+ new Long(7446), new Long(54) }, new String[] {
+ "java.lang.Long", "java.lang.Long" });
+ fail("Should have thrown ReflectionException.");
+ } catch (ReflectionException ignore) {
+ }
+ }
+
+ public final void testGetMBeanInfo() {
+ MBeanInfo mbi = mb.getMBeanInfo();
+ assertNotNull(mbi);
+
+ // Now make sure that what we got back is what we expected.
+
+ // Class name
+ assertTrue(mbi.getClassName().equals(mb.getClass().getName()));
+
+ // No public constructors
+ MBeanConstructorInfo[] constructors = mbi.getConstructors();
+ assertNotNull(constructors);
+ assertTrue(constructors.length == 0);
+
+ // Three public operations
+ MBeanOperationInfo[] operations = mbi.getOperations();
+ assertNotNull(operations);
+ assertTrue(operations.length == 3);
+
+ // No notifications
+ MBeanNotificationInfo[] notifications = mbi.getNotifications();
+ assertNotNull(notifications);
+ assertTrue(notifications.length == 0);
+
+ // Description is just the class name (until I hear it should be
+ // different)
+ assertTrue(mbi.getDescription().equals(mb.getClass().getName()));
+
+ // One attribute - not writable.
+ MBeanAttributeInfo[] attributes = mbi.getAttributes();
+ assertNotNull(attributes);
+ assertTrue(attributes.length == 1);
+ MBeanAttributeInfo attribute = attributes[0];
+ assertTrue(attribute.isReadable());
+ assertFalse(attribute.isWritable());
+ assertEquals("LoggerNames", attribute.getName());
+ assertEquals(String[].class.getName(), attribute.getType());
+ }
+
+ @Override
+ protected void populateTestAttributes() {
+ attribs = new Hashtable<String, AttributeData>();
+ attribs.put("LoggerNames", new AttributeData("[Ljava.lang.String;",
+ true, false, false));
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/LoggingMXBeanImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryMXBeanImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryMXBeanImplTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryMXBeanImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryMXBeanImplTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,442 @@
+/*
+ * 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 com.ibm.lang.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryNotificationInfo;
+import java.lang.management.MemoryUsage;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.Notification;
+import javax.management.NotificationFilterSupport;
+import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
+
+import com.ibm.lang.management.ManagementUtils;
+import com.ibm.lang.management.MemoryMXBeanImpl;
+
+public class MemoryMXBeanImplTest extends SingleInstanceDynamicMXBeanImplTest {
+
+ private MemoryMXBeanImpl notifierBean;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mb = (MemoryMXBeanImpl) ManagementFactory.getMemoryMXBean();
+ notifierBean = (MemoryMXBeanImpl) mb;
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // -----------------------------------------------------------------
+ // DynamicMBean behaviour tests follow ....
+ // -----------------------------------------------------------------
+
+ public final void testGetAttribute() throws Exception {
+ // The good attributes...
+ assertNotNull(mb.getAttribute("HeapMemoryUsage"));
+ assertTrue(mb.getAttribute("HeapMemoryUsage") instanceof CompositeData);
+ assertTrue(((CompositeData) (mb.getAttribute("HeapMemoryUsage")))
+ .containsKey("committed"));
+
+ assertNotNull(mb.getAttribute("NonHeapMemoryUsage"));
+ assertTrue(mb.getAttribute("NonHeapMemoryUsage") instanceof CompositeData);
+ assertTrue(((CompositeData) (mb.getAttribute("NonHeapMemoryUsage")))
+ .containsKey("max"));
+
+ assertNotNull(mb.getAttribute("ObjectPendingFinalizationCount"));
+ assertTrue(mb.getAttribute("ObjectPendingFinalizationCount") instanceof Integer);
+
+ assertNotNull(mb.getAttribute("Verbose"));
+ assertTrue(mb.getAttribute("Verbose") instanceof Boolean);
+
+ // A nonexistent attribute should throw an AttributeNotFoundException
+ try {
+ long rpm = ((Long) (mb.getAttribute("RPM")));
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ // Type mismatch should result in a casting exception
+ try {
+ String bad = (String) (mb.getAttribute("HeapMemoryUsage"));
+ fail("Should have thrown a ClassCastException");
+ } catch (ClassCastException ignore) {
+ }
+ }
+
+ public final void testSetAttribute() throws Exception {
+ // The one writable attribute of this type of bean
+ Attribute attr = new Attribute("Verbose", new Boolean(true));
+ mb.setAttribute(attr);
+
+ // Now check the other attributes can't be set...
+ MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
+ CompositeData cd = ManagementUtils.toMemoryUsageCompositeData(mu);
+ attr = new Attribute("HeapMemoryUsage", cd);
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ attr = new Attribute("NonHeapMemoryUsage", cd);
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ attr = new Attribute("ObjectPendingFinalizationCount", new Long(38));
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ // Try and set the Verbose attribute with an incorrect type.
+ attr = new Attribute("Verbose", new Long(42));
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an InvalidAttributeValueException.");
+ } catch (InvalidAttributeValueException ignore) {
+ }
+ }
+
+ public final void testInvoke() throws Exception {
+ // Only one operation for this bean...
+ Object retVal;
+ retVal = mb.invoke("gc", new Object[] {}, null);
+ assertNull(retVal);
+ }
+
+ public final void testGetAttributes() {
+ AttributeList attributes = mb.getAttributes(attribs.keySet().toArray(
+ new String[] {}));
+ assertNotNull(attributes);
+ assertTrue(attributes.size() == attribs.size());
+
+ // Check through the returned values
+ Iterator<?> it = attributes.iterator();
+ while (it.hasNext()) {
+ Attribute element = (Attribute) it.next();
+ assertNotNull(element);
+ String name = element.getName();
+ Object value = element.getValue();
+ if (attribs.containsKey(name)) {
+ if (attribs.get(name).type.equals(Integer.TYPE.getName())) {
+ assertNotNull(value);
+ assertTrue(value instanceof Integer);
+ assertTrue((Integer) value > -1);
+ }// end if a String value expected
+ else if (attribs.get(name).type.equals(Boolean.TYPE.getName())) {
+ boolean tmp = ((Boolean) value).booleanValue();
+ }// end else a long expected
+ else if (attribs.get(name).type.equals(CompositeData.class
+ .getName())) {
+ assertNotNull(value);
+ assertTrue(value instanceof CompositeData);
+ // Sanity check on the contents of the returned
+ // CompositeData instance. For this kind of bean
+ // the "wrapped" type must be a MemoryUsage.
+ CompositeData cd = (CompositeData) value;
+ assertTrue(cd.containsKey("committed"));
+ assertTrue(cd.containsKey("init"));
+ assertTrue(cd.containsKey("max"));
+ assertTrue(cd.containsKey("used"));
+ assertFalse(cd.containsKey("trash"));
+ }// end else a String array expected
+ }// end if a known attribute
+ else {
+ fail("Unexpected attribute name returned!");
+ }// end else an unknown attribute
+ }// end while
+ }
+
+ public final void testSetAttributes() {
+ // Ideal scenario...
+ AttributeList attList = new AttributeList();
+ Attribute verbose = new Attribute("Verbose", new Boolean(false));
+ attList.add(verbose);
+ AttributeList setAttrs = mb.setAttributes(attList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() == 1);
+ assertTrue(((Attribute) (setAttrs.get(0))).getName().equals("Verbose"));
+
+ // A failure scenario - a non-existent attribute...
+ AttributeList badList = new AttributeList();
+ Attribute garbage = new Attribute("H.R. Puffenstuff", new Long(2888));
+ badList.add(garbage);
+ setAttrs = mb.setAttributes(badList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() == 0);
+
+ // Another failure scenario - a non-writable attribute...
+ badList = new AttributeList();
+ garbage = new Attribute("ObjectPendingFinalizationCount", new Integer(
+ 2888));
+ badList.add(garbage);
+ setAttrs = mb.setAttributes(badList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() == 0);
+
+ // Yet another failure scenario - a wrongly-typed attribute...
+ badList = new AttributeList();
+ garbage = new Attribute("Verbose", new Long(2888));
+ badList.add(garbage);
+ setAttrs = mb.setAttributes(badList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() == 0);
+ }
+
+ public final void testGetMBeanInfo() {
+ MBeanInfo mbi = mb.getMBeanInfo();
+ assertNotNull(mbi);
+
+ // Now make sure that what we got back is what we expected.
+
+ // Class name
+ assertTrue(mbi.getClassName().equals(mb.getClass().getName()));
+
+ // No public constructors
+ MBeanConstructorInfo[] constructors = mbi.getConstructors();
+ assertNotNull(constructors);
+ assertTrue(constructors.length == 0);
+
+ // One public operation
+ MBeanOperationInfo[] operations = mbi.getOperations();
+ assertNotNull(operations);
+ assertTrue(operations.length == 1);
+
+ // One notification
+ MBeanNotificationInfo[] notifications = mbi.getNotifications();
+ assertNotNull(notifications);
+ assertTrue(notifications.length == 1);
+
+ // Description is just the class name (until I hear it should be
+ // different)
+ assertTrue(mbi.getDescription().equals(mb.getClass().getName()));
+
+ // Four attributes - some writable.
+ MBeanAttributeInfo[] attributes = mbi.getAttributes();
+ assertNotNull(attributes);
+ assertEquals(4, attributes.length);
+ for (int i = 0; i < attributes.length; i++) {
+ MBeanAttributeInfo info = attributes[i];
+ assertNotNull(info);
+ validateAttributeInfo(info);
+ }// end for
+ }
+
+ // -----------------------------------------------------------------
+ // Notification implementation tests follow ....
+ // -----------------------------------------------------------------
+
+ /*
+ * Class under test for void
+ * removeNotificationListener(NotificationListener, NotificationFilter,
+ * Object)
+ */
+ public final void testRemoveNotificationListenerNotificationListenerNotificationFilterObject()
+ throws Exception {
+ // Register a listener
+ NotificationFilterSupport filter = new NotificationFilterSupport();
+ filter.enableType(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED);
+ SimpleTestListener listener = new SimpleTestListener();
+ notifierBean.addNotificationListener(listener, filter, null);
+
+ // Fire off a notification and ensure that the listener receives it.
+ MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
+ MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
+ CompositeData cd = ManagementUtils
+ .toMemoryNotificationInfoCompositeData(info);
+ Notification notification = new Notification(
+ MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
+ new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
+ notification.setUserData(cd);
+ notifierBean.sendNotification(notification);
+ assertEquals(1, listener.getNotificationsReceivedCount());
+
+ // Remove the listener
+ notifierBean.removeNotificationListener(listener, filter, null);
+
+ // Fire off a notification and ensure that the listener does
+ // *not* receive it.
+ listener.resetNotificationsReceivedCount();
+ notification = new Notification(
+ MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
+ new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
+ notification.setUserData(cd);
+ notifierBean.sendNotification(notification);
+ assertEquals(0, listener.getNotificationsReceivedCount());
+
+ // Try and remove the listener one more time. Should result in a
+ // ListenerNotFoundException being thrown.
+ try {
+ notifierBean.removeNotificationListener(listener, filter, null);
+ fail("Should have thrown a ListenerNotFoundException!");
+ } catch (ListenerNotFoundException e) {
+ }
+ }
+
+ public final void testAddNotificationListener() throws Exception {
+ // Add a listener with a handback object.
+ SimpleTestListener listener = new SimpleTestListener();
+ ArrayList<String> arr = new ArrayList<String>();
+ arr.add("Hegemony or survival ?");
+ notifierBean.addNotificationListener(listener, null, arr);
+
+ // Fire off a notification and ensure that the listener receives it.
+ MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
+ MemoryNotificationInfo info = new MemoryNotificationInfo("Lloyd", mu,
+ 42);
+ CompositeData cd = ManagementUtils
+ .toMemoryNotificationInfoCompositeData(info);
+ Notification notification = new Notification(
+ MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
+ new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
+ notification.setUserData(cd);
+ notifierBean.sendNotification(notification);
+ assertEquals(1, listener.getNotificationsReceivedCount());
+
+ // Verify that the handback is as expected.
+ assertNotNull(listener.getHandback());
+ assertSame(arr, listener.getHandback());
+ ArrayList arr2 = (ArrayList) listener.getHandback();
+ assertTrue(arr2.size() == 1);
+ assertEquals("Hegemony or survival ?", arr2.get(0));
+ }
+
+ /*
+ * Class under test for void
+ * removeNotificationListener(NotificationListener)
+ */
+ public final void testRemoveNotificationListenerNotificationListener()
+ throws Exception {
+ // Add a listener without a filter object.
+ SimpleTestListener listener = new SimpleTestListener();
+ notifierBean.addNotificationListener(listener, null, null);
+ // Fire off a notification and ensure that the listener receives it.
+ MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
+ MemoryNotificationInfo info = new MemoryNotificationInfo("Sinclair",
+ mu, 42);
+ CompositeData cd = ManagementUtils
+ .toMemoryNotificationInfoCompositeData(info);
+ Notification notification = new Notification(
+ MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
+ new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
+ notification.setUserData(cd);
+ notifierBean.sendNotification(notification);
+ assertEquals(1, listener.getNotificationsReceivedCount());
+
+ // Verify that the handback is as expected.
+ assertNull(listener.getHandback());
+
+ // Verify the user data of the notification.
+ Notification n = listener.getNotification();
+ assertNotNull(n);
+ verifyNotificationUserData(n.getUserData());
+
+ // Remove the listener
+ notifierBean.removeNotificationListener(listener);
+
+ // Fire off a notification and ensure that the listener does
+ // *not* receive it.
+ listener.resetNotificationsReceivedCount();
+ notification = new Notification(
+ MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
+ new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
+ notification.setUserData(cd);
+ notifierBean.sendNotification(notification);
+ assertEquals(0, listener.getNotificationsReceivedCount());
+
+ // Try and remove the listener one more time. Should result in a
+ // ListenerNotFoundException being thrown.
+ try {
+ notifierBean.removeNotificationListener(listener);
+ fail("Should have thrown a ListenerNotFoundException!");
+ } catch (ListenerNotFoundException ignore) {
+ }
+ }
+
+ /**
+ * @param userData
+ */
+ private void verifyNotificationUserData(Object userData) {
+ // Should be a CompositeData instance
+ assertTrue(userData instanceof CompositeData);
+ CompositeData cd = (CompositeData) userData;
+ assertTrue(cd.containsKey("poolName"));
+ assertTrue(cd.containsKey("usage"));
+ assertTrue(cd.containsKey("count"));
+ assertTrue(cd.get("poolName") instanceof String);
+ assertTrue(((String) cd.get("poolName")).length() > 0);
+ assertTrue(cd.get("count") instanceof Long);
+ assertTrue(((Long) cd.get("count")) > 0);
+ }
+
+ public final void testGetNotificationInfo() {
+ MBeanNotificationInfo[] notifications = notifierBean
+ .getNotificationInfo();
+ assertNotNull(notifications);
+ assertTrue(notifications.length > 0);
+ for (int i = 0; i < notifications.length; i++) {
+ MBeanNotificationInfo info = notifications[i];
+ assertEquals(Notification.class.getName(), info.getName());
+ assertEquals("Memory Notification", info.getDescription());
+ String[] types = info.getNotifTypes();
+ for (int j = 0; j < types.length; j++) {
+ String type = types[j];
+ assertTrue(type
+ .equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)
+ || type
+ .equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED));
+
+ }// end for
+ }// end for
+ }
+
+ @Override
+ protected void populateTestAttributes() {
+ attribs = new Hashtable<String, AttributeData>();
+ attribs.put("HeapMemoryUsage", new AttributeData(CompositeData.class
+ .getName(), true, false, false));
+ attribs.put("NonHeapMemoryUsage", new AttributeData(CompositeData.class
+ .getName(), true, false, false));
+ attribs.put("ObjectPendingFinalizationCount", new AttributeData(
+ Integer.TYPE.getName(), true, false, false));
+ attribs.put("Verbose", new AttributeData(Boolean.TYPE.getName(), true,
+ true, true));
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryMXBeanImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryManagerImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryManagerImplTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryManagerImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryManagerImplTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,253 @@
+/*
+ * 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 com.ibm.lang.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryManagerMXBean;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+
+import com.ibm.lang.management.DynamicMXBeanImpl;
+import com.ibm.lang.management.GarbageCollectorMXBeanImpl;
+import com.ibm.lang.management.MemoryManagerMXBeanImpl;
+
+public class MemoryManagerImplTest extends MultiInstanceDynamicMXBeanImplTest {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ List<MemoryManagerMXBean> allBeans = ManagementFactory
+ .getMemoryManagerMXBeans();
+ mbList = new ArrayList<DynamicMXBeanImpl>();
+ for (MemoryManagerMXBean bean : allBeans) {
+ mbList.add((MemoryManagerMXBeanImpl) bean);
+ }// end for
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // -----------------------------------------------------------------
+ // DynamicMBean behaviour tests follow ....
+ // -----------------------------------------------------------------
+ public final void testGetAttributes() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+ AttributeList attributes = mb.getAttributes(attribs.keySet()
+ .toArray(new String[] {}));
+ assertNotNull(attributes);
+ assertTrue(attributes.size() == attribs.size());
+
+ // Check through the returned values
+ Iterator<?> it = attributes.iterator();
+ while (it.hasNext()) {
+ Attribute element = (Attribute) it.next();
+ assertNotNull(element);
+ String name = element.getName();
+ Object value = element.getValue();
+ if (name.equals("Valid")) {
+ // This could be true or false - just so long as we don't
+ // get an exception raised...
+ boolean validVal = ((Boolean) value).booleanValue();
+ } else if (name.equals("Name")) {
+ assertNotNull(value);
+ assertTrue(value instanceof String);
+ assertTrue(((String) value).length() > 0);
+ } else if (name.equals("MemoryPoolNames")) {
+ assertNotNull(value);
+ assertTrue(value instanceof String[]);
+ String[] strVals = (String[]) value;
+ for (int i = 0; i < strVals.length; i++) {
+ String poolName = strVals[i];
+ assertNotNull(poolName);
+ assertTrue(poolName.length() > 0);
+ }// end for
+ }
+ }// end while
+ }// end for
+ }
+
+ public final void testSetAttributes() {
+ AttributeList badList = new AttributeList();
+ Attribute garbage = new Attribute("Name", "Bez");
+ badList.add(garbage);
+ for (DynamicMXBeanImpl mb : mbList) {
+ // No writable attributes for this type
+ AttributeList setAttrs = mb.setAttributes(badList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() == 0);
+ }
+ }
+
+ public final void testGetMBeanInfo() {
+ for (DynamicMXBeanImpl mb : mbList) {
+ MBeanInfo mbi = mb.getMBeanInfo();
+ assertNotNull(mbi);
+
+ // Now make sure that what we got back is what we expected.
+
+ // Class name
+ assertTrue(mbi.getClassName().equals(mb.getClass().getName()));
+
+ // No public constructors
+ MBeanConstructorInfo[] constructors = mbi.getConstructors();
+ assertNotNull(constructors);
+ assertTrue(constructors.length == 0);
+
+ // No public operations
+ MBeanOperationInfo[] operations = mbi.getOperations();
+ assertNotNull(operations);
+ assertTrue(operations.length == 0);
+
+ // No notifications
+ MBeanNotificationInfo[] notifications = mbi.getNotifications();
+ assertNotNull(notifications);
+ assertTrue(notifications.length == 0);
+
+ // Description is just the class name (until I hear it should be
+ // different)
+ assertTrue(mbi.getDescription().equals(mb.getClass().getName()));
+
+ // The number of attributes depends on what kind of
+ // MemoryManagerMXBean we have.
+ MBeanAttributeInfo[] attributes = mbi.getAttributes();
+ assertNotNull(attributes);
+ String runtimeType = mb.getClass().getName();
+ if (runtimeType.equals(MemoryManagerMXBeanImpl.class.getName())) {
+ assertEquals(3, attributes.length);
+ validateMemoryManagerAttributes(attributes);
+ } else if (runtimeType.equals(GarbageCollectorMXBeanImpl.class
+ .getName())) {
+ assertEquals(5, attributes.length);
+ validateGCAttributes(attributes);
+ } else {
+ fail("Unexpected kind of memory manager MXBean : "
+ + runtimeType);
+ }
+ }// end for
+ }
+
+ /**
+ * @param attributes
+ */
+ private void validateMemoryManagerAttributes(MBeanAttributeInfo[] attributes) {
+ for (int i = 0; i < attributes.length; i++) {
+ MBeanAttributeInfo info = attributes[i];
+ assertNotNull(info);
+ validateAttributeInfo(info);
+ }// end for
+ }
+
+ /**
+ * @param attributes
+ */
+ private void validateGCAttributes(MBeanAttributeInfo[] attributes) {
+ GarbageCollectorMXBeanImplTest gcTest = new GarbageCollectorMXBeanImplTest();
+ for (int i = 0; i < attributes.length; i++) {
+ MBeanAttributeInfo info = attributes[i];
+ assertNotNull(info);
+ gcTest.validateAttributeInfo(info);
+ }// end for
+ }
+
+ public final void testGetAttribute() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+ // The good attributes...
+ assertTrue(mb.getAttribute("MemoryPoolNames") instanceof String[]);
+ String[] arr = (String[]) mb.getAttribute("MemoryPoolNames");
+ for (int i = 0; i < arr.length; i++) {
+ String element = arr[i];
+ assertNotNull(element);
+ assertTrue(element.length() > 0);
+ }// end for
+
+ assertTrue(mb.getAttribute("Name") instanceof String);
+ assertTrue(((String) mb.getAttribute("Name")).length() > 0);
+
+ // This could be true or false - just so long as we don't get an
+ // exception raised...
+ boolean validVal = ((Boolean) (mb.getAttribute("Valid")));
+
+ // A nonexistent attribute should throw an
+ // AttributeNotFoundException
+ try {
+ long rpm = ((Long) (mb.getAttribute("RPM")));
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ // Type mismatch should result in a casting exception
+ try {
+ String bad = (String) (mb.getAttribute("MemoryPoolNames"));
+ fail("Should have thrown a ClassCastException");
+ } catch (ClassCastException ignore) {
+ }
+ }// end for
+ }
+
+ public final void testSetAttribute() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+ // Let's try and set some non-writable attributes.
+ Attribute attr = new Attribute("Name", "Dando");
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ attr = new Attribute("Valid", new Boolean(true));
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ attr = new Attribute("MemoryPoolNames", new String[] { "X", "Y",
+ "Z" });
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+ }// end for
+ }
+
+ @Override
+ protected void populateTestAttributes() {
+ attribs = new Hashtable<String, AttributeData>();
+ attribs.put("MemoryPoolNames", new AttributeData("[Ljava.lang.String;",
+ true, false, false));
+ attribs.put("Name", new AttributeData(String.class.getName(), true,
+ false, false));
+ attribs.put("Valid", new AttributeData(Boolean.TYPE.getName(), true,
+ false, true));
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryManagerImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryPoolMXBeanImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryPoolMXBeanImplTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryPoolMXBeanImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryPoolMXBeanImplTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,598 @@
+/*
+ * 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 com.ibm.lang.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryPoolMXBean;
+import java.lang.management.MemoryUsage;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.ReflectionException;
+import javax.management.openmbean.CompositeData;
+
+import com.ibm.lang.management.DynamicMXBeanImpl;
+import com.ibm.lang.management.MemoryPoolMXBeanImpl;
+
+public class MemoryPoolMXBeanImplTest extends
+ MultiInstanceDynamicMXBeanImplTest {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mbList = new ArrayList<DynamicMXBeanImpl>();
+ List<MemoryPoolMXBean> allBeans = ManagementFactory
+ .getMemoryPoolMXBeans();
+ for (MemoryPoolMXBean bean : allBeans) {
+ mbList.add((MemoryPoolMXBeanImpl) bean);
+ }
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // -----------------------------------------------------------------
+ // DynamicMBean behaviour tests follow ....
+ // -----------------------------------------------------------------
+
+ public final void testGetAttributes() {
+ for (DynamicMXBeanImpl mb : mbList) {
+ AttributeList attributes = mb.getAttributes(attribs.keySet()
+ .toArray(new String[] {}));
+ assertNotNull(attributes);
+ assertTrue(attributes.size() <= attribs.size());
+
+ Iterator<?> it = attributes.iterator();
+ while (it.hasNext()) {
+ Attribute element = (Attribute) it.next();
+ assertNotNull(element);
+ String name = element.getName();
+ Object value = element.getValue();
+ if (name.equals("CollectionUsage")) {
+ // Could return a null value if VM does not support
+ // the method.
+ if (value != null) {
+ assertTrue(value instanceof CompositeData);
+ MemoryUsage mu = MemoryUsage
+ .from((CompositeData) value);
+ assertTrue(mu.getCommitted() != -1);
+ assertTrue(mu.getUsed() != -1);
+ }
+ } else if (name.equals("CollectionUsageThreshold")) {
+ assertTrue(value instanceof Long);
+ assertTrue(((Long) (value)) > -1);
+ } else if (name.equals("CollectionUsageThresholdCount")) {
+ assertTrue(value instanceof Long);
+ assertTrue(((Long) (value)) > -1);
+ } else if (name.equals("MemoryManagerNames")) {
+ assertTrue(value instanceof String[]);
+ String[] names = (String[]) value;
+ assertTrue(names.length > 0);
+ for (int i = 0; i < names.length; i++) {
+ String string = names[i];
+ assertNotNull(string);
+ assertTrue(string.length() > 0);
+ }// end for
+ } else if (name.equals("Name")) {
+ assertTrue(value instanceof String);
+ String str = (String) value;
+ assertNotNull(str);
+ } else if (name.equals("PeakUsage")) {
+ assertTrue(value instanceof CompositeData);
+ MemoryUsage mu = MemoryUsage.from((CompositeData) value);
+ assertNotNull(mu);
+ assertTrue(mu.getCommitted() != -1);
+ assertTrue(mu.getUsed() != -1);
+ } else if (name.equals("Type")) {
+ assertTrue(value instanceof String);
+ String str = (String) value;
+ assertNotNull(str);
+ } else if (name.equals("Usage")) {
+ assertTrue(value instanceof CompositeData);
+ MemoryUsage mu = MemoryUsage.from((CompositeData) value);
+ assertNotNull(mu);
+ assertTrue(mu.getCommitted() != -1);
+ assertTrue(mu.getUsed() != -1);
+ } else if (name.equals("UsageThreshold")) {
+ assertTrue(value instanceof Long);
+ assertTrue(((Long) (value)) > -1);
+ } else if (name.equals("UsageThresholdCount")) {
+ assertTrue(value instanceof Long);
+ assertTrue(((Long) (value)) > -1);
+ } else if (name.equals("CollectionUsageThresholdExceeded")) {
+ assertTrue(value instanceof Boolean);
+ } else if (name.equals("CollectionUsageThresholdSupported")) {
+ assertTrue(value instanceof Boolean);
+ } else if (name.equals("UsageThresholdExceeded")) {
+ assertTrue(value instanceof Boolean);
+ } else if (name.equals("UsageThresholdSupported")) {
+ assertTrue(value instanceof Boolean);
+ } else if (name.equals("Valid")) {
+ assertTrue(value instanceof Boolean);
+ } else {
+ fail("Unexpected attribute returned : " + name + " !!");
+ }
+ }// end while
+ }// end for
+ }
+
+ public final void testSetAttributes() {
+ for (DynamicMXBeanImpl mb : mbList) {
+ // Only two attributes can be set for this platform bean type
+ // - UsageThreshold and CollectionUsageThreshold
+ AttributeList attList = new AttributeList();
+ Attribute newUT = new Attribute("UsageThreshold", new Long(
+ 100 * 1024));
+ attList.add(newUT);
+ AttributeList setAttrs = mb.setAttributes(attList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() <= 1);
+
+ if (setAttrs.size() == 1) {
+ assertTrue(((Attribute) (setAttrs.get(0))).getName().equals(
+ "UsageThreshold"));
+ assertTrue(((Attribute) (setAttrs.get(0))).getValue() instanceof Long);
+ long recoveredValue = (Long) ((Attribute) (setAttrs.get(0)))
+ .getValue();
+ assertEquals(100 * 1024, recoveredValue);
+ }
+
+ attList = new AttributeList();
+ Attribute newCUT = new Attribute("CollectionUsageThreshold",
+ new Long(250 * 1024));
+ attList.add(newCUT);
+ setAttrs = mb.setAttributes(attList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() <= 1);
+
+ if (setAttrs.size() == 1) {
+ assertTrue(((Attribute) (setAttrs.get(0))).getName().equals(
+ "CollectionUsageThreshold"));
+ assertTrue(((Attribute) (setAttrs.get(0))).getValue() instanceof Long);
+ long recoveredValue = (Long) ((Attribute) (setAttrs.get(0)))
+ .getValue();
+ assertEquals(250 * 1024, recoveredValue);
+ }
+
+ // A failure scenario - a non-existent attribute...
+ AttributeList badList = new AttributeList();
+ Attribute garbage = new Attribute("Bantry", new Long(2888));
+ badList.add(garbage);
+ setAttrs = mb.setAttributes(badList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() == 0);
+
+ // Another failure scenario - a non-writable attribute...
+ badList = new AttributeList();
+ garbage = new Attribute("Name", new String("george"));
+ badList.add(garbage);
+ setAttrs = mb.setAttributes(badList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() == 0);
+
+ // Yet another failure scenario - a wrongly-typed attribute...
+ badList = new AttributeList();
+ garbage = new Attribute("CollectionUsageThreshold", new Boolean(
+ true));
+ badList.add(garbage);
+ setAttrs = mb.setAttributes(badList);
+ assertNotNull(setAttrs);
+ assertTrue(setAttrs.size() == 0);
+ }// end for
+ }
+
+ public final void testGetMBeanInfo() {
+ for (DynamicMXBeanImpl mb : mbList) {
+ MBeanInfo mbi = mb.getMBeanInfo();
+ assertNotNull(mbi);
+
+ // Now make sure that what we got back is what we expected.
+
+ // Class name
+ assertTrue(mbi.getClassName().equals(mb.getClass().getName()));
+
+ // No public constructors
+ MBeanConstructorInfo[] constructors = mbi.getConstructors();
+ assertNotNull(constructors);
+ assertTrue(constructors.length == 0);
+
+ // One public operation - resetPeakUsage
+ MBeanOperationInfo[] operations = mbi.getOperations();
+ assertNotNull(operations);
+ assertTrue(operations.length == 1);
+ assertEquals("resetPeakUsage", operations[0].getName());
+
+ // No notifications
+ MBeanNotificationInfo[] notifications = mbi.getNotifications();
+ assertNotNull(notifications);
+ assertTrue(notifications.length == 0);
+
+ // Description is just the class name (until I hear it should be
+ // different)
+ assertTrue(mbi.getDescription().equals(mb.getClass().getName()));
+
+ // Fifteen attributes - only two are writable.
+ MBeanAttributeInfo[] attributes = mbi.getAttributes();
+ assertNotNull(attributes);
+ assertEquals(15, attributes.length);
+ for (int i = 0; i < attributes.length; i++) {
+ MBeanAttributeInfo info = attributes[i];
+ assertNotNull(info);
+ validateAttributeInfo(info);
+ }// end for
+ }// end for
+ }
+
+ public final void testGetAttribute() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+ // The 14 good public attributes...
+ {
+ // If collection usage not supported then we can get a
+ // null return here.
+ CompositeData cd = (CompositeData) mb
+ .getAttribute("CollectionUsage");
+ if (cd != null) {
+ MemoryUsage mu = MemoryUsage.from(cd);
+ assertTrue(mu.getCommitted() != -1);
+ assertTrue(mu.getUsed() != -1);
+ }
+ }
+
+ {
+ if (((MemoryPoolMXBean) mb)
+ .isCollectionUsageThresholdSupported()) {
+ Long l = (Long) mb.getAttribute("CollectionUsageThreshold");
+ assertNotNull(l);
+ assertTrue(l > -1);
+ } else {
+ try {
+ Long l = (Long) mb
+ .getAttribute("CollectionUsageThreshold");
+ } catch (UnsupportedOperationException ignore) {
+ }
+ }// end else collection usage threshold is not supported
+ }
+
+ {
+ if (((MemoryPoolMXBean) mb)
+ .isCollectionUsageThresholdSupported()) {
+ Long l = (Long) mb
+ .getAttribute("CollectionUsageThresholdCount");
+ assertNotNull(l);
+ assertTrue(l > -1);
+ } else {
+ try {
+ Long l = (Long) mb
+ .getAttribute("CollectionUsageThresholdCount");
+ fail("Should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException ignore) {
+ }
+ }// end else collection usage threshold is not supported
+ }
+
+ {
+ String[] names = (String[]) mb
+ .getAttribute("MemoryManagerNames");
+ assertNotNull(names);
+ for (int i = 0; i < names.length; i++) {
+ String string = names[i];
+ assertNotNull(string);
+ assertTrue(string.length() > 0);
+ }// end for
+ }
+
+ {
+ String name = (String) mb.getAttribute("Name");
+ assertNotNull(name);
+ assertTrue(name.length() > 0);
+ }
+
+ {
+ CompositeData cd = (CompositeData) mb.getAttribute("PeakUsage");
+
+ if (((MemoryPoolMXBean) mb).isValid()) {
+ assertNotNull(cd);
+ MemoryUsage mu = MemoryUsage.from(cd);
+ assertTrue(mu.getCommitted() != -1);
+ assertTrue(mu.getUsed() != -1);
+ } else {
+ assertNull(cd);
+ }
+ }
+
+ {
+ String name = (String) mb.getAttribute("Type");
+ assertNotNull(name);
+ assertTrue(name.length() > 0);
+ }
+
+ {
+ CompositeData cd = (CompositeData) mb.getAttribute("Usage");
+ if (((MemoryPoolMXBean) mb).isValid()) {
+ assertNotNull(cd);
+ MemoryUsage mu = MemoryUsage.from(cd);
+ assertTrue(mu.getCommitted() != -1);
+ assertTrue(mu.getUsed() != -1);
+ } else {
+ assertNull(cd);
+ }
+ }
+
+ {
+ if (((MemoryPoolMXBean) mb).isUsageThresholdSupported()) {
+ Long l = (Long) mb.getAttribute("UsageThreshold");
+ assertNotNull(l);
+ assertTrue(l > -1);
+ } else {
+ try {
+ Long l = (Long) mb.getAttribute("UsageThreshold");
+ fail("Should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException ignore) {
+ }
+ }// end else usage threshold not supported
+ }
+
+ {
+ if (((MemoryPoolMXBean) mb).isUsageThresholdSupported()) {
+ Long l = (Long) mb.getAttribute("UsageThresholdCount");
+ assertNotNull(l);
+ assertTrue(l > -1);
+ } else {
+ try {
+ Long l = (Long) mb.getAttribute("UsageThresholdCount");
+ fail("Should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException ignore) {
+ }
+ }// end else usage threshold not supported
+ }
+
+ {
+ if (((MemoryPoolMXBean) mb)
+ .isCollectionUsageThresholdSupported()) {
+ Boolean b = (Boolean) mb
+ .getAttribute("CollectionUsageThresholdExceeded");
+ assertNotNull(b);
+ } else {
+ try {
+ Boolean b = (Boolean) mb
+ .getAttribute("CollectionUsageThresholdExceeded");
+ fail("Should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException ignore) {
+ }
+ }// end else collection usage threshold not supported
+ }
+
+ {
+ Boolean b = (Boolean) mb
+ .getAttribute("CollectionUsageThresholdSupported");
+ assertNotNull(b);
+ }
+
+ {
+ if (((MemoryPoolMXBean) mb).isUsageThresholdSupported()) {
+ Boolean b = (Boolean) mb
+ .getAttribute("UsageThresholdExceeded");
+ assertNotNull(b);
+ } else {
+ try {
+ Boolean b = (Boolean) mb
+ .getAttribute("UsageThresholdExceeded");
+ fail("Should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException ignore) {
+ }
+ }// end else usage threshold not supported
+ }
+
+ {
+ Boolean b = (Boolean) mb
+ .getAttribute("UsageThresholdSupported");
+ assertNotNull(b);
+ }
+
+ {
+ Boolean b = (Boolean) mb.getAttribute("Valid");
+ assertNotNull(b);
+ }
+
+ // A nonexistent attribute should throw an
+ // AttributeNotFoundException
+ try {
+ long rpm = ((Long) (mb.getAttribute("RPM")));
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException ignore) {
+ }
+
+ // Type mismatch should result in a casting exception
+ try {
+ Long bad = (Long) (mb.getAttribute("Name"));
+ fail("Should have thrown a ClassCastException");
+ } catch (ClassCastException ignore) {
+ }
+ }// end for
+ }
+
+ public void testSetUsageThresholdAttribute() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+ if (((MemoryPoolMXBean) mb).isUsageThresholdSupported()) {
+ long originalUT = (Long) mb.getAttribute("UsageThreshold");
+ long newUT = originalUT + 1024;
+ Attribute newUTAttr = new Attribute("UsageThreshold", new Long(
+ newUT));
+ mb.setAttribute(newUTAttr);
+
+ assertEquals(new Long(newUT), (Long) mb
+ .getAttribute("UsageThreshold"));
+ } else {
+ try {
+ Attribute newUTAttr = new Attribute("UsageThreshold",
+ new Long(100 * 1024));
+ mb.setAttribute(newUTAttr);
+ fail("Should have thrown UnsupportedOperationException!");
+ } catch (UnsupportedOperationException ignore) {
+ }
+ }// end else usage threshold is not supported
+ }
+ }
+
+ public void testSetCollectionUsageThresholdAttribute() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+ if (((MemoryPoolMXBean) mb).isCollectionUsageThresholdSupported()) {
+ long originalCUT = (Long) mb
+ .getAttribute("CollectionUsageThreshold");
+ long newCUT = originalCUT + 1024;
+ Attribute newCUTAttr = new Attribute(
+ "CollectionUsageThreshold", new Long(newCUT));
+ mb.setAttribute(newCUTAttr);
+
+ assertEquals(new Long(newCUT), (Long) mb
+ .getAttribute("CollectionUsageThreshold"));
+ } else {
+ try {
+ Attribute newCUTAttr = new Attribute(
+ "CollectionUsageThreshold", new Long(100 * 1024));
+ mb.setAttribute(newCUTAttr);
+ fail("Should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException ignore) {
+ }
+ }// end else collection usage threshold is not supported
+ }// end for
+ }
+
+ @Override
+ public void testSetAttribute() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+ // Good case - set the UsageThreshold value
+ if (((Boolean) mb.getAttribute("UsageThresholdSupported"))) {
+ Attribute attr = new Attribute("UsageThreshold", new Long(
+ 68 * 1024));
+ mb.setAttribute(attr);
+ } else {
+ try {
+ Long l = (Long) mb.getAttribute("UsageThreshold");
+ fail("Should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException ignore) {
+ }
+ }// end else usage threshold not supported
+
+ // Good case - set the CollectionUsageThreshold value
+ if (((Boolean) mb.getAttribute("CollectionUsageThresholdSupported"))) {
+ Attribute attr = new Attribute("CollectionUsageThreshold",
+ new Long(99 * 1024));
+ mb.setAttribute(attr);
+ } else {
+ try {
+ Long l = (Long) mb.getAttribute("UsageThreshold");
+ fail("Should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException ignore) {
+ }
+ }// end else usage threshold not supported
+
+ // Let's try and set some non-writable attributes.
+ Attribute attr = new Attribute("UsageThresholdCount", new Long(25));
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an AttributeNotFoundException.");
+ } catch (AttributeNotFoundException e) {
+ }
+
+ // Try and set the UsageThreshold attribute with an incorrect
+ // type.
+ attr = new Attribute("UsageThreshold", "rubbish");
+ try {
+ mb.setAttribute(attr);
+ fail("Should have thrown an InvalidAttributeValueException");
+ } catch (InvalidAttributeValueException ignore) {
+ }
+ }// end for
+ }
+
+ public final void testInvoke() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+ // We have one operation - resetPeakUsage() which should reset
+ // *peak* usage to the current memory usage.
+ Object retVal = mb.invoke("resetPeakUsage", new Object[] {}, null);
+ assertNull(retVal);
+
+ // Try and invoke a non-existent method...
+ try {
+ retVal = mb.invoke("madeupMethod", new Object[] { "fibber" },
+ new String[] { String.class.getName() });
+ fail("Should have thrown a ReflectionException");
+ } catch (ReflectionException ignore) {
+ }
+
+ MemoryUsage currentMU = MemoryUsage.from((CompositeData) mb
+ .getAttribute("Usage"));
+ MemoryUsage peakMU = MemoryUsage.from((CompositeData) mb
+ .getAttribute("PeakUsage"));
+ assertEquals(currentMU.getCommitted(), peakMU.getCommitted());
+ assertEquals(currentMU.getInit(), peakMU.getInit());
+ assertEquals(currentMU.getUsed(), peakMU.getUsed());
+ assertEquals(currentMU.getMax(), peakMU.getMax());
+ }// end for
+ }
+
+ @Override
+ protected void populateTestAttributes() {
+ attribs = new Hashtable<String, AttributeData>();
+ attribs.put("CollectionUsage", new AttributeData(CompositeData.class
+ .getName(), true, false, false));
+ attribs.put("CollectionUsageThreshold", new AttributeData(Long.TYPE
+ .getName(), true, true, false));
+ attribs.put("CollectionUsageThresholdCount", new AttributeData(
+ Long.TYPE.getName(), true, false, false));
+ attribs.put("MemoryManagerNames", new AttributeData(
+ "[Ljava.lang.String;", true, false, false));
+ attribs.put("Name", new AttributeData(String.class.getName(), true,
+ false, false));
+ attribs.put("PeakUsage", new AttributeData(CompositeData.class
+ .getName(), true, false, false));
+ attribs.put("Type", new AttributeData(String.class.getName(), true,
+ false, false));
+ attribs.put("Usage", new AttributeData(CompositeData.class.getName(),
+ true, false, false));
+ attribs.put("UsageThreshold", new AttributeData(Long.TYPE.getName(),
+ true, true, false));
+ attribs.put("UsageThresholdCount", new AttributeData(Long.TYPE
+ .getName(), true, false, false));
+ attribs.put("CollectionUsageThresholdExceeded", new AttributeData(
+ Boolean.TYPE.getName(), true, false, true));
+ attribs.put("CollectionUsageThresholdSupported", new AttributeData(
+ Boolean.TYPE.getName(), true, false, true));
+ attribs.put("UsageThresholdExceeded", new AttributeData(Boolean.TYPE
+ .getName(), true, false, true));
+ attribs.put("UsageThresholdSupported", new AttributeData(Boolean.TYPE
+ .getName(), true, false, true));
+ attribs.put("Valid", new AttributeData(Boolean.TYPE.getName(), true,
+ false, true));
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MemoryPoolMXBeanImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MultiInstanceDynamicMXBeanImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MultiInstanceDynamicMXBeanImplTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MultiInstanceDynamicMXBeanImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MultiInstanceDynamicMXBeanImplTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,59 @@
+/*
+ * 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 com.ibm.lang.management;
+
+import java.util.List;
+
+import javax.management.AttributeList;
+import javax.management.ReflectionException;
+
+import com.ibm.lang.management.DynamicMXBeanImpl;
+
+public abstract class MultiInstanceDynamicMXBeanImplTest extends
+ DynamicMXBeanImplTest {
+
+ protected List<DynamicMXBeanImpl> mbList;
+
+ public void testInvoke() throws Exception {
+ // Default for DynamicMXBeanImpl that has no operations to invoke...
+ for (DynamicMXBeanImpl mb : mbList) {
+ // No operations to invoke...
+ try {
+ Object retVal = mb.invoke("KissTheRoadOfRoratonga",
+ new Object[] { new Long(7446), new Long(54) },
+ new String[] { "java.lang.Long", "java.lang.Long" });
+ fail("Should have thrown a ReflectionException.");
+ } catch (ReflectionException ignore) {
+ }
+ }// end for
+ }
+
+ public void testGetAttributesBad() throws Exception {
+ for (DynamicMXBeanImpl mb : mbList) {
+ String[] badNames = { "Cork", "Galway" };
+ AttributeList attributes = mb.getAttributes(badNames);
+ assertNotNull(attributes);
+ // No attributes will have been returned.
+ assertTrue(attributes.size() == 0);
+
+ }// end for
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/MultiInstanceDynamicMXBeanImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native