jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1239590 - in /jmeter/trunk: src/components/org/apache/jmeter/sampler/ src/components/org/apache/jmeter/sampler/gui/ src/core/org/apache/jmeter/resources/ src/core/org/apache/jmeter/threads/ xdocs/
Date Thu, 02 Feb 2012 12:50:53 GMT
Author: pmouawad
Date: Thu Feb  2 12:50:53 2012
New Revision: 1239590

URL: http://svn.apache.org/viewvc?rev=1239590&view=rev
Log:
Bug 45839 - Test Action : Allow premature exit from a loop

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/sampler/TestAction.java
    jmeter/trunk/src/components/org/apache/jmeter/sampler/gui/TestActionGui.java
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java
    jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/sampler/TestAction.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/sampler/TestAction.java?rev=1239590&r1=1239589&r2=1239590&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/sampler/TestAction.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/sampler/TestAction.java Thu Feb  2 12:50:53
2012
@@ -42,6 +42,7 @@ public class TestAction extends Abstract
     public final static int STOP = 0;
     public final static int PAUSE = 1;
     public final static int STOP_NOW = 2;
+    public final static int RESTART_NEXT_LOOP = 3;
 
     // Action targets
     public final static int THREAD = 0;
@@ -67,10 +68,15 @@ public class TestAction extends Abstract
         int action = getAction();
         if (action == PAUSE) {
             pause(getDurationAsString());
-        } else if (action == STOP || action == STOP_NOW) {
+        } else if (action == STOP || action == STOP_NOW || action == RESTART_NEXT_LOOP) {
             if (target == THREAD) {
-                log.info("Stopping current thread");
-                context.getThread().stop();
+                if(action == STOP || action == STOP_NOW) {
+                    log.info("Stopping current thread");
+                    context.getThread().stop();                    
+                } else {
+                    log.info("Restarting next loop");
+                    context.setRestartNextLoop(true);
+                }
 //             //Not yet implemented
 //            } else if (target==THREAD_GROUP) {
             } else if (target == TEST) {

Modified: jmeter/trunk/src/components/org/apache/jmeter/sampler/gui/TestActionGui.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/sampler/gui/TestActionGui.java?rev=1239590&r1=1239589&r2=1239590&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/sampler/gui/TestActionGui.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/sampler/gui/TestActionGui.java Thu Feb 
2 12:50:53 2012
@@ -52,6 +52,8 @@ public class TestActionGui extends Abstr
 
     private JRadioButton stopNowButton;
 
+    private JRadioButton restartNextLoopButton;
+    
     private JTextField durationField;
 
     // State variables
@@ -77,6 +79,8 @@ public class TestActionGui extends Abstr
 
     private final String stopNowAction = JMeterUtils.getResString("test_action_stop_now");
// $NON-NLS-1$
 
+    private final String restartNextLoopAction = JMeterUtils.getResString("test_action_restart_next_loop");
// $NON-NLS-1$
+
     private final String durationLabel = JMeterUtils.getResString("test_action_duration");
// $NON-NLS-1$
 
     public TestActionGui() {
@@ -107,8 +111,10 @@ public class TestActionGui extends Abstr
             pauseButton.setSelected(true);
         } else if (action == TestAction.STOP_NOW) {
             stopNowButton.setSelected(true);
-        } else {
+        } else if(action == TestAction.STOP ){
             stopButton.setSelected(true);
+        } else {
+            restartNextLoopButton.setSelected(true);
         }
 
         durationString = ta.getDurationAsString();
@@ -186,6 +192,7 @@ public class TestActionGui extends Abstr
                 if (pauseButton.isSelected()) {
                     action = TestAction.PAUSE;
                     durationField.setEnabled(true);
+                    targetBox.setEnabled(true);
                 }
 
             }
@@ -196,6 +203,7 @@ public class TestActionGui extends Abstr
                 if (stopButton.isSelected()) {
                     action = TestAction.STOP;
                     durationField.setEnabled(false);
+                    targetBox.setEnabled(true);
                 }
             }
         });
