From 41c0ee4f7c977af1777ff2fbeb5bdd3be9b3f4cb Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 17 Nov 2004 05:57:41 +0000 Subject: [PATCH] add ThreadCpu test --- .../hyperic/sigar/test/SigarTestRunner.java | 1 + .../net/hyperic/sigar/test/TestThreadCpu.java | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 bindings/java/src/net/hyperic/sigar/test/TestThreadCpu.java diff --git a/bindings/java/src/net/hyperic/sigar/test/SigarTestRunner.java b/bindings/java/src/net/hyperic/sigar/test/SigarTestRunner.java index 8d0754b1..b40a7ca6 100644 --- a/bindings/java/src/net/hyperic/sigar/test/SigarTestRunner.java +++ b/bindings/java/src/net/hyperic/sigar/test/SigarTestRunner.java @@ -35,6 +35,7 @@ public class SigarTestRunner extends SigarCommandBase { TestProcStat.class, TestProcTime.class, TestSwap.class, + TestThreadCpu.class, TestUptime.class, }; diff --git a/bindings/java/src/net/hyperic/sigar/test/TestThreadCpu.java b/bindings/java/src/net/hyperic/sigar/test/TestThreadCpu.java new file mode 100644 index 00000000..760c04d9 --- /dev/null +++ b/bindings/java/src/net/hyperic/sigar/test/TestThreadCpu.java @@ -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()); + } +}