jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1304962 - in /jmeter/trunk: src/core/org/apache/jmeter/control/TransactionController.java src/core/org/apache/jmeter/threads/JMeterThread.java xdocs/changes.xml
Date Sat, 24 Mar 2012 23:22:29 GMT
Author: pmouawad
Date: Sat Mar 24 23:22:29 2012
New Revision: 1304962

URL: http://svn.apache.org/viewvc?rev=1304962&view=rev
Log:
Bug 52968 - Option Start Next Loop in Thread Group does not mark parent Transaction Sampler
in error when an error occurs

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

Modified: jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java?rev=1304962&r1=1304961&r2=1304962&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java Sat Mar 24
23:22:29 2012
@@ -26,6 +26,7 @@ import org.apache.jmeter.samplers.Sample
 import org.apache.jmeter.samplers.Sampler;
 import org.apache.jmeter.testelement.property.BooleanProperty;
 import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterThread;
 import org.apache.jmeter.threads.JMeterVariables;
 import org.apache.jmeter.threads.ListenerNotifier;
@@ -43,33 +44,52 @@ import org.apache.log.Logger;
  */
 public class TransactionController extends GenericController implements SampleListener, Controller,
Serializable {
     private static final long serialVersionUID = 233L;
+    
+    private static final String TRUE = Boolean.toString(true); // i.e. "true"
 
+    private static final String PARENT = "TransactionController.parent";// $NON-NLS-1$
+
+    private final static String INCLUDE_TIMERS = "TransactionController.includeTimers";//
$NON-NLS-1$
+    
     private static final Logger log = LoggingManager.getLoggerForClass();
 
+    /**
+     * Only used in parent Mode
+     */
     private transient TransactionSampler transactionSampler;
-
+    
+    /**
+     * Only used in NON parent Mode
+     */
     private transient ListenerNotifier lnf;
 
+    /**
+     * Only used in NON parent Mode
+     */
     private transient SampleResult res;
-
+    
+    /**
+     * Only used in NON parent Mode
+     */
     private transient int calls;
-
+    
+    /**
+     * Only used in NON parent Mode
+     */
     private transient int noFailingSamples;
 
     /**
      * Cumulated pause time to excluse timer and post/pre processor times
+     * Only used in NON parent Mode
      */
     private transient long pauseTime;
 
     /**
      * Previous end time
+     * Only used in NON parent Mode
      */
     private transient long prevEndTime;
 
-    private static final String PARENT = "TransactionController.parent";// $NON-NLS-1$
-
-    private final static String INCLUDE_TIMERS = "TransactionController.includeTimers";//
$NON-NLS-1$
-
     /**
      * Creates a Transaction Controller
      */
@@ -173,32 +193,12 @@ public class TransactionController exten
         {
             if (res != null) {
                 res.setIdleTime(pauseTime+res.getIdleTime());
-                 res.sampleEnd();
+                res.sampleEnd();
                 res.setResponseMessage("Number of samples in transaction : " + calls + ",
number of failing samples : " + noFailingSamples);
                 if(res.isSuccessful()) {
                     res.setResponseCodeOK();
                 }
-
-                // TODO could these be done earlier (or just once?)
-                JMeterContext threadContext = getThreadContext();
-                JMeterVariables threadVars = threadContext.getVariables();
-
-                SamplePackage pack = (SamplePackage) threadVars.getObject(JMeterThread.PACKAGE_OBJECT);
-                if (pack == null) {
-                	// If child of TransactionController is a ThroughputController and TPC does
-                	// not sample its children, then we will have this
-                	// TODO Should this be at warn level ?
-                    log.warn("Could not fetch SamplePackage");
-                } else {
-                    SampleEvent event = new SampleEvent(res, threadContext.getThreadGroup().getName(),threadVars,
true);
-                    // We must set res to null now, before sending the event for the transaction,
-                    // so that we can ignore that event in our sampleOccured method
-                    res = null;
-                    // bug 50032 
-                    if (!getThreadContext().isReinitializingSubControllers()) {
-                        lnf.notifyListeners(event, pack.getSampleListeners());
-                    }
-                }
+                notifyListeners();
             }
         }
         else {
@@ -209,6 +209,52 @@ public class TransactionController exten
         return returnValue;
     }
 
+    /**
+     * @see org.apache.jmeter.control.GenericController#triggerEndOfLoop()
+     */
+    @Override
+    public void triggerEndOfLoop() {
+        if(!isParent()) {
+            if (res != null) {
+                res.setIdleTime(pauseTime+res.getIdleTime());
+                res.sampleEnd();
+                res.setSuccessful(TRUE.equals(JMeterContextService.getContext().getVariables().get(JMeterThread.LAST_SAMPLE_OK)));
+                res.setResponseMessage("Number of samples in transaction : " + calls + ",
number of failing samples : " + noFailingSamples);
+                notifyListeners();
+            }
+        } else {
+            transactionSampler.setTransactionDone();
+            // This transaction is done
+            transactionSampler = null;
+        }
+        super.triggerEndOfLoop();
+    }
+
+    /**
+     * Create additional SampleEvent in NON Parent Mode
+     */
+    protected void notifyListeners() {
+        // TODO could these be done earlier (or just once?)
+        JMeterContext threadContext = getThreadContext();
+        JMeterVariables threadVars = threadContext.getVariables();
+        SamplePackage pack = (SamplePackage) threadVars.getObject(JMeterThread.PACKAGE_OBJECT);
+        if (pack == null) {
+            // If child of TransactionController is a ThroughputController and TPC does
+            // not sample its children, then we will have this
+            // TODO Should this be at warn level ?
+            log.warn("Could not fetch SamplePackage");
+        } else {
+            SampleEvent event = new SampleEvent(res, threadContext.getThreadGroup().getName(),threadVars,
true);
+            // We must set res to null now, before sending the event for the transaction,
+            // so that we can ignore that event in our sampleOccured method
+            res = null;
+            // bug 50032 
+            if (!getThreadContext().isReinitializingSubControllers()) {
+                lnf.notifyListeners(event, pack.getSampleListeners());
+            }
+        }
+    }
+
     public void sampleOccurred(SampleEvent se) {
         if (!isParent()) {
             // Check if we are still sampling our children

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=1304962&r1=1304961&r2=1304962&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java Sat Mar 24 23:22:29
2012
@@ -271,7 +271,7 @@ public class JMeterThread implements Run
                 	process_sampler(sam, null, threadContext);
                 	if(onErrorStartNextLoop || threadContext.isRestartNextLoop()) {
                 	    if(threadContext.isRestartNextLoop()) {
-                            triggerEndOfLoopOnParentControllers(sam);
+                            triggerEndOfLoopOnParentControllers(sam, threadContext);
                             sam = null;
                             threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE);
                             threadContext.setRestartNextLoop(false);
@@ -281,7 +281,7 @@ public class JMeterThread implements Run
     	                		if(log.isDebugEnabled()) {
     	                    		log.debug("StartNextLoop option is on, Last sample failed, starting
next loop");
     	                    	}
-    	                    	triggerEndOfLoopOnParentControllers(sam);
+    	                    	triggerEndOfLoopOnParentControllers(sam, threadContext);
     	                        sam = null;
     	                        threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE);
                     		} else {
@@ -333,10 +333,18 @@ public class JMeterThread implements Run
     /**
      * Trigger end of loop on parent controllers up to Thread Group
      * @param sam Sampler Base sampler
+     * @param threadContext 
      */
-    private void triggerEndOfLoopOnParentControllers(Sampler sam) {
+    private void triggerEndOfLoopOnParentControllers(Sampler sam, JMeterContext threadContext)
{
         // Find parent controllers of current sampler
-        FindTestElementsUpToRootTraverser pathToRootTraverser = new FindTestElementsUpToRootTraverser(sam);
+        FindTestElementsUpToRootTraverser pathToRootTraverser=null;
+        TransactionSampler transactionSampler = null;
+        if(sam instanceof TransactionSampler) {
+            transactionSampler = (TransactionSampler) sam;
+            pathToRootTraverser = new FindTestElementsUpToRootTraverser((transactionSampler).getTransactionController());
+        } else {
+            pathToRootTraverser = new FindTestElementsUpToRootTraverser(sam);
+        }
         testTree.traverse(pathToRootTraverser);
         List<Controller> controllersToReinit = pathToRootTraverser.getControllersToRoot();
   	
@@ -351,6 +359,9 @@ public class JMeterThread implements Run
                 parentController.triggerEndOfLoop();
             }
         }
+        if(transactionSampler!=null) {
+            process_sampler(transactionSampler, null, threadContext);
+        }
     }
 
     /**

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1304962&r1=1304961&r2=1304962&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Mar 24 23:22:29 2012
@@ -103,6 +103,7 @@ Graph Full Results Listener has been rem
 
 <h3>Controllers</h3>
 <ul>
+<li>Bug 52968 - Option Start Next Loop in Thread Group does not mark parent Transaction
Sampler in error when an error occurs</li>
 </ul>
 
 <h3>Listeners</h3>



Mime
View raw message