jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1698393 - in /jmeter/trunk: bin/ src/components/org/apache/jmeter/timers/ src/components/org/apache/jmeter/timers/gui/ src/core/org/apache/jmeter/resources/ xdocs/ xdocs/images/screenshots/timers/ xdocs/usermanual/
Date Fri, 28 Aug 2015 19:08:37 GMT
Author: sebb
Date: Fri Aug 28 19:08:36 2015
New Revision: 1698393

URL: http://svn.apache.org/r1698393
Log:
Add interrupt Timer
Bugzilla Id: 58299

Added:
    jmeter/trunk/src/components/org/apache/jmeter/timers/InterruptTimer.java   (with props)
    jmeter/trunk/src/components/org/apache/jmeter/timers/gui/InterruptTimerGui.java   (with
props)
    jmeter/trunk/xdocs/images/screenshots/timers/interrupt_timer.png   (with props)
Modified:
    jmeter/trunk/bin/saveservice.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jmeter/trunk/bin/saveservice.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/saveservice.properties?rev=1698393&r1=1698392&r2=1698393&view=diff
==============================================================================
--- jmeter/trunk/bin/saveservice.properties (original)
+++ jmeter/trunk/bin/saveservice.properties Fri Aug 28 19:08:36 2015
@@ -165,6 +165,8 @@ 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

Added: jmeter/trunk/src/components/org/apache/jmeter/timers/InterruptTimer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/timers/InterruptTimer.java?rev=1698393&view=auto
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/timers/InterruptTimer.java (added)
+++ jmeter/trunk/src/components/org/apache/jmeter/timers/InterruptTimer.java Fri Aug 28 19:08:36
2015
@@ -0,0 +1,123 @@
+package org.apache.jmeter.timers;
+
+import java.io.Serializable;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.jmeter.engine.event.LoopIterationEvent;
+import org.apache.jmeter.engine.event.LoopIterationListener;
+import org.apache.jmeter.samplers.Interruptible;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.testelement.AbstractTestElement;
+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;
+
+public class InterruptTimer extends AbstractTestElement implements Timer, Serializable, LoopIterationListener
{
+
+    private static final long serialVersionUID = 1L;
+
+    private static final Logger LOG = LoggingManager.getLoggerForClass();
+
+    private static final String TIMEOUT = "InterruptTimer.timeout"; //$NON-NLS-1$
+
+    private long timeout = 0;
+
+    private JMeterContext context;
+
+    private ScheduledFuture<?> future;
+    
+    private ScheduledExecutorService tpool;
+    
+    private final boolean debug;
+
+    /**
+     * No-arg constructor.
+     */
+    public InterruptTimer() {
+        debug = LOG.isDebugEnabled(); // TODO is this the best place for 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);
+    }
+
+    /**
+     * Retrieve the delay to use during test execution.
+     * This is called just before starting a sampler.
+     * It is used to schedule future task to interrupt the sampler.
+     * 
+     * @return Always returns zero, because this timer does not wait
+     */
+    @Override
+    public long delay() {
+        if (future != null) {
+            if (!future.isDone()) {
+                boolean cancelled = future.cancel(false);
+                if (debug) {
+                    LOG.debug("Cancelled the task:" + future + " with result " + cancelled);
+                }
+            }
+            future = null;
+        }
+        if (timeout <= 0) {
+            return 0;
+        }
+        final Sampler samp = context.getCurrentSampler();
+        if (!(samp instanceof Interruptible)) {
+            // Log this?
+            return 0;
+        }
+        final Interruptible sampler = (Interruptible) samp;
+        Runnable run=new Runnable() {
+            public void run() {
+                  boolean interrupted = sampler.interrupt();
+                  if (interrupted) {
+                      LOG.warn("The sampler " + samp.getName() + " was interrupted.");
+                  }
+            }
+        };
+        // schedule the interrupt to occur 
+        future = tpool.schedule(run, timeout, TimeUnit.MILLISECONDS);
+        return 0;
+    }
+
+    /**
+     * Provide a description of this timer class.
+     *
+     * @return the description of this timer class.
+     */
+    @Override
+    public String toString() {
+        return JMeterUtils.getResString("interrupt_timer_memo"); //$NON-NLS-1$
+    }
+
+    /**
+     * Gain access to any variables that have been defined.
+     *
+     * @see LoopIterationListener#iterationStart(LoopIterationEvent)
+     */
+    @Override
+    public void iterationStart(LoopIterationEvent event) {
+        timeout = getPropertyAsLong(TIMEOUT);
+        context = JMeterContextService.getContext(); // TODO is this called from the correct
thread?
+        tpool = Executors.newScheduledThreadPool(1); // ditto
+    }
+}

Propchange: jmeter/trunk/src/components/org/apache/jmeter/timers/InterruptTimer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jmeter/trunk/src/components/org/apache/jmeter/timers/gui/InterruptTimerGui.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/timers/gui/InterruptTimerGui.java?rev=1698393&view=auto
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/timers/gui/InterruptTimerGui.java (added)
+++ jmeter/trunk/src/components/org/apache/jmeter/timers/gui/InterruptTimerGui.java Fri Aug
28 19:08:36 2015
@@ -0,0 +1,131 @@
+/*
+ * 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.timers.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.testelement.TestElement;
+import org.apache.jmeter.timers.InterruptTimer;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.gui.layout.VerticalLayout;
+
+/**
+ * The GUI for InterruptTimer.
+ *
+ */
+public class InterruptTimerGui extends AbstractTimerGui {
+    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 InterruptTimerGui() {
+        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 "interrupt_timer_title"; // $NON-NLS-1$
+    }
+
+    /**
+     * Create the test element underlying this GUI component.
+     *
+     * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
+     */
+    @Override
+    public TestElement createTestElement() {
+        InterruptTimer timer = new InterruptTimer();
+        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);
+        ((InterruptTimer) 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(((InterruptTimer) 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("interrupt_timer_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/trunk/src/components/org/apache/jmeter/timers/gui/InterruptTimerGui.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1698393&r1=1698392&r2=1698393&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Fri Aug 28 19:08:36
2015
@@ -423,6 +423,9 @@ 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

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1698393&r1=1698392&r2=1698393&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Fri Aug 28 19:08:36 2015
@@ -89,7 +89,7 @@ Summary
 <h3>Other samplers</h3>
 <ul>
     <li><bug>57928</bug>Add ability to define protocol (http/https) to
AccessLogSampler GUI. Contributed by Jérémie Lesage (jeremie.lesage at jeci.fr)</li>
-    <li><bug>58300</bug> Make existing Java Samplers implement interruptible</li>
+    <li><bug>58300</bug> Make existing Java Samplers implement Interruptible</li>
 </ul>
 
 <h3>Controllers</h3>
@@ -104,6 +104,7 @@ Summary
 
 <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>
 <ul>
+<li><bug>58299</bug>Add interrupt Timer</li>
 </ul>
 
 <h3>Functions</h3>

Added: jmeter/trunk/xdocs/images/screenshots/timers/interrupt_timer.png
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/images/screenshots/timers/interrupt_timer.png?rev=1698393&view=auto
==============================================================================
Binary file - no diff available.

Propchange: jmeter/trunk/xdocs/images/screenshots/timers/interrupt_timer.png
------------------------------------------------------------------------------
    svn:mime-type = image/png

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1698393&r1=1698392&r2=1698393&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Fri Aug 28 19:08:36 2015
@@ -5236,6 +5236,23 @@ to the random delay.</property>
 
 </component>
 
+<component name="Interrupt Timer" index="&sect-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>



Mime
View raw message