test SigarProcessMBean

This commit is contained in:
Doug MacEachern 2008-10-18 23:37:21 +00:00
parent 6b46d63201
commit 06945a8e31
2 changed files with 25 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.jmx.SigarProcess;
import org.hyperic.sigar.jmx.SigarRegistry;
public class Mx extends SigarCommandBase {
@ -70,6 +71,8 @@ public class Mx extends SigarCommandBase {
SigarRegistry registry = new SigarRegistry();
try {
server.registerMBean(registry, null);
SigarProcess proc = new SigarProcess();
server.registerMBean(proc, new ObjectName(proc.getObjectName()));
isRegistered = true;
} catch (Exception e) {
throw new SigarException(e.getMessage());

View File

@ -28,6 +28,7 @@ import javax.management.ObjectName;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.cmd.Mx;
import org.hyperic.sigar.jmx.SigarProcess;
import org.hyperic.sigar.jmx.SigarRegistry;
public class TestMx extends SigarTestCase {
@ -45,6 +46,19 @@ public class TestMx extends SigarTestCase {
}
}
private void _testProcess(MBeanServer server) throws Exception {
long[] pids = getSigar().getProcList();
for (int i=0; i<pids.length; i++) {
SigarProcess proc = new SigarProcess();
proc.setPid(pids[i]);
ObjectName name = new ObjectName(proc.getObjectName());
if (server.isRegistered(name)) {
continue;
}
server.registerMBean(proc, name);
}
}
private void _testRegister() throws Exception {
MBeanServer server;
try {
@ -54,14 +68,18 @@ public class TestMx extends SigarTestCase {
return;
}
server.registerMBean(new SigarRegistry(), null);
SigarRegistry rgy = new SigarRegistry();
ObjectName name = new ObjectName(rgy.getObjectName());
if (!server.isRegistered(name)) {
server.registerMBean(new SigarRegistry(), name);
}
Set beans =
server.queryNames(new ObjectName("sigar:*"), null);
assertGtZeroTrace("beans.size", beans.size());
for (Iterator it=beans.iterator(); it.hasNext();) {
ObjectName name = (ObjectName)it.next();
name = (ObjectName)it.next();
MBeanInfo info = server.getMBeanInfo(name);
MBeanAttributeInfo[] attrs = info.getAttributes();
for (int k = 0; k < attrs.length; k++) {
@ -70,5 +88,7 @@ public class TestMx extends SigarTestCase {
traceln(name + ":" + attr + "=" + o);
}
}
_testProcess(server);
}
}