You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by Felix Schumacher <fe...@internetallee.de> on 2017/05/12 04:34:28 UTC

Re: svn commit: r1794861 - in /jmeter/trunk: src/core/org/apache/jmeter/threads/JMeterThread.java test/src/org/apache/jmeter/control/TestTransactionController.java xdocs/changes.xml


Am 11. Mai 2017 20:02:25 MESZ schrieb undera@apache.org:
>Author: undera
>Date: Thu May 11 18:02:25 2017
>New Revision: 1794861
>
>URL: http://svn.apache.org/viewvc?rev=1794861&view=rev
>Log:
>Bug 57958 - Fix transaction sample not generated if thread
>stops/restarts
>
>Added:
>jmeter/trunk/test/src/org/apache/jmeter/control/TestTransactionController.java
>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=1794861&r1=1794860&r2=1794861&view=diff
>==============================================================================
>--- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java
>(original)
>+++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java
>Thu May 11 18:02:25 2017
>@@ -433,16 +433,25 @@ public class JMeterThread implements Run
>             if (log.isInfoEnabled()) {
>                 log.info("Stopping Test: {}", e.toString());
>             }
>+            if (current != null && current instanceof
>TransactionSampler) {

The null check is not needed, as the instanceof is false in case of current being null.

>+                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 != null && current instanceof
>TransactionSampler) {

Same here.

>+                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 != null && current instanceof
>TransactionSampler) {

... and here :)

Regards,
 Felix

>+                doEndTransactionSampler((TransactionSampler) current,
>parent, compiler.configureTransactionSampler((TransactionSampler)
>current), threadContext);
>+            }
>             stopThread();
>         } catch (Exception e) {
>             if (current != null) {
>@@ -527,12 +536,21 @@ 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()) {
>
>Added:
>jmeter/trunk/test/src/org/apache/jmeter/control/TestTransactionController.java
>URL:
>http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/control/TestTransactionController.java?rev=1794861&view=auto
>==============================================================================
>---
>jmeter/trunk/test/src/org/apache/jmeter/control/TestTransactionController.java
>(added)
>+++
>jmeter/trunk/test/src/org/apache/jmeter/control/TestTransactionController.java
>Thu May 11 18:02:25 2017
>@@ -0,0 +1,95 @@
>+package org.apache.jmeter.control;
>+
>+import org.apache.jmeter.assertions.ResponseAssertion;
>+import org.apache.jmeter.junit.JMeterTestCase;
>+import org.apache.jmeter.reporters.ResultCollector;
>+import org.apache.jmeter.sampler.DebugSampler;
>+import org.apache.jmeter.samplers.SampleEvent;
>+import org.apache.jmeter.samplers.SampleListener;
>+import org.apache.jmeter.threads.JMeterContextService;
>+import org.apache.jmeter.threads.JMeterThread;
>+import org.apache.jmeter.threads.JMeterVariables;
>+import org.apache.jmeter.threads.ListenerNotifier;
>+import org.apache.jmeter.threads.TestCompiler;
>+import org.apache.jmeter.threads.ThreadGroup;
>+import org.apache.jorphan.collections.ListedHashTree;
>+import org.junit.Test;
>+
>+import java.util.ArrayList;
>+import java.util.List;
>+
>+import static org.junit.Assert.assertEquals;
>+
>+
>+public class TestTransactionController extends JMeterTestCase {
>+
>+    /**
>+     * @see "http://bz.apache.org/bugzilla/show_bug.cgi?id=57958"
>+     */
>+    @Test
>+    public void testIssue57958() throws Exception {
>+        JMeterContextService.getContext().setVariables(new
>JMeterVariables());
>+
>+
>+        TestSampleListener listener = new TestSampleListener();
>+
>+        TransactionController transactionController = new
>TransactionController();
>+        transactionController.setGenerateParentSample(true);
>+
>+        ResponseAssertion assertion = new ResponseAssertion();
>+        assertion.setTestFieldResponseCode();
>+        assertion.setToEqualsType();
>+        assertion.addTestString("201");
>+
>+        DebugSampler debugSampler = new DebugSampler();
>+        debugSampler.addTestElement(assertion);
>+
>+        LoopController loop = new LoopController();
>+        loop.setLoops(1);
>+        loop.setContinueForever(false);
>+
>+        ListedHashTree hashTree = new ListedHashTree();
>+        hashTree.add(loop);
>+        hashTree.add(loop, transactionController);
>+        hashTree.add(transactionController, debugSampler);
>+        hashTree.add(transactionController, listener);
>+        hashTree.add(debugSampler, assertion);
>+
>+        TestCompiler compiler = new TestCompiler(hashTree);
>+        hashTree.traverse(compiler);
>+
>+        ThreadGroup threadGroup = new ThreadGroup();
>+        threadGroup.setNumThreads(1);
>+
>+        ListenerNotifier notifier = new ListenerNotifier();
>+
>+        JMeterThread thread = new JMeterThread(hashTree, threadGroup,
>notifier);
>+        thread.setThreadGroup(threadGroup);
>+        thread.setOnErrorStopThread(true);
>+        thread.run();
>+
>+        assertEquals("Must one transaction samples with parent debug
>sample", 1, listener.events.size());
>+        assertEquals("Number of samples in transaction : 1, number of
>failing samples : 1",
>listener.events.get(0).getResult().getResponseMessage());
>+    }
>+
>+
>+
>+    public class TestSampleListener extends ResultCollector implements
>SampleListener {
>+        public List<SampleEvent> events = new ArrayList<>();
>+
>+        @Override
>+        public void sampleOccurred(SampleEvent e) {
>+            events.add(e);
>+        }
>+
>+        @Override
>+        public void sampleStarted(SampleEvent e) {
>+            events.add(e);
>+        }
>+
>+        @Override
>+        public void sampleStopped(SampleEvent e) {
>+            events.add(e);
>+        }
>+    }
>+}
>
>Modified: jmeter/trunk/xdocs/changes.xml
>URL:
>http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1794861&r1=1794860&r2=1794861&view=diff
>==============================================================================
>--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
>+++ jmeter/trunk/xdocs/changes.xml [utf-8] Thu May 11 18:02:25 2017
>@@ -173,6 +173,7 @@ Summary
><li><bug>61054</bug>Endless loop in JOrphanUtils#replaceAllWithRegex
>when regex is contained in replacement</li>
><li><bug>60995</bug>HTTP Test Script Recorder: Port field is very small
>under some LAF</li>
><li><bug>61073</bug>HTTP(S) Test Script Recorder panel have some fields
>with bad size on HiDPI screen or GTK+ L&F on Linux/XWayland</li>
>+    <li><bug>57958</bug>Fix transaction sample not generated if thread
>stops/restarts. Implemented by Artem Fedorov (artem at blazemeter.com)
>and contributed by BlazeMeter Ltd.</li>
> </ul>
> 
>  <!--  =================== Thanks =================== -->