You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2012/08/30 15:31:15 UTC

svn commit: r1378929 - in /jmeter/trunk: docs/images/screenshots/ src/core/org/apache/jmeter/control/gui/ src/core/org/apache/jmeter/engine/ src/core/org/apache/jmeter/resources/ src/core/org/apache/jmeter/testelement/ xdocs/ xdocs/images/screenshots/ ...

Author: sebb
Date: Thu Aug 30 13:31:14 2012
New Revision: 1378929

URL: http://svn.apache.org/viewvc?rev=1378929&view=rev
Log:
Run tearDown Thread Groups after shutdown of main threads
Bugzilla Id: 53671

Modified:
    jmeter/trunk/docs/images/screenshots/testplan.png
    jmeter/trunk/src/core/org/apache/jmeter/control/gui/TestPlanGui.java
    jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.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/testelement/TestPlan.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/images/screenshots/testplan.png
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jmeter/trunk/docs/images/screenshots/testplan.png
URL: http://svn.apache.org/viewvc/jmeter/trunk/docs/images/screenshots/testplan.png?rev=1378929&r1=1378928&r2=1378929&view=diff
==============================================================================
Binary files - no diff available.

Modified: jmeter/trunk/src/core/org/apache/jmeter/control/gui/TestPlanGui.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/control/gui/TestPlanGui.java?rev=1378929&r1=1378928&r2=1378929&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/control/gui/TestPlanGui.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/control/gui/TestPlanGui.java Thu Aug 30 13:31:14 2012
@@ -55,6 +55,8 @@ public class TestPlanGui extends Abstrac
 
     private final JCheckBox serializedMode;
 
+    private final JCheckBox tearDownOnShutdown;
+
     /** A panel allowing the user to define variables. */
     private final ArgumentsPanel argsPanel;
 
@@ -68,6 +70,7 @@ public class TestPlanGui extends Abstrac
         argsPanel = new ArgumentsPanel(JMeterUtils.getResString("user_defined_variables")); // $NON-NLS-1$
         serializedMode = new JCheckBox(JMeterUtils.getResString("testplan.serialized")); // $NON-NLS-1$
         functionalMode = new JCheckBox(JMeterUtils.getResString("functional_mode")); // $NON-NLS-1$
+        tearDownOnShutdown = new JCheckBox(JMeterUtils.getResString("teardown_on_shutdown")); // $NON-NLS-1$
         init();
     }
 
@@ -113,6 +116,7 @@ public class TestPlanGui extends Abstrac
         if (plan instanceof TestPlan) {
             TestPlan tp = (TestPlan) plan;
             tp.setFunctionalMode(functionalMode.isSelected());
+            tp.setTearDownOnShutdown(tearDownOnShutdown.isSelected());
             tp.setSerialized(serializedMode.isSelected());
             tp.setUserDefinedVariables((Arguments) argsPanel.createTestElement());
             tp.setTestPlanClasspathArray(browseJar.getFiles());
@@ -151,6 +155,7 @@ public class TestPlanGui extends Abstrac
             TestPlan tp = (TestPlan) el;
         functionalMode.setSelected(tp.isFunctionalMode());
         serializedMode.setSelected(tp.isSerialized());
+        tearDownOnShutdown.setSelected(tp.isTearDownOnShutdown());
         final JMeterProperty udv = tp.getUserDefinedVariablesAsProperty();
         if (udv != null) {
             argsPanel.configure((Arguments) udv.getObjectValue());
@@ -172,6 +177,7 @@ public class TestPlanGui extends Abstrac
 
         VerticalPanel southPanel = new VerticalPanel();
         southPanel.add(serializedMode);
+        southPanel.add(tearDownOnShutdown);
         southPanel.add(functionalMode);
         JTextArea explain = new JTextArea(JMeterUtils.getResString("functional_mode_explanation")); // $NON-NLS-1$
         explain.setEditable(false);
@@ -187,6 +193,7 @@ public class TestPlanGui extends Abstrac
         super.clearGui();
         functionalMode.setSelected(false);
         serializedMode.setSelected(false);
+        tearDownOnShutdown.setSelected(false);
         argsPanel.clear();
         browseJar.clearFiles();
     }

Modified: jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java?rev=1378929&r1=1378928&r2=1378929&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java Thu Aug 30 13:31:14 2012
@@ -91,12 +91,18 @@ public class StandardJMeterEngine implem
     /** Flag to show whether test is running. Set to false to stop creating more threads. */
     private volatile boolean running = false;
 
+    /** Flag to show whether test was shutdown gracefully. */
+    private volatile boolean shutdown = false;
+
     /** Flag to show whether engine is active. Set to false at end of test. */
     private volatile boolean active = false;
 
     /** Thread Groups run sequentially */
     private volatile boolean serialized = false;
 
+    /** tearDown Thread Groups run after shutdown of main threads */
+    private volatile boolean tearDownOnShutdown = false;
+
     private HashTree test;
 
     private final String host;
@@ -160,9 +166,9 @@ public class StandardJMeterEngine implem
         if (plan.length == 0) {
             throw new RuntimeException("Could not find the TestPlan class!");
         }
-        if (((TestPlan) plan[0]).isSerialized()) {
-            serialized = true;
-        }
+        TestPlan tp = (TestPlan) plan[0];
+        serialized = tp.isSerialized();
+        tearDownOnShutdown = tp.isTearDownOnShutdown();
         active = true;
         test = testTree;
     }
