You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2017/08/07 20:49:23 UTC

svn commit: r1804356 - in /jmeter/trunk: src/core/org/apache/jmeter/threads/JMeterThread.java xdocs/changes.xml

Author: pmouawad
Date: Mon Aug  7 20:49:23 2017
New Revision: 1804356

URL: http://svn.apache.org/viewvc?rev=1804356&view=rev
Log:
Bug 61380 - JMeter shutdown using timers releases thundering herd of interrupted samplers
Within this bug,  improve fix for bug 57958 which does not handle correctly the shutdown.
Bugzilla Id: 61380

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java?rev=1804356&r1=1804355&r2=1804356&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java Mon Aug  7 20:49:23 2017
@@ -386,15 +386,13 @@ public class JMeterThread implements Run
      */
     private SampleResult processSampler(Sampler current, Sampler parent, JMeterContext threadContext) {
         SampleResult transactionResult = null;
+        // Check if we are running a transaction
+        TransactionSampler transactionSampler = null;
+        // Find the package for the transaction
+        SamplePackage transactionPack = null;
         try {
-            // Check if we are running a transaction
-            TransactionSampler transactionSampler = null;
             if(current instanceof TransactionSampler) {
                 transactionSampler = (TransactionSampler) current;
-            }
-            // Find the package for the transaction
-            SamplePackage transactionPack = null;
-            if(transactionSampler != null) {
                 transactionPack = compiler.configureTransactionSampler(transactionSampler);
 
                 // Check if the transaction is done
@@ -434,25 +432,16 @@ public class JMeterThread implements Run
             if (log.isInfoEnabled()) {
                 log.info("Stopping Test: {}", e.toString());
             }
-            if (current instanceof TransactionSampler) {
-                doEndTransactionSampler((TransactionSampler) current, parent, compiler.configureTransactionSampler((TransactionSampler) current), threadContext);
-            }
             shutdownTest();
         } catch (JMeterStopTestNowException e) { // NOSONAR
             if (log.isInfoEnabled()) {
                 log.info("Stopping Test with interruption of current samplers: {}", e.toString());
             }
-            if (current instanceof TransactionSampler) {
-                doEndTransactionSampler((TransactionSampler) current, parent, compiler.configureTransactionSampler((TransactionSampler) current), threadContext);
-            }
             stopTestNow();
         } catch (JMeterStopThreadException e) { // NOSONAR
             if (log.isInfoEnabled()) {
                 log.info("Stopping Thread: {}", e.toString());
             }
-            if (current instanceof TransactionSampler) {
-                doEndTransactionSampler((TransactionSampler) current, parent, compiler.configureTransactionSampler((TransactionSampler) current), threadContext);
-            }
             stopThread();
         } catch (Exception e) {
             if (current != null) {
@@ -461,6 +450,13 @@ public class JMeterThread implements Run
                 log.error("Error while processing sampler.", e);
             }
         }
+        if(!running 
+                && transactionResult == null 
+                && transactionSampler != null
+                && transactionPack != null) {
+            transactionResult = doEndTransactionSampler(transactionSampler, parent, transactionPack, threadContext);
+        }
+
         return transactionResult;
     }
 
@@ -482,32 +478,33 @@ public class JMeterThread implements Run
         threadVars.putObject(PACKAGE_OBJECT, pack);
 
         delay(pack.getTimers());
-        Sampler sampler = pack.getSampler();
-        sampler.setThreadContext(threadContext);
-        // TODO should this set the thread names for all the subsamples?
-        // might be more efficient than fetching the name elsewhere
-        sampler.setThreadName(threadName);
-        TestBeanHelper.prepare(sampler);
-
-        // Perform the actual sample
-        currentSampler = sampler;
-        if(!sampleMonitors.isEmpty()) {
-            for(SampleMonitor sampleMonitor : sampleMonitors) {
-                sampleMonitor.sampleStarting(sampler);
-            }
-        }
         SampleResult result = null;
-        try {
-            result = sampler.sample(null);
-        } finally {
+        if(running) {
+            Sampler sampler = pack.getSampler();
+            sampler.setThreadContext(threadContext);
+            // TODO should this set the thread names for all the subsamples?
+            // might be more efficient than fetching the name elsewhere
+            sampler.setThreadName(threadName);
+            TestBeanHelper.prepare(sampler);
+    
+            // Perform the actual sample
+            currentSampler = sampler;
             if(!sampleMonitors.isEmpty()) {
                 for(SampleMonitor sampleMonitor : sampleMonitors) {
-                    sampleMonitor.sampleEnded(sampler);
+                    sampleMonitor.sampleStarting(sampler);
+                }
+            }
+            try {
+                result = sampler.sample(null);
+            } finally {
+                if(!sampleMonitors.isEmpty()) {
+                    for(SampleMonitor sampleMonitor : sampleMonitors) {
+                        sampleMonitor.sampleEnded(sampler);
+                    }
                 }
             }
+            currentSampler = null;
         }
-        currentSampler = null;
-
         // If we got any results, then perform processing on the result
         if (result != null) {
             int nbActiveThreadsInThreadGroup = threadGroup.getNumberOfThreads();
@@ -537,21 +534,12 @@ public class JMeterThread implements Run
 
             // Check if thread or test should be stopped
             if (result.isStopThread() || (!result.isSuccessful() && onErrorStopThread)) {
-                if (transactionSampler != null) {
-                    doEndTransactionSampler(transactionSampler, current, transactionPack, threadContext);
-                }
                 stopThread();
             }
             if (result.isStopTest() || (!result.isSuccessful() && onErrorStopTest)) {
-                if (transactionSampler != null) {
-                    doEndTransactionSampler(transactionSampler, current, transactionPack, threadContext);
-                }
                 shutdownTest();
             }
             if (result.isStopTestNow() || (!result.isSuccessful() && onErrorStopTestNow)) {
-                if (transactionSampler != null) {
-                    doEndTransactionSampler(transactionSampler, current, transactionPack, threadContext);
-                }
                 stopTestNow();
             }
             if(result.isStartNextThreadLoop()) {
@@ -567,9 +555,8 @@ public class JMeterThread implements Run
                             Sampler parent,
                             SamplePackage transactionPack,
                             JMeterContext threadContext) {
-        SampleResult transactionResult;
         // Get the transaction sample result
-        transactionResult = transactionSampler.getTransactionResult();
+        SampleResult transactionResult = transactionSampler.getTransactionResult();
         transactionResult.setThreadName(threadName);
         transactionResult.setGroupThreads(threadGroup.getNumberOfThreads());
         transactionResult.setAllThreads(JMeterContextService.getNumberOfThreads());

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1804356&r1=1804355&r2=1804356&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Mon Aug  7 20:49:23 2017
@@ -223,6 +223,7 @@ Incorporated feed back about unclear doc
     <li><bug>61270</bug>Fixed width fonts too small in text areas to read under hidpi (user manual bug)</li>
     <li><bug>61292</bug>Make processing of samples in reporter more robust.</li>
     <li><bug>61359</bug>When cutting an element from Tree, Test plan is not marked as dirty</li>
+    <li><bug>61380</bug>JMeter shutdown using timers releases thundering herd of interrupted samplers</li>
 </ul>
 
  <!--  =================== Thanks =================== -->