use of java.lang.management.MemoryPoolMXBean in project openj9 by eclipse.
the class TestMemoryPoolMXBean method testInvoke.
@Test
public final void testInvoke() {
MemoryPoolMXBean testImpl = testBean;
// usage to the current memory usage.
try {
Object retVal = null;
try {
retVal = mbs.invoke(objName, "resetPeakUsage", new Object[] {}, null);
} catch (InstanceNotFoundException e) {
// InstanceNotFoundException is an unlikely exception - if this occurs, we
// can proceed with the test.
Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
}
MemoryUsage currentMU = testImpl.getUsage();
MemoryUsage peakMU = testImpl.getPeakUsage();
logger.debug("currentMU : " + currentMU);
logger.debug("peakMU : " + peakMU);
AssertJUnit.assertNull(retVal);
} catch (Exception e) {
Assert.fail("Unexpected exception: " + e.getMessage());
}
// Try and invoke a non-existent method...
try {
Object retVal = mbs.invoke(objName, "madeupMethod", new Object[] { "fibber" }, new String[] { String.class.getName() });
Assert.fail("Unreacheable code: should have thrown an exception calling a non-existent operation");
} catch (MBeanException e) {
Assert.fail("Unexpected MBeanException occurred: " + e.getMessage());
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof ReflectionException);
logger.debug("ReflectionException occurred, as expected: attempted to invoke non-existent method.");
}
}
use of java.lang.management.MemoryPoolMXBean in project openj9 by eclipse.
the class TestMemoryPoolMXBean method testGetAttribute.
@Test
public final void testGetAttribute() {
MemoryPoolMXBean testImpl = testBean;
try {
// The 14 good public attributes...
{
// null return here.
try {
CompositeData cd = (CompositeData) mbs.getAttribute(objName, "CollectionUsage");
if (cd != null) {
logger.debug("CollectionUsage : cd=" + cd);
MemoryUsage mu = MemoryUsage.from(cd);
AssertJUnit.assertTrue(mu.getCommitted() != -1);
AssertJUnit.assertTrue(mu.getUsed() != -1);
logger.debug("CollectionUsage : " + mu);
}
} catch (Exception e) {
// logger.debug("**Error TestMemoryPoolMXBean testImpl: "+ testImpl.getName() +", testGetAttribute() Exception: "+ e.getClass().getName());
Assert.fail("Unexpected exception : " + e.getClass().getName());
}
}
try {
if (testImpl.isCollectionUsageThresholdSupported()) {
Long l = (Long) mbs.getAttribute(objName, "CollectionUsageThreshold");
AssertJUnit.assertNotNull(l);
AssertJUnit.assertTrue(l > -1);
} else {
try {
Long l = (Long) mbs.getAttribute(objName, "CollectionUsageThreshold");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof javax.management.RuntimeMBeanException);
logger.debug("Exception occurred: as expected (collection usage threshold not supported).");
}
}
// end else collection usage threshold is not supported
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
if (testImpl.isCollectionUsageThresholdSupported()) {
Long l = (Long) mbs.getAttribute(objName, "CollectionUsageThresholdCount");
AssertJUnit.assertNotNull(l);
AssertJUnit.assertTrue(l > -1);
} else {
try {
Long l = (Long) mbs.getAttribute(objName, "CollectionUsageThresholdCount");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof javax.management.RuntimeMBeanException);
logger.debug("Exception occurred: as expected (collection usage threshold count not supported).");
}
}
// end else collection usage threshold is not supported
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
String[] names = (String[]) mbs.getAttribute(objName, "MemoryManagerNames");
AssertJUnit.assertNotNull(names);
for (int i = 0; i < names.length; i++) {
String string = names[i];
AssertJUnit.assertNotNull(string);
AssertJUnit.assertTrue(string.length() > 0);
logger.debug("MemoryManagerNames[" + i + "] = " + string);
}
// end for
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
String name = (String) mbs.getAttribute(objName, "Name");
AssertJUnit.assertNotNull(name);
AssertJUnit.assertTrue(name.length() > 0);
logger.debug("Name is " + name);
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
CompositeData cd = (CompositeData) mbs.getAttribute(objName, "PeakUsage");
if (testImpl.isValid()) {
AssertJUnit.assertNotNull(cd);
MemoryUsage mu = MemoryUsage.from(cd);
AssertJUnit.assertTrue(mu.getCommitted() != -1);
AssertJUnit.assertTrue(mu.getUsed() != -1);
logger.debug("PeakUsage : " + mu);
} else {
AssertJUnit.assertNull(cd);
}
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
String name = (String) mbs.getAttribute(objName, "Type");
AssertJUnit.assertNotNull(name);
AssertJUnit.assertTrue(name.length() > 0);
logger.debug("Type is " + name);
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
CompositeData cd = (CompositeData) mbs.getAttribute(objName, "Usage");
if (testImpl.isValid()) {
AssertJUnit.assertNotNull(cd);
MemoryUsage mu = MemoryUsage.from(cd);
AssertJUnit.assertTrue(mu.getCommitted() != -1);
AssertJUnit.assertTrue(mu.getUsed() != -1);
logger.debug("Usage : " + mu);
} else {
AssertJUnit.assertNull(cd);
}
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
if (testImpl.isUsageThresholdSupported()) {
Long l = (Long) mbs.getAttribute(objName, "UsageThreshold");
AssertJUnit.assertNotNull(l);
AssertJUnit.assertTrue(l > -1);
logger.debug("Usage threshold = " + l);
} else {
try {
Long l = (Long) mbs.getAttribute(objName, "UsageThreshold");
Assert.fail("Unreacheable code: should have thrown exception");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof javax.management.RuntimeMBeanException);
logger.debug("Exception occurred: as expected (usage threshold not supported).");
}
}
// end else usage threshold not supported
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
if (testImpl.isUsageThresholdSupported()) {
Long l = (Long) mbs.getAttribute(objName, "UsageThresholdCount");
AssertJUnit.assertNotNull(l);
AssertJUnit.assertTrue(l > -1);
logger.debug("Usage threshold count = " + l);
} else {
try {
Long l = (Long) mbs.getAttribute(objName, "UsageThresholdCount");
Assert.fail("Unreacheable code: should have thrown exception");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof javax.management.RuntimeMBeanException);
logger.debug("Exception occurred: as expected (usage threshold count not supported).");
}
}
// end else usage threshold not supported
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
if (testImpl.isCollectionUsageThresholdSupported()) {
Boolean b = (Boolean) mbs.getAttribute(objName, "CollectionUsageThresholdExceeded");
AssertJUnit.assertNotNull(b);
logger.debug("CollectionUsageThresholdExceeded is " + b);
} else {
try {
Boolean b = (Boolean) mbs.getAttribute(objName, "CollectionUsageThresholdExceeded");
Assert.fail("Unreacheable code: should have thrown exception");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof javax.management.RuntimeMBeanException);
logger.debug("Exception occurred: " + "as expected (collection usage threshold exceeded not supported).");
}
}
// end else collection usage threshold not supported
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
Boolean b = (Boolean) mbs.getAttribute(objName, "CollectionUsageThresholdSupported");
AssertJUnit.assertNotNull(b);
logger.debug("CollectionUsageThresholdSupported is " + b);
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
if (testImpl.isUsageThresholdSupported()) {
Boolean b = (Boolean) mbs.getAttribute(objName, "UsageThresholdExceeded");
AssertJUnit.assertNotNull(b);
logger.debug("UsageThresholdExceeded is " + b);
} else {
try {
Boolean b = (Boolean) mbs.getAttribute(objName, "UsageThresholdExceeded");
Assert.fail("Unreacheable code: should have thrown exception");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof javax.management.RuntimeMBeanException);
logger.debug("Exception occurred: as expected (usage threshold exceeded not supported).");
}
}
// end else usage threshold not supported
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
Boolean b = (Boolean) mbs.getAttribute(objName, "UsageThresholdSupported");
AssertJUnit.assertNotNull(b);
logger.debug("UsageThresholdSupported is " + b);
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
try {
Boolean b = (Boolean) mbs.getAttribute(objName, "Valid");
AssertJUnit.assertNotNull(b);
logger.debug("Valid is " + b);
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
// The 1 good IBM attribute ...
try {
// If not supported on the VM then permissible to get a
// null return value.
CompositeData cd = (CompositeData) mbs.getAttribute(objName, "PreCollectionUsage");
if (null != cd) {
MemoryUsage mu = MemoryUsage.from(cd);
AssertJUnit.assertTrue(mu.getCommitted() != -1);
AssertJUnit.assertTrue(mu.getUsed() != -1);
logger.debug("(IBM) PreCollectionUsage : " + mu);
}
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
}
} catch (AttributeNotFoundException e) {
Assert.fail("Unexpected AttributeNotFoundException : " + e.getMessage());
} catch (MBeanException e) {
Assert.fail("Unexpected MBeanException : " + e.getMessage());
} catch (ReflectionException e) {
Assert.fail("Unexpected ReflectionException : " + e.getMessage());
}
// A nonexistent attribute should throw an AttributeNotFoundException
try {
long rpm = ((Long) (mbs.getAttribute(objName, "RPM")));
Assert.fail("Unreacheable code: should have thrown an AttributeNotFoundException.");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof AttributeNotFoundException);
logger.debug("Exception occurred: as expected, no such attribute found (RPM).");
}
// Type mismatch should result in a casting exception
try {
Long bad = (Long) (mbs.getAttribute(objName, "Name"));
Assert.fail("Unreacheable code: should have thrown a ClassCastException");
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof ClassCastException);
logger.debug("Exception occurred: as expected, invalid type cast attempted.");
}
}
use of java.lang.management.MemoryPoolMXBean in project openj9 by eclipse.
the class TestMemoryPoolMXBean method testGetMBeanInfo.
@Test
public final void testGetMBeanInfo() {
MemoryPoolMXBean testImpl = testBean;
MBeanInfo mbi = null;
try {
mbi = mbs.getMBeanInfo(objName);
} catch (InstanceNotFoundException e) {
Assert.fail("Unexpected InstanceNotFoundException : " + e.getMessage());
} catch (ReflectionException e) {
Assert.fail("Unexpected ReflectionException : " + e.getMessage());
} catch (IntrospectionException e) {
Assert.fail("Unexpected IntrospectionException : " + e.getMessage());
}
AssertJUnit.assertNotNull(mbi);
// Now make sure that what we got back is what we expected.
// Class name
AssertJUnit.assertTrue(mbi.getClassName().equals(testImpl.getClass().getName()));
// No public constructors
MBeanConstructorInfo[] constructors = mbi.getConstructors();
AssertJUnit.assertNotNull(constructors);
AssertJUnit.assertTrue(constructors.length == 0);
// One public operation - resetPeakUsage
MBeanOperationInfo[] operations = mbi.getOperations();
AssertJUnit.assertNotNull(operations);
AssertJUnit.assertTrue(operations.length == 1);
AssertJUnit.assertEquals("resetPeakUsage", operations[0].getName());
// No notifications
MBeanNotificationInfo[] notifications = mbi.getNotifications();
AssertJUnit.assertNotNull(notifications);
AssertJUnit.assertTrue(notifications.length == 0);
// Print description and the class name (not necessarily identical).
logger.debug("MBean description for " + testImpl.getClass().getName() + ": " + mbi.getDescription());
// Sixteen attributes - only two are writable.
MBeanAttributeInfo[] attributes = mbi.getAttributes();
AssertJUnit.assertNotNull(attributes);
AssertJUnit.assertTrue(attributes.length == 17);
for (int i = 0; i < attributes.length; i++) {
MBeanAttributeInfo info = attributes[i];
AssertJUnit.assertNotNull(info);
AllManagementTests.validateAttributeInfo(info, TestMemoryPoolMXBean.ignoredAttributes, attribs);
}
// end for
}
use of java.lang.management.MemoryPoolMXBean in project openj9 by eclipse.
the class TestMemoryPoolMXBean method testSetUsageThresholdAttribute.
@Test
public void testSetUsageThresholdAttribute() {
MemoryPoolMXBean testImpl = testBean;
if (testImpl.isUsageThresholdSupported()) {
try {
long originalUT = (Long) mbs.getAttribute(objName, "UsageThreshold");
long newUT = originalUT + 1024;
Attribute newUTAttr = new Attribute("UsageThreshold", new Long(newUT));
mbs.setAttribute(objName, newUTAttr);
AssertJUnit.assertEquals(new Long(newUT), (Long) mbs.getAttribute(objName, "UsageThreshold"));
} catch (AttributeNotFoundException e) {
e.printStackTrace();
Assert.fail("Unexpected AttributeNotFoundException occurred: " + e.getMessage());
} catch (InstanceNotFoundException e) {
e.printStackTrace();
Assert.fail("Unexpected InstanceNotFoundException occurred: " + e.getMessage());
} catch (MBeanException e) {
e.printStackTrace();
Assert.fail("Unexpected MBeanException occurred: " + e.getMessage());
} catch (ReflectionException e) {
e.printStackTrace();
Assert.fail("Unexpected ReflectionException occurred: " + e.getMessage());
} catch (InvalidAttributeValueException e) {
e.printStackTrace();
Assert.fail("Unexpected InvalidAttributeValueException occurred: " + e.getMessage());
}
} else {
try {
Attribute newUTAttr = new Attribute("UsageThreshold", new Long(100 * 1024));
mbs.setAttribute(objName, newUTAttr);
Assert.fail("Unreacheable code: should have thrown exception!");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof javax.management.RuntimeMBeanException);
logger.debug("Exception occurred, as expected: cannot set attribute (UsageThreshold).");
}
}
// end else usage threshold is not supported
}
use of java.lang.management.MemoryPoolMXBean in project openj9 by eclipse.
the class TestManagementFactory method testGetMemoryPoolMXBeans.
@Test
public final void testGetMemoryPoolMXBeans() {
List<MemoryPoolMXBean> allBeans = ManagementFactory.getMemoryPoolMXBeans();
AssertJUnit.assertNotNull(allBeans);
AssertJUnit.assertTrue(allBeans.size() > 0);
MemoryPoolMXBean mmb = allBeans.get(0);
AssertJUnit.assertNotNull(mmb);
}
Aggregations