@@ -245,8 +251,9 @@ public class StandardJMeterEngine implem
         stopTest(true);
     }
 
-    public synchronized void stopTest(boolean b) {
-        Thread stopThread = new Thread(new StopTest(b));
+    public synchronized void stopTest(boolean now) {
+        shutdown = !now;
+        Thread stopThread = new Thread(new StopTest(now));
         stopThread.start();
     }
 
@@ -371,6 +378,7 @@ public class StandardJMeterEngine implem
         System.gc();
 
         JMeterContextService.getContext().setSamplingStarted(true);
+        boolean mainGroups = running; // still running at this point, i.e. setUp was not cancelled
         while (running && iter.hasNext()) {// for each thread group
             AbstractThreadGroup group = iter.next();
             //ignore Setup and Post here.  We could have filtered the searcher. but then
@@ -406,6 +414,9 @@ public class StandardJMeterEngine implem
             groupCount = 0;
             JMeterContextService.clearTotalThreads();
             log.info("Starting tearDown thread groups");
+            if (mainGroups && !running) { // i.e. shutdown/stopped during main thread groups
+                running = shutdown & tearDownOnShutdown; // re-enable for tearDown if necessary
+            }
             while (running && postIter.hasNext()) {//for each setup thread group
                 AbstractThreadGroup group = postIter.next();
                 groupCount++;
@@ -502,7 +513,7 @@ public class StandardJMeterEngine implem
     }
 
     /**
-     * For each thread group, invoke:
+     * For each current thread group, invoke:
      * <ul> 
      * <li>{@link AbstractThreadGroup#stop()} - set stop flag</li>
      * </ul> 

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=1378929&r1=1378928&r2=1378929&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Thu Aug 30 13:31:14 2012
@@ -1006,6 +1006,7 @@ tcp_port=Port Number\:
 tcp_request_data=Text to send
 tcp_sample_title=TCP Sampler
 tcp_timeout=Timeout (milliseconds)\:
+teardown_on_shutdown=Run tearDown Thread Groups after shutdown of main threads
 template_field=Template\:
 test=Test
 test_action_action=Action

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=1378929&r1=1378928&r2=1378929&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 Aug 30 13:31:14 2012
@@ -1000,6 +1000,7 @@ tcp_port=Num\u00E9ro de port \:
 tcp_request_data=Texte \u00E0 envoyer \:
 tcp_sample_title=Requ\u00EAte TCP
 tcp_timeout=Expiration (millisecondes) \:
+teardown_on_shutdown=Run tearDown Thread Groups after shutdown of main threads
 template_field=Canevas \:
 test=Test
 test_action_action=Action \:

Modified: jmeter/trunk/src/core/org/apache/jmeter/testelement/TestPlan.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testelement/TestPlan.java?rev=1378929&r1=1378928&r2=1378929&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/testelement/TestPlan.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/testelement/TestPlan.java Thu Aug 30 13:31:14 2012
@@ -48,6 +48,9 @@ public class TestPlan extends AbstractTe
     private static final String SERIALIZE_THREADGROUPS = "TestPlan.serialize_threadgroups"; //$NON-NLS-1$
 
     private static final String CLASSPATHS = "TestPlan.user_define_classpath"; //$NON-NLS-1$
+
+    private static final String TEARDOWN_ON_SHUTDOWN = "TestPlan.tearDown_on_shutdown"; //$NON-NLS-1$
+
     //- JMX field names
 
     private static final String CLASSPATH_SEPARATOR = ","; //$NON-NLS-1$
@@ -144,6 +147,14 @@ public class TestPlan extends AbstractTe
         setProperty(new BooleanProperty(SERIALIZE_THREADGROUPS, serializeTGs));
     }
 
+    public void setTearDownOnShutdown(boolean tearDown) {
+        setProperty(TEARDOWN_ON_SHUTDOWN, tearDown, false);
+    }
+
+    public boolean isTearDownOnShutdown() {
+        return getPropertyAsBoolean(TEARDOWN_ON_SHUTDOWN, false);
+    }
+
     /**
      * Set the classpath for the test plan
      * @param text

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1378929&r1=1378928&r2=1378929&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Thu Aug 30 13:31:14 2012
@@ -150,6 +150,7 @@ The original behaviour can be restored b
 
 <h3>Controllers</h3>
 <ul>
+<li><bugzilla>53671</bugzilla> - tearDown thread group to run even if shutdown test happens</li>
 </ul>
 
 <h3>Listeners</h3>

Modified: jmeter/trunk/xdocs/images/screenshots/testplan.png
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/images/screenshots/testplan.png?rev=1378929&r1=1378928&r2=1378929&view=diff
==============================================================================
Binary files - no diff available.

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1378929&r1=1378928&r2=1378929&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Thu Aug 30 13:31:14 2012
@@ -5076,6 +5076,10 @@ If more data is required for a particula
 [The option does not affect CSV result files, which cannot currently store such information.]
 </p>
 <p>Also, an option exists here to instruct JMeter to run the <complink name="Thread Group"/> serially rather than in parallel.</p>
+<p>Run tearDown Thread Groups after shutdown of main threads: 
+if selected, the tearDown groups (if any) will be run after graceful shutdown of the main threads.
+The tearDown threads won't be run if the test is forcibly stopped.
+</p>
 <p>
 Test plan now provides an easy way to add classpath setting to a specific test plan. 
 The feature is additive, meaning that you can add jar files or directories, but removing an entry requires restarting JMeter.