Merge branch 'sigar-1.6'
This commit is contained in:
commit
6a806d1724
8 files changed
+50
-13
No files matched your search
@@ -36,7 +36,7 @@ public class Humidor {
|
||||
private Object LOCK = new Object();
|
||||
private InvocationHandler _handler;
|
||||
private SigarProxy _sigar;
|
||||
private Sigar _impl;
|
||||
private Sigar _impl, _inst;
|
||||
|
||||
private Humidor() {}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class Humidor {
|
||||
synchronized(LOCK) {
|
||||
if (_sigar == null) {
|
||||
if (_impl == null) {
|
||||
_impl = new Sigar();
|
||||
_inst = _impl = new Sigar();
|
||||
}
|
||||
_handler = new MyHandler(_impl);
|
||||
_sigar = (SigarProxy)
|
||||
@@ -84,4 +84,13 @@ public class Humidor {
|
||||
public static Humidor getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
//close the Sigar instance if getSigar() created it
|
||||
public void close() {
|
||||
if (_inst != null) {
|
||||
_inst.close();
|
||||
_impl = _inst = null;
|
||||
}
|
||||
_sigar = null;
|
||||
}
|
||||
}
|
||||
@@ -204,9 +204,18 @@ public class Shell extends ShellBase {
|
||||
|
||||
public void shutdown() {
|
||||
this.sigar.close();
|
||||
//avoid possible Class Not Found: junit/framework/TestCase
|
||||
if (System.getProperty("jni.dmalloc") != null) {
|
||||
//org.hyperic.sigar.test.SigarTestCase.closeSigar(); //shutup dmalloc
|
||||
//cleanup for dmalloc
|
||||
//using reflection incase junit.jar is not present
|
||||
try {
|
||||
//SigarTestCase.closeSigar();
|
||||
Class.forName("org.hyperic.sigar.test.SigarTestCase").
|
||||
getMethod("closeSigar", new Class[0]).invoke(null, new Object[0]);
|
||||
} catch (ClassNotFoundException e) {
|
||||
//SigarTestCase.java not compiled w/o junit.jar
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
//avoiding possible Class Not Found: junit/framework/TestCase
|
||||
}
|
||||
super.shutdown();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,9 @@ import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.hyperic.sigar.Humidor;
|
||||
import org.hyperic.sigar.Sigar;
|
||||
import org.hyperic.sigar.ptql.ProcessQueryFactory;
|
||||
|
||||
//helper to add optional tracing.
|
||||
public abstract class SigarTestCase extends TestCase {
|
||||
@@ -80,6 +82,8 @@ public abstract class SigarTestCase extends TestCase {
|
||||
sigar.close();
|
||||
sigar = null;
|
||||
}
|
||||
ProcessQueryFactory.getInstance().clear();
|
||||
Humidor.getInstance().close();
|
||||
}
|
||||
|
||||
public Properties getProperties() {
|
||||
|
||||
@@ -116,9 +116,18 @@ public class TestPTQL extends SigarTestCase {
|
||||
|
||||
public TestPTQL(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
this.qf = new ProcessQueryFactory();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
this.qf.clear();
|
||||
}
|
||||
|
||||
private int runQuery(Sigar sigar, String qs)
|
||||
throws MalformedQueryException,
|
||||
SigarException {
|
||||
@@ -174,7 +183,6 @@ public class TestPTQL extends SigarTestCase {
|
||||
assertTrue(qs,
|
||||
runQuery(sigar, qs) >= 0);
|
||||
}
|
||||
this.qf.clear();
|
||||
}
|
||||
|
||||
public void testValidRegexQueries() throws Exception {
|
||||
@@ -183,7 +191,6 @@ public class TestPTQL extends SigarTestCase {
|
||||
assertTrue(qs,
|
||||
runQuery(getSigar(), qs) >= 0);
|
||||
}
|
||||
this.qf.clear();
|
||||
}
|
||||
|
||||
public void testMalformedQueries() throws Exception {
|
||||
@@ -197,7 +204,6 @@ public class TestPTQL extends SigarTestCase {
|
||||
assertTrue(qs + " Malformed", true);
|
||||
}
|
||||
}
|
||||
this.qf.clear();
|
||||
}
|
||||
|
||||
public void testSelf() throws Exception {
|
||||
|
||||
@@ -54,6 +54,7 @@ public class TestProcTime extends SigarTestCase {
|
||||
double value = procTime.getPercent() * 100.0;
|
||||
traceln("Percent=" + value);
|
||||
assertTrue(value >= 0.0);
|
||||
assertTrue(value <= 100.0);
|
||||
int ncpu = sigar.getCpuList().length;
|
||||
assertTrue(value <= (100.0 * ncpu)); //SIGAR-145 Irix mode
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user