jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1698378 - in /jmeter/trunk: src/protocol/java/org/apache/jmeter/protocol/java/sampler/ src/protocol/java/org/apache/jmeter/protocol/java/test/ xdocs/
Date Fri, 28 Aug 2015 17:16:29 GMT
Author: sebb
Date: Fri Aug 28 17:16:28 2015
New Revision: 1698378

URL: http://svn.apache.org/r1698378
Log:
 Make existing Java Samplers implement Interruptible
Bugzilla Id: 58300

Modified:
    jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/JavaSampler.java
    jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/test/JavaTest.java
    jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/test/SleepTest.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/JavaSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/JavaSampler.java?rev=1698378&r1=1698377&r2=1698378&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/JavaSampler.java
(original)
+++ jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/JavaSampler.java
Fri Aug 28 17:16:28 2015
@@ -29,6 +29,7 @@ import org.apache.jmeter.config.Argument
 import org.apache.jmeter.config.ConfigTestElement;
 import org.apache.jmeter.samplers.AbstractSampler;
 import org.apache.jmeter.samplers.Entry;
+import org.apache.jmeter.samplers.Interruptible;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.testelement.TestElement;
 import org.apache.jmeter.testelement.TestStateListener;
@@ -42,7 +43,7 @@ import org.apache.log.Logger;
  * information on writing Java code to be executed by this sampler.
  *
  */
-public class JavaSampler extends AbstractSampler implements TestStateListener {
+public class JavaSampler extends AbstractSampler implements TestStateListener, Interruptible
{
 
     private static final Logger log = LoggingManager.getLoggerForClass();
 
@@ -334,4 +335,13 @@ public class JavaSampler extends Abstrac
         String guiClass = configElement.getProperty(TestElement.GUI_CLASS).getStringValue();
         return APPLIABLE_CONFIG_CLASSES.contains(guiClass);
     }
+
+    @Override
+    public boolean interrupt() {
+        if (javaClient instanceof Interruptible) {
+            return ((Interruptible) javaClient).interrupt();
+            
+        }
+        return false;
+    }
 }

Modified: jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/test/JavaTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/test/JavaTest.java?rev=1698378&r1=1698377&r2=1698378&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/test/JavaTest.java (original)
+++ jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/test/JavaTest.java Fri
Aug 28 17:16:28 2015
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
 import org.apache.jmeter.config.Arguments;
 import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
 import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
+import org.apache.jmeter.samplers.Interruptible;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.testelement.TestElement;
 import org.apache.jorphan.logging.LoggingManager;
@@ -67,7 +68,7 @@ import org.apache.log.Logger;
  *
  */
 
-public class JavaTest extends AbstractJavaSamplerClient implements Serializable {
+public class JavaTest extends AbstractJavaSamplerClient implements Serializable, Interruptible
{
 
     private static final Logger LOG = LoggingManager.getLoggerForClass();
 
@@ -150,6 +151,8 @@ public class JavaTest extends AbstractJa
     /** The name used to store the Success Status parameter. */
     private static final String SUCCESS_NAME = "Status";
 
+    private volatile Thread myThread;
+
     /**
      * Default constructor for <code>JavaTest</code>.
      *
@@ -300,12 +303,14 @@ public class JavaTest extends AbstractJa
             // Execute the sample. In this case sleep for the
             // specified time, if any
             if (sleep > 0) {
+                myThread = Thread.currentThread();
                 TimeUnit.MILLISECONDS.sleep(sleep);
+                myThread = null;
             }
             results.setSuccessful(success);
         } catch (InterruptedException e) {
             LOG.warn("JavaTest: interrupted.");
-            results.setSuccessful(true);
+            results.setSuccessful(false);
         } catch (Exception e) {
             LOG.error("JavaTest: error during sample", e);
             results.setSuccessful(false);
@@ -350,4 +355,12 @@ public class JavaTest extends AbstractJa
         return sb.toString();
     }
 
+    @Override
+    public boolean interrupt() {
+        Thread t = myThread;
+        if (t!= null) {
+            t.interrupt();
+        }
+        return t != null;
+    }
 }

Modified: jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/test/SleepTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/test/SleepTest.java?rev=1698378&r1=1698377&r2=1698378&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/test/SleepTest.java (original)
+++ jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/test/SleepTest.java Fri
Aug 28 17:16:28 2015
@@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
 import org.apache.jmeter.config.Arguments;
 import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
 import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
+import org.apache.jmeter.samplers.Interruptible;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.testelement.TestElement;
 import org.apache.jorphan.logging.LoggingManager;
@@ -47,7 +48,7 @@ import org.apache.log.Logger;
  *
  * @version $Revision$
  */
-public class SleepTest extends AbstractJavaSamplerClient implements Serializable {
+public class SleepTest extends AbstractJavaSamplerClient implements Serializable, Interruptible
{
 
     private static final Logger LOG = LoggingManager.getLoggerForClass();
 
@@ -77,6 +78,8 @@ public class SleepTest extends AbstractJ
     // The name of the sampler
     private String name;
 
+    private volatile Thread myThread;
+
     /**
      * Default constructor for <code>SleepTest</code>.
      *
@@ -148,14 +151,16 @@ public class SleepTest extends AbstractJ
             // Record sample start time.
             results.sampleStart();
 
+            myThread = Thread.currentThread();
             // Execute the sample. In this case sleep for the
             // specified time.
             TimeUnit.MILLISECONDS.sleep(sleep);
+            myThread = null;
 
             results.setSuccessful(true);
         } catch (InterruptedException e) {
             LOG.warn("SleepTest: interrupted.");
-            results.setSuccessful(true);
+            results.setSuccessful(false);
             results.setResponseMessage(e.toString());
         } catch (Exception e) {
             LOG.error("SleepTest: error during sample", e);
@@ -219,4 +224,13 @@ public class SleepTest extends AbstractJ
         sb.append(Integer.toHexString(hashCode()));
         return sb.toString();
     }
+
+    @Override
+    public boolean interrupt() {
+        Thread t = myThread;
+        if (t!= null) {
+            t.interrupt();
+        }
+        return t != null;
+    }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1698378&r1=1698377&r2=1698378&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Fri Aug 28 17:16:28 2015
@@ -89,6 +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>
 </ul>
 
 <h3>Controllers</h3>



Mime
View raw message