@@ -205,16 +213,33 @@ public class TestActionGui extends Abstr
                 if (stopNowButton.isSelected()) {
                     action = TestAction.STOP_NOW;
                     durationField.setEnabled(false);
+                    targetBox.setEnabled(true);
                 }
             }
         });
+        
+        restartNextLoopButton = new JRadioButton(restartNextLoopAction, false);
+        restartNextLoopButton.addChangeListener(new ChangeListener() {
+            public void stateChanged(ChangeEvent e) {
+                if (restartNextLoopButton.isSelected()) {
+                    action = TestAction.RESTART_NEXT_LOOP;
+                    durationField.setEnabled(false);
+                    targetBox.setSelectedIndex(TestAction.THREAD);
+                    targetBox.setEnabled(false);
+                }
+            }
+        });
+        
         actionButtons.add(pauseButton);
         actionButtons.add(stopButton);
         actionButtons.add(stopNowButton);
+        actionButtons.add(restartNextLoopButton);
+
         actionPanel.add(new JLabel(actionLabel));
         actionPanel.add(pauseButton);
         actionPanel.add(stopButton);
         actionPanel.add(stopNowButton);
+        actionPanel.add(restartNextLoopButton);
         add(actionPanel);
 
         // Duration

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=1239590&r1=1239589&r2=1239590&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Thu Feb  2 12:50:53
2012
@@ -760,7 +760,7 @@ sample_scope_variable=JMeter Variable
 sampler_label=Label
 sampler_on_error_action=Action to be taken after a Sampler error
 sampler_on_error_continue=Continue
-sampler_on_error_start_next_loop=Start Next Loop
+sampler_on_error_start_next_loop=Start Next Thread Loop
 sampler_on_error_stop_test=Stop Test
 sampler_on_error_stop_test_now=Stop Test Now
 sampler_on_error_stop_thread=Stop Thread
@@ -959,6 +959,7 @@ test=Test
 test_action_action=Action
 test_action_duration=Duration (milliseconds)
 test_action_pause=Pause
+test_action_restart_next_loop=Go to next loop iteration
 test_action_stop=Stop
 test_action_stop_now=Stop Now
 test_action_target=Target
@@ -1159,4 +1160,4 @@ xpath_tidy_report_errors=Report errors
 xpath_tidy_show_warnings=Show warnings
 you_must_enter_a_valid_number=You must enter a valid number
 zh_cn=Chinese (Simplified)
-zh_tw=Chinese (Traditional)
+zh_tw=Chinese (Traditional)
\ No newline at end of file

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1239590&r1=1239589&r2=1239590&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Thu Feb  2 12:50:53
2012
@@ -953,6 +953,7 @@ test=Test
 test_action_action=Action \:
 test_action_duration=Dur\u00E9e (millisecondes) \:
 test_action_pause=Mettre en pause
+test_action_restart_next_loop=Passer \u00E0 l'it\u00E9ration suivante de la boucle
 test_action_stop=Arr\u00EAter
 test_action_stop_now=Arr\u00EAter imm\u00E9diatement
 test_action_target=Cible \:

Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java?rev=1239590&r1=1239589&r2=1239590&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java Thu Feb  2 12:50:53
2012
@@ -18,9 +18,9 @@
 
 package org.apache.jmeter.threads;
 
