On 26 August 2013 09:51, <[email protected]> wrote: > Author: pmouawad > Date: Mon Aug 26 08:51:03 2013 > New Revision: 1517464 > > URL: http://svn.apache.org/r1517464 > Log: > Bug 55403 - Enhancement to OS sampler: Support for timeout > Fixed compilation error > Bugzilla Id: 55403 > > Modified: > jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java > > jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/NativeCommand.java > > jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/SystemSampler.java > > Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java > URL: > http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java?rev=1517464&r1=1517463&r2=1517464&view=diff > ============================================================================== > --- jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java > (original) > +++ jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java Mon > Aug 26 08:51:03 2013 > @@ -26,7 +26,6 @@ import java.util.Collections; > import java.util.List; > import java.util.Map; > > -import org.apache.jmeter.util.JMeterUtils; > import org.apache.jorphan.util.JOrphanUtils; > > /** > @@ -34,7 +33,6 @@ import org.apache.jorphan.util.JOrphanUt > */ > public class SystemCommand { > > - private static final int POLL_INTERVAL = > JMeterUtils.getPropDefault("os_sampler.poll_for_timeout", 100); > private StreamGobbler outputGobbler; > private final File directory; > private final Map<String, String> env; > @@ -43,13 +41,14 @@ public class SystemCommand { > private final String stdout; > private final String stderr; > private final long timeoutMillis; > + private final int pollInterval; > > /** > * @param env Environment variables appended to environment (may be null) > * @param directory File working directory (may be null) > */ > public SystemCommand(File directory, Map<String, String> env) { > - this(directory, 0L, env, null, null, null); > + this(directory, 0L, 100, env, null, null, null); > } > > /** > @@ -57,15 +56,17 @@ public class SystemCommand { > * @param env Environment variables appended to environment (may be null) > * @param directory File working directory (may be null) > * @param timeoutMillis timeout in Milliseconds > + * @param pollInterval Value used to poll for Process execution end > * @param stdin File name that will contain data to be input to process > (may be null) > * @param stdout File name that will contain out stream (may be null) > * @param stderr File name that will contain err stream (may be null) > */ > - public SystemCommand(File directory, long timeoutMillis, Map<String, > String> env, String stdin, String stdout, String stderr) { > + public SystemCommand(File directory, long timeoutMillis, int > pollInterval, Map<String, String> env, String stdin, String stdout, String > stderr) { > super(); > this.timeoutMillis = timeoutMillis; > this.directory = directory; > this.env = env; > + this.pollInterval = pollInterval; > this.stdin = JOrphanUtils.nullifyIfEmptyTrimmed(stdin); > this.stdout = JOrphanUtils.nullifyIfEmptyTrimmed(stdout); > this.stderr = JOrphanUtils.nullifyIfEmptyTrimmed(stderr); > @@ -157,7 +158,7 @@ public class SystemCommand { > long now = System.currentTimeMillis(); > long finish = now + timeoutInMillis; > while (isAlive(proc) && (System.currentTimeMillis() < finish)) { > - Thread.sleep(POLL_INTERVAL); > + Thread.sleep(pollInterval); > } > > if (isAlive(proc)) { > > Modified: > jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/NativeCommand.java > URL: > http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/NativeCommand.java?rev=1517464&r1=1517463&r2=1517464&view=diff > ============================================================================== > --- > jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/NativeCommand.java > (original) > +++ > jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/NativeCommand.java > Mon Aug 26 08:51:03 2013 > @@ -45,7 +45,7 @@ public class NativeCommand extends org. > * @param stderr File name that will contain err stream > */ > public NativeCommand(File directory, Map<String, String> env, String > stdin, String stdout, String stderr) { > - super(directory, 0L, env, stdin, stdout, stderr); > + super(directory, 0L, 100, env, stdin, stdout, stderr);
Why use 100 here? There should be no "magic" numbers in the code. > } > > } > \ No newline at end of file > > Modified: > jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/SystemSampler.java > URL: > http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/SystemSampler.java?rev=1517464&r1=1517463&r2=1517464&view=diff > ============================================================================== > --- > jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/SystemSampler.java > (original) > +++ > jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/SystemSampler.java > Mon Aug 26 08:51:03 2013 > @@ -38,6 +38,7 @@ import org.apache.jmeter.samplers.Sample > import org.apache.jmeter.services.FileServer; > import org.apache.jmeter.testelement.TestElement; > import org.apache.jmeter.testelement.property.TestElementProperty; > +import org.apache.jmeter.util.JMeterUtils; > import org.apache.jorphan.exec.SystemCommand; > import org.apache.jorphan.logging.LoggingManager; > import org.apache.log.Logger; > @@ -46,6 +47,9 @@ import org.apache.log.Logger; > * A sampler for executing a System function. > */ > public class SystemSampler extends AbstractSampler { > + > + private static final int POLL_INTERVAL = > JMeterUtils.getPropDefault("os_sampler.poll_for_timeout", 100); > + > private static final long serialVersionUID = 1; > > // + JMX names, do not change their values > @@ -146,7 +150,7 @@ public class SystemSampler extends Abstr > "\nEnvironment:"+env+ > "\nExecuting:" + cmdLine.toString()); > > - SystemCommand nativeCommand = new SystemCommand(directory, > getTimeout(), env, getStdin(), getStdout(), getStderr()); > + SystemCommand nativeCommand = new SystemCommand(directory, > getTimeout(), POLL_INTERVAL, env, getStdin(), getStdout(), getStderr()); > > try { > results.sampleStart(); > >
