remove ProcessFinder usage

This commit is contained in:
Doug MacEachern 2007-04-22 02:28:58 +00:00
parent e4981c4d5c
commit f469e054ea
1 changed files with 9 additions and 7 deletions

View File

@ -24,11 +24,12 @@ import org.hyperic.sigar.SigarNotImplementedException;
import org.hyperic.sigar.ptql.ProcessQuery; import org.hyperic.sigar.ptql.ProcessQuery;
import org.hyperic.sigar.ptql.ProcessQueryFactory; import org.hyperic.sigar.ptql.ProcessQueryFactory;
import org.hyperic.sigar.ptql.ProcessFinder;
import org.hyperic.sigar.ptql.MalformedQueryException; import org.hyperic.sigar.ptql.MalformedQueryException;
public class TestPTQL extends SigarTestCase { public class TestPTQL extends SigarTestCase {
private ProcessQueryFactory qf;
private static final String[] OK_QUERIES = { private static final String[] OK_QUERIES = {
"State.Name.eq=java", //all java processs "State.Name.eq=java", //all java processs
"Exe.Name.ew=java", //similar "Exe.Name.ew=java", //similar
@ -102,6 +103,7 @@ public class TestPTQL extends SigarTestCase {
public TestPTQL(String name) { public TestPTQL(String name) {
super(name); super(name);
this.qf = new ProcessQueryFactory();
} }
private int runQuery(Sigar sigar, String qs) private int runQuery(Sigar sigar, String qs)
@ -110,22 +112,19 @@ public class TestPTQL extends SigarTestCase {
ProcessQuery query; ProcessQuery query;
try { try {
query = query = this.qf.getQuery(qs);
ProcessQueryFactory.getInstance(qs);
} catch (MalformedQueryException e) { } catch (MalformedQueryException e) {
traceln("parse error: " + qs); traceln("parse error: " + qs);
throw e; throw e;
} }
ProcessFinder finder = new ProcessFinder(sigar);
try { try {
long[] pids = finder.find(query); long[] pids = query.findProcesses(sigar);
traceln(pids.length + " processes match: " + qs); traceln(pids.length + " processes match: " + qs);
if (pids.length == 1) { if (pids.length == 1) {
long pid = finder.findSingleProcess(query); long pid = query.findProcess(sigar);
assertTrue(pid + "==" + pids[0], assertTrue(pid + "==" + pids[0],
pid == pids[0]); pid == pids[0]);
} }
@ -141,6 +140,7 @@ public class TestPTQL extends SigarTestCase {
assertTrue(qs, assertTrue(qs,
runQuery(sigar, qs) >= 0); runQuery(sigar, qs) >= 0);
} }
this.qf.clear();
} }
private void testReOK(Sigar sigar) throws Exception { private void testReOK(Sigar sigar) throws Exception {
@ -149,6 +149,7 @@ public class TestPTQL extends SigarTestCase {
assertTrue(qs, assertTrue(qs,
runQuery(sigar, qs) >= 0); runQuery(sigar, qs) >= 0);
} }
this.qf.clear();
} }
private void testMalformed(Sigar sigar) throws Exception { private void testMalformed(Sigar sigar) throws Exception {
@ -162,6 +163,7 @@ public class TestPTQL extends SigarTestCase {
assertTrue(qs + " Malformed", true); assertTrue(qs + " Malformed", true);
} }
} }
this.qf.clear();
} }
public void testCreate() throws Exception { public void testCreate() throws Exception {