Hello sebb, About your note: This will leave proc running. My answer was wrong, for me it works , as destroy will be called in finally, right ?
On Tue, Aug 27, 2013 at 3:00 PM, Philippe Mouawad < [email protected]> wrote: > > > > On Tue, Aug 27, 2013 at 2:54 PM, sebb <[email protected]> wrote: > >> On 25 August 2013 15:11, <[email protected]> wrote: >> > Author: pmouawad >> > Date: Sun Aug 25 14:11:05 2013 >> > New Revision: 1517293 >> > >> > URL: http://svn.apache.org/r1517293 >> > Log: >> > Bug 55403 - Enhancement to OS sampler: Support for timeout >> > Bugzilla Id: 55403 >> > >> > Modified: >> > jmeter/trunk/bin/jmeter.properties >> > >> jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties >> > >> jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties >> > >> jmeter/trunk/src/core/org/apache/jmeter/testelement/AbstractTestElement.java >> > jmeter/trunk/src/core/org/apache/jmeter/testelement/TestElement.java >> > 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 >> > >> jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/gui/SystemSamplerGui.java >> > jmeter/trunk/xdocs/changes.xml >> > >> > Modified: jmeter/trunk/bin/jmeter.properties >> > URL: >> http://svn.apache.org/viewvc/jmeter/trunk/bin/jmeter.properties?rev=1517293&r1=1517292&r2=1517293&view=diff >> > >> ============================================================================== >> > --- jmeter/trunk/bin/jmeter.properties (original) >> > +++ jmeter/trunk/bin/jmeter.properties Sun Aug 25 14:11:05 2013 >> > @@ -626,6 +626,12 @@ wmlParser.types=text/vnd.wap.wml >> > # monitor.buffer.size=800 >> > >> > >> #--------------------------------------------------------------------------- >> > +# OS Process Sampler configuration >> > >> +#--------------------------------------------------------------------------- >> > +# Polling to see if process has finished its work, used when a timeout >> is configured on sampler >> > +#os_sampler.poll_for_timeout=100 >> > + >> > >> +#--------------------------------------------------------------------------- >> > # TCP Sampler configuration >> > >> #--------------------------------------------------------------------------- >> > >> > >> > Modified: >> jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties >> > URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1517293&r1=1517292&r2=1517293&view=diff >> > >> ============================================================================== >> > --- >> jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties >> (original) >> > +++ >> jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Sun >> Aug 25 14:11:05 2013 >> > @@ -1090,6 +1090,8 @@ throughput_control_title=Throughput Cont >> > throughput_control_tplabel=Throughput >> > time_format=Format string for SimpleDateFormat (optional) >> > timelim=Time limit >> > +timeout_config_box_title=Timeout configuration >> > +timeout_title=Timeout (ms) >> > toggle=Toggle >> > toolbar_icon_set_not_found=The file description of toolbar icon set is >> not found. See logs. >> > total_threads_tooltip=Total number of threads to run >> > >> > Modified: >> jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties >> > URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1517293&r1=1517292&r2=1517293&view=diff >> > >> ============================================================================== >> > --- >> jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties >> (original) >> > +++ >> jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties >> Sun Aug 25 14:11:05 2013 >> > @@ -1083,6 +1083,8 @@ throughput_control_title=Contr\u00F4leur >> > throughput_control_tplabel=D\u00E9bit \: >> > time_format=Chaine de formatage sur le mod\u00E8le SimpleDateFormat >> (optionnel) >> > timelim=Limiter le temps de r\u00E9ponses \u00E0 (ms) >> > +timeout_config_box_title=Configuration du d\u00E9lai d'expiration >> > +timeout_title=D\u00E9lai expiration (ms) >> > toggle=Permuter >> > toolbar_icon_set_not_found=Le fichier de description des ic\u00F4nes >> de la barre d'outils n'est pas trouv\u00E9. Voir les journaux. >> > total_threads_tooltip=Nombre total d'Unit\u00E9s \u00E0 lancer >> > >> > Modified: >> jmeter/trunk/src/core/org/apache/jmeter/testelement/AbstractTestElement.java >> > URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testelement/AbstractTestElement.java?rev=1517293&r1=1517292&r2=1517293&view=diff >> > >> ============================================================================== >> > --- >> jmeter/trunk/src/core/org/apache/jmeter/testelement/AbstractTestElement.java >> (original) >> > +++ >> jmeter/trunk/src/core/org/apache/jmeter/testelement/AbstractTestElement.java >> Sun Aug 25 14:11:05 2013 >> > @@ -33,6 +33,7 @@ import org.apache.jmeter.testelement.pro >> > import org.apache.jmeter.testelement.property.CollectionProperty; >> > import org.apache.jmeter.testelement.property.IntegerProperty; >> > import org.apache.jmeter.testelement.property.JMeterProperty; >> > +import org.apache.jmeter.testelement.property.LongProperty; >> > import org.apache.jmeter.testelement.property.MapProperty; >> > import org.apache.jmeter.testelement.property.MultiProperty; >> > import org.apache.jmeter.testelement.property.NullProperty; >> > @@ -406,7 +407,7 @@ public abstract class AbstractTestElemen >> > } >> > >> > /** >> > - * Create a boolean property - but only if it is not the default. >> > + * Create an int property - but only if it is not the default. >> > * This is intended for use when adding new properties to JMeter >> > * so that JMX files are not expanded unnecessarily. >> > * >> > @@ -424,6 +425,31 @@ public abstract class AbstractTestElemen >> > setProperty(new IntegerProperty(name, value)); >> > } >> > } >> > + >> > + @Override >> > + public void setProperty(String name, long value) { >> > + setProperty(new LongProperty(name, value)); >> > + } >> > + >> > + /** >> > + * Create a long property - but only if it is not the default. >> > + * This is intended for use when adding new properties to JMeter >> > + * so that JMX files are not expanded unnecessarily. >> > + * >> > + * N.B. - must agree with the default applied when reading the >> property. >> > + * >> > + * @param name property name >> > + * @param value current value >> > + * @param dflt default >> > + */ >> > + @Override >> > + public void setProperty(String name, long value, long dflt) { >> > + if (value == dflt) { >> > + removeProperty(name); >> > + } else { >> > + setProperty(new LongProperty(name, value)); >> > + } >> > + } >> > >> > @Override >> > public PropertyIterator propertyIterator() { >> > >> > Modified: >> jmeter/trunk/src/core/org/apache/jmeter/testelement/TestElement.java >> > URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testelement/TestElement.java?rev=1517293&r1=1517292&r2=1517293&view=diff >> > >> ============================================================================== >> > --- >> jmeter/trunk/src/core/org/apache/jmeter/testelement/TestElement.java >> (original) >> > +++ >> jmeter/trunk/src/core/org/apache/jmeter/testelement/TestElement.java Sun >> Aug 25 14:11:05 2013 >> > @@ -56,6 +56,10 @@ public interface TestElement extends Clo >> > >> > void setProperty(String key, int value, int dflt); >> > >> > + void setProperty(String name, long value); >> > + >> > + void setProperty(String name, long value, long dflt); >> > + >> > /** >> > * Check if ENABLED property is present and true ; defaults to true >> > * >> >> Ideally it would have been better to add the changes to >> TestElement/ATE in a separate commit, as they are generic. >> > > You're right. > >> >> > 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=1517293&r1=1517292&r2=1517293&view=diff >> > >> ============================================================================== >> > --- jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java >> (original) >> > +++ jmeter/trunk/src/jorphan/org/apache/jorphan/exec/SystemCommand.java >> Sun Aug 25 14:11:05 2013 >> > @@ -26,6 +26,7 @@ import java.util.Collections; >> > import java.util.List; >> > import java.util.Map; >> > >> > +import org.apache.jmeter.util.JMeterUtils; >> > import org.apache.jorphan.util.JOrphanUtils; >> > >> > /** >> > @@ -33,6 +34,7 @@ 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; >> > @@ -40,25 +42,28 @@ public class SystemCommand { >> > private final String stdin; >> > private final String stdout; >> > private final String stderr; >> > + private final long timeoutMillis; >> > >> > /** >> > * @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, env, null, null, null); >> > + this(directory, 0L, env, null, null, null); >> > } >> > >> > /** >> > * >> > * @param env Environment variables appended to environment (may >> be null) >> > * @param directory File working directory (may be null) >> > + * @param timeoutMillis timeout in Milliseconds >> > * @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, Map<String, String> env, >> String stdin, String stdout, String stderr) { >> > + public SystemCommand(File directory, long timeoutMillis, >> Map<String, String> env, String stdin, String stdout, String stderr) { >> > super(); >> > + this.timeoutMillis = timeoutMillis; >> > this.directory = directory; >> > this.env = env; >> > this.stdin = JOrphanUtils.nullifyIfEmptyTrimmed(stdin); >> > @@ -108,7 +113,7 @@ public class SystemCommand { >> > } else { >> > proc.getOutputStream().close(); // ensure the >> application does not hang if it requests input >> > } >> > - int exitVal = proc.waitFor(); >> > + int exitVal = waitForEndWithTimeout(proc, timeoutMillis); >> > >> > if (outputGobbler != null) { >> > outputGobbler.join(); >> > @@ -139,6 +144,44 @@ public class SystemCommand { >> > } >> > >> > /** >> > + * Wait for end of proc execution or timeout if timeoutInMillis is >> greater than 0 >> > + * @param proc Process >> > + * @param timeoutInMillis long timeout in ms >> > + * @return proc exit value >> > + * @throws InterruptedException >> > + */ >> > + private int waitForEndWithTimeout(Process proc, long >> timeoutInMillis) throws InterruptedException { >> > + if (timeoutInMillis <= 0L) { >> > + return proc.waitFor(); >> > + } else { >> > + long now = System.currentTimeMillis(); >> > + long finish = now + timeoutInMillis; >> > + while (isAlive(proc) && (System.currentTimeMillis() < >> finish)) { >> > + Thread.sleep(POLL_INTERVAL); >> > + } >> > + >> > + if (isAlive(proc)) { >> >> This will leave the process running. Is that intentional? >> >> If so, it needs to be documented. >> > > You mean we should call proc.destroy(). > Good catch although I remember there may be issues with destro on Windows > >> >> > + throw new InterruptedException( "Process timeout out >> after " + timeoutInMillis + " milliseconds" ); >> > + } >> > + return proc.exitValue(); >> > + } >> > + } >> > + >> > + /** >> > + * >> > + * @param p Process >> > + * @return true if p is still running >> > + */ >> > + public static boolean isAlive(Process p) { >> > + try { >> > + p.exitValue(); >> > + return false; >> > + } catch (IllegalThreadStateException e) { >> > + return true; >> > + } >> > + } >> > + >> > + /** >> > * @return Out/Err stream contents >> > */ >> > public String getOutResult() { >> > >> > 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=1517293&r1=1517292&r2=1517293&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 >> Sun Aug 25 14:11:05 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, env, stdin, stdout, stderr); >> > + super(directory, 0L, env, stdin, stdout, stderr); >> > } >> > >> > } >> > \ 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=1517293&r1=1517292&r2=1517293&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 >> Sun Aug 25 14:11:05 2013 >> > @@ -67,6 +67,8 @@ public class SystemSampler extends Abstr >> > >> > private static final String STDIN = "SystemSampler.stdin"; >> > >> > + private static final String TIMEOUT = "SystemSampler.timeout"; >> > + >> > // - JMX names >> > >> > /** >> > @@ -144,7 +146,7 @@ public class SystemSampler extends Abstr >> > "\nEnvironment:"+env+ >> > "\nExecuting:" + cmdLine.toString()); >> > >> > - SystemCommand nativeCommand = new SystemCommand(directory, >> env, getStdin(), getStdout(), getStderr()); >> > + SystemCommand nativeCommand = new SystemCommand(directory, >> getTimeout(), env, getStdin(), getStdout(), getStderr()); >> > >> > try { >> > results.sampleStart(); >> > @@ -309,4 +311,11 @@ public class SystemSampler extends Abstr >> > setProperty(STDIN, filename, ""); >> > } >> > >> > + public long getTimeout() { >> > + return getPropertyAsLong(TIMEOUT, 0L); >> > + } >> > + >> > + public void setTimout(long timeoutMs) { >> > + setProperty(TIMEOUT, timeoutMs, 0L); >> > + } >> > } >> > \ No newline at end of file >> > >> > Modified: >> jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/gui/SystemSamplerGui.java >> > URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/gui/SystemSamplerGui.java?rev=1517293&r1=1517292&r2=1517293&view=diff >> > >> ============================================================================== >> > --- >> jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/gui/SystemSamplerGui.java >> (original) >> > +++ >> jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/gui/SystemSamplerGui.java >> Sun Aug 25 14:11:05 2013 >> > @@ -40,12 +40,15 @@ import org.apache.jmeter.testelement.Tes >> > import org.apache.jmeter.util.JMeterUtils; >> > import org.apache.jorphan.gui.JLabeledTextField; >> > import org.apache.jorphan.gui.ObjectTableModel; >> > +import org.apache.jorphan.logging.LoggingManager; >> > import org.apache.jorphan.reflect.Functor; >> > +import org.apache.log.Logger; >> > >> > /** >> > * GUI for {@link SystemSampler} >> > */ >> > public class SystemSamplerGui extends AbstractSamplerGui implements >> ItemListener { >> > + private static final Logger log = >> LoggingManager.getLoggerForClass(); >> > >> > /** >> > * >> > @@ -59,6 +62,7 @@ public class SystemSamplerGui extends Ab >> > private final FilePanelEntry stderr = new >> FilePanelEntry(JMeterUtils.getResString("system_sampler_stderr")); // >> $NON-NLS-1$ >> > private JLabeledTextField directory; >> > private JLabeledTextField command; >> > + private JLabeledTextField timeout; >> > private ArgumentsPanel argsPanel; >> > private ArgumentsPanel envPanel; >> > >> > @@ -92,7 +96,8 @@ public class SystemSamplerGui extends Ab >> > >> > JPanel streamsCodePane = new JPanel(new BorderLayout()); >> > streamsCodePane.add(makeStreamsPanel(), BorderLayout.NORTH); >> > - streamsCodePane.add(makeReturnCodePanel(), BorderLayout.SOUTH); >> > + streamsCodePane.add(makeReturnCodePanel(), >> BorderLayout.CENTER); >> > + streamsCodePane.add(makeTimeoutPanel(), BorderLayout.SOUTH); >> > add(streamsCodePane, BorderLayout.SOUTH); >> > } >> > >> > @@ -125,6 +130,13 @@ public class SystemSamplerGui extends Ab >> > systemSampler.setStdin(stdin.getFilename()); >> > systemSampler.setStdout(stdout.getFilename()); >> > systemSampler.setStderr(stderr.getFilename()); >> > + if(!StringUtils.isEmpty(timeout.getText())) { >> > + try { >> > + >> systemSampler.setTimout(Long.parseLong(timeout.getText())); >> > + } catch (NumberFormatException e) { >> > + log.error("Error parsing timeout field >> value:"+timeout.getText(), e); >> > + } >> > + } >> > } >> > >> > /* Overrides AbstractJMeterGuiComponent.configure(TestElement) */ >> > @@ -165,6 +177,21 @@ public class SystemSamplerGui extends Ab >> > } >> > >> > /** >> > + * @return JPanel timeout config >> > + */ >> > + private JPanel makeTimeoutPanel() { >> > + JPanel panel = new JPanel(); >> > + panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); >> > + panel.setBorder(BorderFactory.createTitledBorder( >> > + BorderFactory.createEtchedBorder(), >> > + >> JMeterUtils.getResString("timeout_config_box_title"))); // $NON-NLS-1$ >> > + timeout = new >> JLabeledTextField(JMeterUtils.getResString("timeout_title")); // $NON-NLS-1$ >> > + timeout.setSize(timeout.getSize().height, 30); >> > + panel.add(timeout); >> > + return panel; >> > + } >> > + >> > + /** >> > * @return JPanel Command + directory >> > */ >> > private JPanel makeCommandPanel() { >> > >> > Modified: jmeter/trunk/xdocs/changes.xml >> > URL: >> http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1517293&r1=1517292&r2=1517293&view=diff >> > >> ============================================================================== >> > --- jmeter/trunk/xdocs/changes.xml (original) >> > +++ jmeter/trunk/xdocs/changes.xml Sun Aug 25 14:11:05 2013 >> > @@ -73,6 +73,11 @@ citizen in JMeter, you can now test your >> > <figure width="906" height="313" >> image="changes/2.10/03_mongodb_script_alpha.png"></figure> >> > </p> >> > >> > +<h4>* Timeout has been added to OS Process Sampler</h4> >> > +<p> >> > +<figure width="540" height="600" >> image="changes/2.10/17_os_process_timeout.png"></figure> >> > +</p> >> > + >> > <h4>* Query timeout has been added to JDBC Request</h4> >> > <p> >> > <figure width="540" height="600" >> image="changes/2.10/04_jdbc_request_timeout.png"></figure> >> > @@ -129,19 +134,22 @@ template into your Test Plan</h4> >> > <figure width="911" height="614" >> image="changes/2.10/11_color_syntax_jsr223_preprocessor.png"></figure> >> > </p> >> > >> > +<h4>* JMeter GUI can now be fully Internationalized, all remaining >> issues have been fixed</h4> >> > +<h5>Currently French has all its labels translated. Other languages >> are partly translated, feel free to >> > +contribute translations by reading <a >> href="localising/index.html">Localisation (Translator's Guide)</a></h5> >> > + >> > <h4>* Moving elements in Test plan has been improved in many ways</h4> >> > <h5>Drag and drop of elements in Test Plan tree is now much easier and >> possible on multiple nodes</h5> >> > <p> >> > <figure width="894" height="236" >> image="changes/2.10/12_drap_n-drop_multiple.png"></figure> >> > </p> >> > <p> >> > -Note that due to this <a href=" >> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6560955">bug in >> Java</a>, >> > +<b>Note that due to this <a href=" >> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6560955">bug in >> Java</a>, >> > you cannot drop a node after last node. The workaround is to drop it >> before this last node and then Drag and Drop the last node >> > -before the one you just dropped. >> > -<figure width="762" height="277" image="changes/2.10/XXX.png"></figure> >> > +before the one you just dropped.</b> >> > </p> >> > <h5>New shortcuts have been added to move elements in the tree. </h5> >> > -<p>(alt + Arrow Up) and (alt + Arrow Down) move the element within the >> parent node. >> > +<p>(alt + Arrow Up) and (alt + Arrow Down) move the element within the >> parent node.<br/> >> > (alt + Arrow Left) and (alt + Arrow Right) move the element up and >> down in the tree depth</p> >> > >> > <h4>* Response Time Graph Y axis can now be scaled</h4> >> > @@ -328,6 +336,7 @@ Previously the default was 1, which coul >> > <li><bugzilla>54759</bugzilla> - SSLPeerUnverifiedException using >> HTTPS , property documented.</li> >> > <li><bugzilla>54896</bugzilla> - JUnit sampler gives only "failed to >> create an instance of the class" message with constructor problems.</li> >> > <li><bugzilla>55084</bugzilla> - Add timeout support for JDBC Request. >> Contributed by Mikhail Epikhin (epihin-m at yandex.ru)</li> >> > +<li><bugzilla>55403</bugzilla> - Enhancement to OS sampler: Support >> for timeout</li> >> > </ul> >> > >> > <h3>Controllers</h3> >> > >> > >> > > > > -- > Cordialement. > Philippe Mouawad. > > > -- Cordialement. Philippe Mouawad.
