jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1769429 - in /jmeter/trunk: src/core/org/apache/jmeter/threads/ThreadGroup.java xdocs/changes.xml
Date Sat, 12 Nov 2016 21:26:36 GMT
Author: pmouawad
Date: Sat Nov 12 21:26:36 2016
New Revision: 1769429

URL: http://svn.apache.org/viewvc?rev=1769429&view=rev
Log:
Bug 60299 - Thread Group with Scheduler : Weird behaviour when End-Time is in the past 
Bugzilla Id: 60299

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

Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/ThreadGroup.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/ThreadGroup.java?rev=1769429&r1=1769428&r2=1769429&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/ThreadGroup.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/ThreadGroup.java Sat Nov 12 21:26:36 2016
@@ -18,6 +18,8 @@
 
 package org.apache.jmeter.threads;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
@@ -31,6 +33,7 @@ import org.apache.jmeter.testelement.pro
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.collections.ListedHashTree;
 import org.apache.jorphan.logging.LoggingManager;
+import org.apache.jorphan.util.JMeterStopTestException;
 import org.apache.log.Logger;
 
 /**
@@ -42,6 +45,8 @@ public class ThreadGroup extends Abstrac
     private static final long serialVersionUID = 280L;
 
     private static final Logger log = LoggingManager.getLoggerForClass();
+    
+    private static final String DATE_FIELD_FORMAT = "yyyy/MM/dd HH:mm:ss"; //$NON-NLS-1$
 
     private static final long WAIT_TO_DIE = JMeterUtils.getPropDefault("jmeterengine.threadstop.wait",
5 * 1000); // 5 seconds
 
@@ -218,6 +223,7 @@ public class ThreadGroup extends Abstrac
      * @param thread JMeterThread
      */
     private void scheduleThread(JMeterThread thread, long now) {
+
         // if true the Scheduler is enabled
         if (getScheduler()) {
             // set the start time for the Thread
@@ -227,7 +233,7 @@ public class ThreadGroup extends Abstrac
                 long start = getStartTime();
                 if (start < now) {
                     start = now; // Force a sensible start time
-                }
+                }                
                 thread.setStartTime(start);
             }
 
@@ -235,6 +241,12 @@ public class ThreadGroup extends Abstrac
             if (getDuration() > 0) {// Duration is in seconds
                 thread.setEndTime(getDuration() * 1000 + (thread.getStartTime()));
             } else {
+                if( getEndTime() <= now ) {
+                    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FIELD_FORMAT);
+                    throw new JMeterStopTestException("End Time ("
+                            + sdf.format(new Date(getEndTime()))+") of Scheduler for Thread
Group "+getName() 
+                            + " is in the past, fix value of End Time field");
+                }
                 thread.setEndTime(getEndTime());
             }
 
