add ThreadCpu test

This commit is contained in:
Doug MacEachern 2004-11-17 05:57:41 +00:00
parent 65fe21ae2b
commit 41c0ee4f7c
2 changed files with 47 additions and 0 deletions

View File

@ -35,6 +35,7 @@ public class SigarTestRunner extends SigarCommandBase {
TestProcStat.class,
TestProcTime.class,
TestSwap.class,
TestThreadCpu.class,
TestUptime.class,
};

View File

@ -0,0 +1,46 @@
package net.hyperic.sigar.test;
import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.SigarNotImplementedException;
import net.hyperic.sigar.ThreadCpu;
import net.hyperic.sigar.ThreadCpuTime;
public class TestThreadCpu extends SigarTestCase {
public TestThreadCpu(String name) {
super(name);
}
public void testCreate() throws Exception {
Sigar sigar = new Sigar();
ThreadCpuTime cpu = new ThreadCpuTime(sigar);
try {
cpu.getCurrent();
} catch (SigarNotImplementedException e) {
return;
}
assertGtEqZeroTrace("User", cpu.getUser());
assertGtEqZeroTrace("Sys", cpu.getSys());
assertGtEqZeroTrace("Total", cpu.getTotal());
for (int i=0; i<1000000; i++) {
System.getProperty("java.home");
}
traceln("\nDiff...\n");
ThreadCpu diff = cpu.getDiff();
assertGtEqZeroTrace("User", diff.getUser());
assertGtEqZeroTrace("Sys", diff.getSys());
assertGtEqZeroTrace("Total", diff.getTotal());
}
}