You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2015/12/14 20:32:38 UTC
svn commit: r1719992 - in /jmeter/branches/SampleTimeout: bin/
src/components/org/apache/jmeter/modifiers/
src/components/org/apache/jmeter/modifiers/gui/
src/components/org/apache/jmeter/timers/
src/components/org/apache/jmeter/timers/gui/ src/core/or...
Author: sebb
Date: Mon Dec 14 19:32:38 2015
New Revision: 1719992
URL: http://svn.apache.org/viewvc?rev=1719992&view=rev
Log:
Use Pre-Processor rather than Timer
Added:
jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/SampleTimeout.java (with props)
jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/gui/SampleTimeoutGui.java (with props)
jmeter/branches/SampleTimeout/xdocs/images/screenshots/sample_timeout.png (with props)
Removed:
jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/timers/InterruptTimer.java
jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/timers/gui/InterruptTimerGui.java
jmeter/branches/SampleTimeout/xdocs/images/screenshots/timers/interrupt_timer.png
Modified:
jmeter/branches/SampleTimeout/bin/saveservice.properties
jmeter/branches/SampleTimeout/src/core/org/apache/jmeter/resources/messages.properties
jmeter/branches/SampleTimeout/src/core/org/apache/jmeter/resources/messages_fr.properties
jmeter/branches/SampleTimeout/xdocs/usermanual/component_reference.xml
Modified: jmeter/branches/SampleTimeout/bin/saveservice.properties
URL: http://svn.apache.org/viewvc/jmeter/branches/SampleTimeout/bin/saveservice.properties?rev=1719992&r1=1719991&r2=1719992&view=diff
==============================================================================
--- jmeter/branches/SampleTimeout/bin/saveservice.properties (original)
+++ jmeter/branches/SampleTimeout/bin/saveservice.properties Mon Dec 14 19:32:38 2015
@@ -165,8 +165,6 @@ IncludeController=org.apache.jmeter.cont
IncludeControllerGui=org.apache.jmeter.control.gui.IncludeControllerGui
InterleaveControl=org.apache.jmeter.control.InterleaveControl
InterleaveControlGui=org.apache.jmeter.control.gui.InterleaveControlGui
-InterruptTimer=org.apache.jmeter.timers.InterruptTimer
-InterruptTimerGui=org.apache.jmeter.timers.gui.InterruptTimerGui
JavaConfig=org.apache.jmeter.protocol.java.config.JavaConfig
JavaConfigGui=org.apache.jmeter.protocol.java.config.gui.JavaConfigGui
JavaSampler=org.apache.jmeter.protocol.java.sampler.JavaSampler
@@ -261,6 +259,8 @@ ResultSaverGui=org.apache.jmeter.reporte
RunTime=org.apache.jmeter.control.RunTime
RunTimeGui=org.apache.jmeter.control.gui.RunTimeGui
SampleSaveConfiguration=org.apache.jmeter.samplers.SampleSaveConfiguration
+SampleTimeout=org.apache.jmeter.modifiers.SampleTimeout
+SampleTimeoutGui=org.apache.jmeter.modifiers.gui.SampleTimeoutGui
SimpleConfigGui=org.apache.jmeter.config.gui.SimpleConfigGui
SimpleDataWriter=org.apache.jmeter.visualizers.SimpleDataWriter
SizeAssertion=org.apache.jmeter.assertions.SizeAssertion
Added: jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/SampleTimeout.java
URL: http://svn.apache.org/viewvc/jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/SampleTimeout.java?rev=1719992&view=auto
==============================================================================
--- jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/SampleTimeout.java (added)
+++ jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/SampleTimeout.java Mon Dec 14 19:32:38 2015
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.modifiers;
+
+import java.io.Serializable;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.jmeter.samplers.Interruptible;
+import org.apache.jmeter.samplers.SampleEvent;
+import org.apache.jmeter.samplers.SampleListener;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.testelement.AbstractTestElement;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jmeter.testelement.ThreadListener;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
+
+/**
+ *
+ * Sample timeout implementation using Executor threads
+ *
+ */
+public class SampleTimeout extends AbstractTestElement implements Serializable, ThreadListener, SampleListener {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger LOG = LoggingManager.getLoggerForClass();
+
+ private static final String TIMEOUT = "InterruptTimer.timeout"; //$NON-NLS-1$
+
+ private final boolean useRunnable = JMeterUtils.getPropDefault("InterruptTimer.useRunnable", false);
+
+ private static class TPOOLHolder {
+ static final ScheduledExecutorService EXEC_SERVICE =
+ Executors.newScheduledThreadPool(1,
+ new ThreadFactory() {
+ public Thread newThread(Runnable r) {
+ Thread t = Executors.defaultThreadFactory().newThread(r);
+ t.setDaemon(true); // also ensures that Executor thread is daemon
+ return t;
+ }
+ });
+ }
+
+ private static ScheduledExecutorService getExecutorService() {
+ return TPOOLHolder.EXEC_SERVICE;
+ }
+
+ private JMeterContext context; // Cache this here to avoid refetching
+
+ private ScheduledFuture<?> future;
+
+ private final transient ScheduledExecutorService execService;
+
+ private final boolean debug;
+
+ /**
+ * No-arg constructor.
+ */
+ public SampleTimeout() {
+// LOG.setPriority(org.apache.log.Priority.DEBUG); // for local debugging when enabled
+ debug = LOG.isDebugEnabled();
+ execService = getExecutorService();
+ if (debug) {
+ LOG.debug(whoAmI("InterruptTimer()", this));
+ }
+ }
+
+ /**
+ * Set the timeout for this timer.
+ * @param timeout The timeout for this timer
+ */
+ public void setTimeout(String timeout) {
+ setProperty(TIMEOUT, timeout);
+ }
+
+ /**
+ * Get the timeout value for display.
+ *
+ * @return the timeout value for display.
+ */
+ public String getTimeout() {
+ return getPropertyAsString(TIMEOUT);
+ }
+
+ @Override
+ public void sampleStarted(SampleEvent e) {
+ if (debug) {
+ LOG.debug(whoAmI("sampleStarted()", this));
+ }
+ createTask();
+ }
+
+ @Override
+ public void sampleStopped(SampleEvent e) {
+ if (debug) {
+ LOG.debug(whoAmI("sampleStopped()", this));
+ }
+ cancelTask();
+ }
+
+ private void createTask() {
+ long timeout = getPropertyAsLong(TIMEOUT); // refetch each time so it can be a variable
+ if (timeout <= 0) {
+ return;
+ }
+ final Sampler samp = context.getCurrentSampler();
+ if (!(samp instanceof Interruptible)) { // may be applied to a whole test
+ return; // Cannot time out in this case
+ }
+ final Interruptible sampler = (Interruptible) samp;
+
+ if (useRunnable) {
+ Runnable run=new Runnable() {
+ public void run() {
+ long start = System.nanoTime();
+ boolean interrupted = sampler.interrupt();
+ String elapsed = Double.toString((double)(System.nanoTime()-start)/ 1000000000)+" secs";
+ if (interrupted) {
+ LOG.warn("Run Done interrupting " + getInfo(samp) + " took " + elapsed);
+ } else {
+ if (debug) {
+ LOG.debug("Run Didn't interrupt: " + getInfo(samp) + " took " + elapsed);
+ }
+ }
+ }
+ };
+ // schedule the interrupt to occur and save for possible cancellation
+ future = execService.schedule(run, timeout, TimeUnit.MILLISECONDS);
+ } else {
+ Callable<Object> call = new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ long start = System.nanoTime();
+ boolean interrupted = sampler.interrupt();
+ String elapsed = Double.toString((double)(System.nanoTime()-start)/ 1000000000)+" secs";
+ if (interrupted) {
+ LOG.warn("Call Done interrupting " + getInfo(samp) + " took " + elapsed);
+ } else {
+ if (debug) {
+ LOG.debug("Call Didn't interrupt: " + getInfo(samp) + " took " + elapsed);
+ }
+ }
+ return null;
+ }
+
+ };
+ // schedule the interrupt to occur and save for possible cancellation
+ future = execService.schedule(call, timeout, TimeUnit.MILLISECONDS);
+ }
+ if (debug) {
+ LOG.debug("Scheduled timer: @" + System.identityHashCode(future) + " " + getInfo(samp));
+ }
+ }
+
+ @Override
+ public void threadStarted() {
+ if (debug) {
+ LOG.debug(whoAmI("threadStarted()", this));
+ }
+ context = JMeterContextService.getContext();
+ }
+
+ @Override
+ public void threadFinished() {
+ if (debug) {
+ LOG.debug(whoAmI("threadFinished()", this));
+ }
+ cancelTask(); // cancel final if any
+ }
+
+ /**
+ * Provide a description of this class.
+ *
+ * @return the description of this class.
+ */
+ @Override
+ public String toString() {
+ return JMeterUtils.getResString("sample_timeout_memo"); //$NON-NLS-1$
+ }
+
+ private String whoAmI(String id, TestElement o) {
+ return id + " @" + System.identityHashCode(o)+ " '"+ o.getName() + "' " + (debug ? Thread.currentThread().getName() : "");
+ }
+
+ private String getInfo(TestElement o) {
+ return whoAmI(o.getClass().getSimpleName(), o);
+ }
+
+ private void cancelTask() {
+ if (future != null) {
+ if (!future.isDone()) {
+ boolean cancelled = future.cancel(false);
+ if (debug) {
+ LOG.debug("Cancelled timer: @" + System.identityHashCode(future) + " with result " + cancelled);
+ }
+ }
+ future = null;
+ }
+ }
+
+ @Override
+ public void sampleOccurred(SampleEvent e) {
+ // Not used
+ }
+}
Propchange: jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/SampleTimeout.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/gui/SampleTimeoutGui.java
URL: http://svn.apache.org/viewvc/jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/gui/SampleTimeoutGui.java?rev=1719992&view=auto
==============================================================================
--- jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/gui/SampleTimeoutGui.java (added)
+++ jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/gui/SampleTimeoutGui.java Mon Dec 14 19:32:38 2015
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.modifiers.gui;
+
+import javax.swing.Box;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JTextField;
+
+import org.apache.jmeter.modifiers.SampleTimeout;
+import org.apache.jmeter.processor.gui.AbstractPreProcessorGui;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.gui.layout.VerticalLayout;
+
+/**
+ * The GUI for SampleTimeout.
+ */
+public class SampleTimeoutGui extends AbstractPreProcessorGui {
+
+ private static final long serialVersionUID = 240L;
+
+ /**
+ * The default value for the timeout.
+ */
+ private static final String DEFAULT_TIMEOUT = "10000";
+
+ private JTextField timeoutField;
+
+ /**
+ * No-arg constructor.
+ */
+ public SampleTimeoutGui() {
+ init();
+ }
+
+ /**
+ * Handle an error.
+ *
+ * @param e
+ * the Exception that was thrown.
+ * @param thrower
+ * the JComponent that threw the Exception.
+ */
+ public static void error(Exception e, JComponent thrower) {
+ JOptionPane.showMessageDialog(thrower, e, "Error", JOptionPane.ERROR_MESSAGE);
+ }
+
+ @Override
+ public String getLabelResource() {
+ return "sample_timeout_title"; // $NON-NLS-1$
+ }
+
+ /**
+ * Create the test element underlying this GUI component.
+ *
+ * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
+ */
+ @Override
+ public TestElement createTestElement() {
+ SampleTimeout timer = new SampleTimeout();
+ modifyTestElement(timer);
+ return timer;
+ }
+
+ /**
+ * Modifies a given TestElement to mirror the data in the gui components.
+ *
+ * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
+ */
+ @Override
+ public void modifyTestElement(TestElement timer) {
+ this.configureTestElement(timer);
+ ((SampleTimeout) timer).setTimeout(timeoutField.getText());
+ }
+
+ /**
+ * Configure this GUI component from the underlying TestElement.
+ *
+ * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(TestElement)
+ */
+ @Override
+ public void configure(TestElement el) {
+ super.configure(el);
+ timeoutField.setText(((SampleTimeout) el).getTimeout());
+ }
+
+ /**
+ * Initialize this component.
+ */
+ private void init() {
+ setLayout(new VerticalLayout(5, VerticalLayout.BOTH, VerticalLayout.TOP));
+
+ setBorder(makeBorder());
+ add(makeTitlePanel());
+
+ Box timeoutPanel = Box.createHorizontalBox();
+ JLabel timeoutLabel = new JLabel(JMeterUtils.getResString("sample_timeout_timeout"));//$NON-NLS-1$
+ timeoutPanel.add(timeoutLabel);
+
+ timeoutField = new JTextField(6);
+ timeoutField.setText(DEFAULT_TIMEOUT);
+ timeoutPanel.add(timeoutField);
+
+ add(timeoutPanel);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clearGui() {
+ timeoutField.setText(DEFAULT_TIMEOUT);
+ super.clearGui();
+ }
+}
Propchange: jmeter/branches/SampleTimeout/src/components/org/apache/jmeter/modifiers/gui/SampleTimeoutGui.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jmeter/branches/SampleTimeout/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jmeter/branches/SampleTimeout/src/core/org/apache/jmeter/resources/messages.properties?rev=1719992&r1=1719991&r2=1719992&view=diff
==============================================================================
--- jmeter/branches/SampleTimeout/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/branches/SampleTimeout/src/core/org/apache/jmeter/resources/messages.properties Mon Dec 14 19:32:38 2015
@@ -423,9 +423,6 @@ insert_after=Insert After
insert_before=Insert Before
insert_parent=Insert Parent
interleave_control_title=Interleave Controller
-interrupt_timer_memo=Interrupt the sampler if it times out
-interrupt_timer_timeout=Sampler timeout (in milliseconds)\:
-interrupt_timer_title=Interrupt Timer
intsum_param_1=First int to add.
intsum_param_2=Second int to add - further ints can be summed by adding further arguments.
invalid_data=Invalid data
@@ -887,6 +884,9 @@ sampler_on_error_start_next_loop=Start N
sampler_on_error_stop_test=Stop Test
sampler_on_error_stop_test_now=Stop Test Now
sampler_on_error_stop_thread=Stop Thread
+sample_timeout_memo=Interrupt the sampler if it times out
+sample_timeout_timeout=Sample timeout (in milliseconds)\:
+sample_timeout_title=Sample Timeout
save=Save
save?=Save?
save_all_as=Save Test Plan as
Modified: jmeter/branches/SampleTimeout/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/branches/SampleTimeout/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1719992&r1=1719991&r2=1719992&view=diff
==============================================================================
--- jmeter/branches/SampleTimeout/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/branches/SampleTimeout/src/core/org/apache/jmeter/resources/messages_fr.properties Mon Dec 14 19:32:38 2015
@@ -416,9 +416,6 @@ insert_after=Ins\u00E9rer apr\u00E8s
insert_before=Ins\u00E9rer avant
insert_parent=Ins\u00E9rer en tant que parent
interleave_control_title=Contr\u00F4leur Interleave
-interrupt_timer_memo=Interrompre l'\u00E9chantillon si le d\u00E9lai est d\u00E9pass\u00E9
-interrupt_timer_timeout=D\u00E9lai d'attente avant interruption (en millisecondes) \:
-interrupt_timer_title=Compteur Interruption
intsum_param_1=Premier entier \u00E0 ajouter
intsum_param_2=Deuxi\u00E8me entier \u00E0 ajouter - les entier(s) suivants peuvent \u00EAtre ajout\u00E9(s) avec les arguments suivants.
invalid_data=Donn\u00E9e invalide
@@ -866,6 +863,9 @@ sample_scope_children=Les ressources li\
sample_scope_parent=L'\u00E9chantillon
sample_scope_variable=Une variable \:
sampler_label=Libell\u00E9
+sample_timeout_memo=Interrompre l'\u00E9chantillon si le d\u00E9lai est d\u00E9pass\u00E9
+sample_timeout_timeout=D\u00E9lai d'attente avant interruption (en millisecondes) \:
+sample_timeout_title=Compteur Interruption
sampler_on_error_action=Action \u00E0 suivre apr\u00E8s une erreur d'\u00E9chantillon
sampler_on_error_continue=Continuer
sampler_on_error_start_next_loop=D\u00E9marrer it\u00E9ration suivante
Added: jmeter/branches/SampleTimeout/xdocs/images/screenshots/sample_timeout.png
URL: http://svn.apache.org/viewvc/jmeter/branches/SampleTimeout/xdocs/images/screenshots/sample_timeout.png?rev=1719992&view=auto
==============================================================================
Binary file - no diff available.
Propchange: jmeter/branches/SampleTimeout/xdocs/images/screenshots/sample_timeout.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Modified: jmeter/branches/SampleTimeout/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/branches/SampleTimeout/xdocs/usermanual/component_reference.xml?rev=1719992&r1=1719991&r2=1719992&view=diff
==============================================================================
--- jmeter/branches/SampleTimeout/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/branches/SampleTimeout/xdocs/usermanual/component_reference.xml Mon Dec 14 19:32:38 2015
@@ -5236,23 +5236,6 @@ to the random delay.</property>
</component>
-<component name="Interrupt Timer" index="§-num;.6.1" anchor="interrupt" width="336" height="148" screenshot="timers/interrupt_timer.png">
-<description>
-<p>This is not strictly a timer, as it does not cause a delay before a sampler.
-Instead it interrupts the sampler if that has taken longer than the timeout.
-The timeout is ignored if it is zero or negative.
-For this to work, the sampler must implement Interruptible.
-The following samplers are known to do so:<br></br>
-AJP, BeanShell, FTP, HTTP, Soap, AccessLog, MailReader, JMS Subscriber, TCPSampler, TestAction
-</p></description>
-
-<properties>
- <property name="Name" required="No">Descriptive name for this timer that is shown in the tree.</property>
- <property name="Sampler Timeout" required="Yes">If the sampler takes longer to complete, it will be interrupted.</property>
-</properties>
-</component>
-
-
<a href="#">^</a>
</section>
@@ -5587,6 +5570,36 @@ this one will be used by "Calculate Pric
<link href="../demos/RegEx-User-Parameters.jmx">Test Plan showing how to use RegEx User Parameters</link>
</links>
+<component name="Sample Timeout" index="§-num;.7.11" anchor="interrupt" width="316" height="138" screenshot="sample_timeout.png">
+<description>
+<note>BETA CODE - the test element may be moved or replaced in a future release</note>
+<p>This Pre-Processor schedules a timer task to interrupt a sample if it takes too long to complete.
+The timeout is ignored if it is zero or negative.
+For this to work, the sampler must implement Interruptible.
+The following samplers are known to do so:<br></br>
+AJP, BeanShell, FTP, HTTP, Soap, AccessLog, MailReader, JMS Subscriber, TCPSampler, TestAction, JavaSampler
+</p>
+<p>
+The test element is intended for use where individual timeouts such as Connection Timeout or Response Timeout are insufficient,
+or where the Sampler does not support timeouts.
+The timeout should be set sufficiently long so that it is not triggered in normal tests, but short enough that it interrupts samples
+that are stuck.
+</p>
+<p>
+[By default, JMeter uses a Callable to interrupt the sampler.
+This executes in the same thread as the timer, so if the interrupt takes a long while,
+it may delay the processing of subsequent timeouts.
+This is not expected to be a problem, but if necessary the property <code>InterruptTimer.useRunnable</code>
+can be set to <code>true</code> to use a separate Runnable thread instead of the Callable.]
+</p>
+</description>
+
+<properties>
+ <property name="Name" required="No">Descriptive name for this timer that is shown in the tree.</property>
+ <property name="Sampler Timeout" required="Yes">If the sample takes longer to complete, it will be interrupted.</property>
+</properties>
+</component>
+
<a href="#">^</a>
</section>