+import org.apache.jmeter.engine.StandardJMeterEngine;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.samplers.Sampler;
-import org.apache.jmeter.engine.StandardJMeterEngine;
 
 /**
  * Holds context for a thread.
@@ -49,6 +49,8 @@ public class JMeterContext {
 
     private boolean isReinitSubControllers = false;
 
+    private boolean restartNextLoop = false;
+
     JMeterContext() {
         clear0();
     }
@@ -187,4 +189,20 @@ public class JMeterContext {
     public boolean isReinitializingSubControllers() {
         return isReinitSubControllers;
     }
+
+    /**
+     * if set to true a restart of the loop will occurs
+     * @param restartNextLoop
+     */
+    public void setRestartNextLoop(boolean restartNextLoop) {
+        this.restartNextLoop = restartNextLoop;
+    }
+
+    /**
+     * a restart of the loop was required ?
+     * @return the restartNextLoop
+     */
+    public boolean isRestartNextLoop() {
+        return restartNextLoop;
+    }
 }

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=1239590&r1=1239589&r2=1239590&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java Thu Feb  2 12:50:53
2012
@@ -269,33 +269,25 @@ public class JMeterThread implements Run
                 Sampler sam = firstSampler;
                 while (running && sam != null) {
                 	process_sampler(sam, null, threadContext);
-                	if(onErrorStartNextLoop) {
-                		boolean lastSampleFailed = !TRUE.equals(threadContext.getVariables().get(LAST_SAMPLE_OK));
-                		if(lastSampleFailed) {
-	                		if(log.isDebugEnabled()) {
-	                    		log.debug("StartNextLoop option is on, Last sample failed, starting
next loop");
-	                    	}
-	                    	// Find parent controllers of current sampler
-	                        FindTestElementsUpToRootTraverser pathToRootTraverser = new FindTestElementsUpToRootTraverser(sam);
-	                        testTree.traverse(pathToRootTraverser);
-	                        List<Controller> controllersToReinit = pathToRootTraverser.getControllersToRoot();
-	
-	                        // Trigger end of loop condition on all parent controllers of current
sampler
-	                        for (Iterator<Controller> iterator = controllersToReinit
-	                                .iterator(); iterator.hasNext();) {
-	                            Controller parentController =  iterator.next();
-	                            if(parentController instanceof ThreadGroup) {
-	                                ThreadGroup tg = (ThreadGroup) parentController;
-	                                tg.startNextLoop();
-	                            } else {
-	                                parentController.triggerEndOfLoop();
-	                            }
-	                        }
-	                        sam = null;
-	                        threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE);
-                		} else {
-                			sam = controller.next();
-                		}
+                	if(onErrorStartNextLoop || threadContext.isRestartNextLoop()) {
+                	    if(threadContext.isRestartNextLoop()) {
+                            triggerEndOfLoopOnParentControllers(sam);
+                            sam = null;
+                            threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE);
+                            threadContext.setRestartNextLoop(false);
+                	    } else {
+                    		boolean lastSampleFailed = !TRUE.equals(threadContext.getVariables().get(LAST_SAMPLE_OK));
+                    		if(lastSampleFailed) {
+    	                		if(log.isDebugEnabled()) {
+    	                    		log.debug("StartNextLoop option is on, Last sample failed, starting
next loop");
+    	                    	}
+    	                    	triggerEndOfLoopOnParentControllers(sam);
+    	                        sam = null;
+    	                        threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE);
+                    		} else {
+                    			sam = controller.next();
+                    		}
+                	    }
                 	} 
                 	else {
                 		sam = controller.next();
@@ -339,6 +331,29 @@ public class JMeterThread implements Run
     }
 
     /**
+     * Trigger end of loop on parent controllers up to Thread Group
+     * @param sam Sampler Base sampler
+     */
+    private void triggerEndOfLoopOnParentControllers(Sampler sam) {
+        // Find parent controllers of current sampler
+        FindTestElementsUpToRootTraverser pathToRootTraverser = new FindTestElementsUpToRootTraverser(sam);
+        testTree.traverse(pathToRootTraverser);
+        List<Controller> controllersToReinit = pathToRootTraverser.getControllersToRoot();
+  	
+        // Trigger end of loop condition on all parent controllers of current sampler
+        for (Iterator<Controller> iterator = controllersToReinit
+                .iterator(); iterator.hasNext();) {
+            Controller parentController =  iterator.next();
+            if(parentController instanceof ThreadGroup) {
+                ThreadGroup tg = (ThreadGroup) parentController;
+                tg.startNextLoop();
+            } else {
+                parentController.triggerEndOfLoop();
+            }
+        }
+    }
+
+    /**
      * Process the current sampler, handling transaction samplers.
      *
      * @param current sampler

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1239590&r1=1239589&r2=1239590&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Thu Feb  2 12:50:53 2012
@@ -133,7 +133,7 @@ or a Debug Sampler with all fields set t
 
 <h3>General</h3>
 <ul>
-
+<li>Bug 45839 - Test Action : Allow premature exit from a loop</li>
 </ul>
 
 <h2>Non-functional changes</h2>



Mime
View raw message