public void testMemoryMXBean()
throws Exception
{
ManagementView mgtView = getManagementView();
ComponentType type = new ComponentType("MBean", "Platform");
ManagedComponent mo = mgtView.getComponent(ManagementFactory.MEMORY_MXBEAN_NAME, type);
assertNotNull(mo);
assertEquals(ManagementFactory.MEMORY_MXBEAN_NAME, mo.getName());
Map<String, ManagedProperty> props = mo.getProperties();
assertNotNull(props);
// heapMemoryUsage
ManagedProperty heapMemoryUsage = props.get("heapMemoryUsage");
assertNotNull(heapMemoryUsage);
assertEquals("object representing the heap memory usage.", heapMemoryUsage.getDescription());
CompositeValue heapMemoryUsageMV = CompositeValue.class.cast(heapMemoryUsage.getValue());
assertNotNull(heapMemoryUsageMV);
getLog().debug("heapMemoryUsageMV; "+heapMemoryUsageMV);
MemoryUsage heapMemoryUsageMU = ManagementFactoryUtils.unwrapMemoryUsage(heapMemoryUsageMV);
assertTrue(heapMemoryUsageMU.getInit() >= 0);
assertTrue(heapMemoryUsageMU.getUsed() >= 1000);
assertTrue(heapMemoryUsageMU.getMax() >= heapMemoryUsageMU.getCommitted());
assertTrue(heapMemoryUsageMU.getCommitted() >= heapMemoryUsageMU.getUsed());
// nonHeapMemoryUsage
ManagedProperty nonHeapMemoryUsage = props.get("nonHeapMemoryUsage");
assertNotNull(nonHeapMemoryUsage);
assertEquals("object representing the non-heap memory usage.", nonHeapMemoryUsage.getDescription());
CompositeValue nonHeapMemoryUsageMV = CompositeValue.class.cast(nonHeapMemoryUsage.getValue());
assertNotNull(nonHeapMemoryUsageMV);
getLog().debug("nonHeapMemoryUsageMV; "+nonHeapMemoryUsageMV);
MemoryUsage nonHeapMemoryUsageMU = ManagementFactoryUtils.unwrapMemoryUsage(nonHeapMemoryUsageMV);
assertTrue(nonHeapMemoryUsageMU.getInit() >= 0);
assertTrue(nonHeapMemoryUsageMU.getUsed() >= 1000);
// Ignore undefined nonHeap max memory, seen with IBM JDK 6
if(nonHeapMemoryUsageMU.getMax() != -1)
assertTrue(nonHeapMemoryUsageMU.getMax() >= nonHeapMemoryUsageMU.getCommitted());
assertTrue(nonHeapMemoryUsageMU.getCommitted() >= nonHeapMemoryUsageMU.getUsed());
// objectPendingFinalizationCount
ManagedProperty objectPendingFinalizationCount = props.get("objectPendingFinalizationCount");
assertNotNull(objectPendingFinalizationCount);
assertEquals("the approximate number objects for which finalization is pending.", objectPendingFinalizationCount.getDescription());
MetaValue objectPendingFinalizationCountMV = objectPendingFinalizationCount.getValue();
assertNotNull(objectPendingFinalizationCountMV);
getLog().debug("objectPendingFinalizationCountMV; "+objectPendingFinalizationCountMV);
// verbose
ManagedProperty verbose = props.get("verbose");
assertNotNull(verbose);
assertEquals(SimpleMetaType.BOOLEAN_PRIMITIVE, verbose.getMetaType());
assertEquals("the verbose output flag for the memory system.", verbose.getDescription());
SimpleValue verboseSV = SimpleValue.class.cast(verbose.getValue());
assertNotNull(verboseSV);
getLog().debug("verboseSV; "+verboseSV);
// The gc op
Set<ManagedOperation> ops = mo.getOperations();
assertNotNull(ops);
assertEquals("There is 1 op", 1, ops.size());
ManagedOperation gc = ops.iterator().next();
assertEquals("gc", gc.getName());
assertEquals("Runs the garbage collector", gc.getDescription());