@@ -533,49 +545,59 @@ public class ThreadGroup extends Abstrac
         
         @Override
         public void run() {
-            // Copy in ThreadStarter thread context from calling Thread
-            JMeterContextService.getContext().setVariables(this.context.getVariables());
-            long now = System.currentTimeMillis(); // needs to be constant for all threads
-            long endtime = 0;
-            final boolean usingScheduler = getScheduler();
-            if (usingScheduler) {
-                // set the start time for the Thread
-                if (getDelay() > 0) {// Duration is in seconds
-                    delayBy(getDelay() * 1000);
-                } else {
-                    long start = getStartTime();
-                    if (start >= now) {
-                        delayBy(start-now);
-                    } 
-                    // else start immediately
-                }
-                // set the endtime for the Thread
-                endtime = getDuration();
-                if (endtime > 0) {// Duration is in seconds, starting from when the threads
start
-                    endtime = endtime *1000 + System.currentTimeMillis();
-                } else {
-                    endtime = getEndTime();
-                }
-            }
-            final int numThreads = getNumThreads();
-            final int perThreadDelayInMillis = Math.round(((float) (getRampUp() * 1000) /
(float) numThreads));
-            for (int i = 0; running && i < numThreads; i++) {
-                if (i > 0) {
-                    pause(perThreadDelayInMillis); // ramp-up delay (except first)
-                }
-                if (usingScheduler && System.currentTimeMillis() > endtime) {
-                    break; // no point continuing beyond the end time
-                }
-                JMeterThread jmThread = makeThread(groupCount, notifier, threadGroupTree,
engine, i, context);
-                jmThread.setInitialDelay(0);   // Already waited
+            try {
+                // Copy in ThreadStarter thread context from calling Thread
+                JMeterContextService.getContext().setVariables(this.context.getVariables());
+                long now = System.currentTimeMillis(); // needs to be constant for all threads
+                long endtime = 0;
+                final boolean usingScheduler = getScheduler();
                 if (usingScheduler) {
-                    jmThread.setScheduled(true);
-                    jmThread.setEndTime(endtime);
+                    // set the start time for the Thread
+                    if (getDelay() > 0) {// Duration is in seconds
+                        delayBy(getDelay() * 1000);
+                    } else {
+                        long start = getStartTime();
+                        if (start >= now) {
+                            delayBy(start-now);
+                        } 
+                        // else start immediately
+                    }
+                    // set the endtime for the Thread
+                    endtime = getDuration();
+                    if (endtime > 0) {// Duration is in seconds, starting from when the
threads start
+                        endtime = endtime *1000 + System.currentTimeMillis();
+                    } else {
+                        if( getEndTime() <= now ) {
+                            SimpleDateFormat sdf = new SimpleDateFormat(DATE_FIELD_FORMAT);
+                            throw new JMeterStopTestException("End Time ("
+                                    + sdf.format(new Date(getEndTime()))+") of Scheduler
for Thread Group "+getName() 
+                                    + " is in the past, fix value of End Time field");
+                        }
+                        endtime = getEndTime();
+                    }
                 }
-                Thread newThread = new Thread(jmThread, jmThread.getThreadName());
-                newThread.setDaemon(false); // ThreadStarter is daemon, but we don't want
sampler threads to be so too
-                registerStartedThread(jmThread, newThread);
-                newThread.start();
+                final int numThreads = getNumThreads();
+                final int perThreadDelayInMillis = Math.round(((float) (getRampUp() * 1000)
/ (float) numThreads));
+                for (int i = 0; running && i < numThreads; i++) {
+                    if (i > 0) {
+                        pause(perThreadDelayInMillis); // ramp-up delay (except first)
+                    }
+                    if (usingScheduler && System.currentTimeMillis() > endtime)
{
+                        break; // no point continuing beyond the end time
+                    }
+                    JMeterThread jmThread = makeThread(groupCount, notifier, threadGroupTree,
engine, i, context);
+                    jmThread.setInitialDelay(0);   // Already waited
+                    if (usingScheduler) {
+                        jmThread.setScheduled(true);
+                        jmThread.setEndTime(endtime);
+                    }
+                    Thread newThread = new Thread(jmThread, jmThread.getThreadName());
+                    newThread.setDaemon(false); // ThreadStarter is daemon, but we don't
want sampler threads to be so too
+                    registerStartedThread(jmThread, newThread);
+                    newThread.start();
+                }
+            } catch (Exception ex) {
+                log.error("An error occured scheduling delay start of threads for Thread
Group:"+getName(), ex);
             }
         }
     }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1769429&r1=1769428&r2=1769429&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Nov 12 21:26:36 2016
@@ -362,6 +362,7 @@ This allows you to update Think Times fr
     <li><bug>59439</bug>Report / Dashboard : AbstractOverTimeGraphConsumer.createGroupInfos()
should be abstract</li>
     <li><bug>59918</bug>Ant generated HTML report is broken (extras folder)</li>
     <li><bug>60295</bug>JSON Extractor doesn't index array elements when
only one element is found. Based on a patch by Roberto Braga (roberto.braga at sociale.it)</li>
+    <li><bug>60299</bug>Thread Group with Scheduler : Weird behaviour when
End-Time is in the past</li>
 </ul>
 
  <!--  =================== Thanks =================== -->



Mime
View raw message