Author: pmouawad
Date: Sun Jan  7 18:30:44 2018
New Revision: 1820475

URL: http://svn.apache.org/viewvc?rev=1820475&view=rev
Log:
Bug 61931 New Component : Precise Throughput Timer, timer that produces poisson 
arrivals with given constant throughput
Fix sonar warnings
Contributed by Graham Russell
This closes #370
Bugzilla Id: 61931

Modified:
    
jmeter/trunk/src/components/org/apache/jmeter/timers/poissonarrivals/ConstantPoissonProcessGenerator.java

Modified: 
jmeter/trunk/src/components/org/apache/jmeter/timers/poissonarrivals/ConstantPoissonProcessGenerator.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/timers/poissonarrivals/ConstantPoissonProcessGenerator.java?rev=1820475&r1=1820474&r2=1820475&view=diff
==============================================================================
--- 
jmeter/trunk/src/components/org/apache/jmeter/timers/poissonarrivals/ConstantPoissonProcessGenerator.java
 (original)
+++ 
jmeter/trunk/src/components/org/apache/jmeter/timers/poissonarrivals/ConstantPoissonProcessGenerator.java
 Sun Jan  7 18:30:44 2018
@@ -94,12 +94,14 @@ public class ConstantPoissonProcessGener
                 log.info("Duration should exceed 5 seconds");
                 break;
             }
-            for (i = 0; time < duration; i++) {
+            i = 0;
+            while (time < duration) {
                 double u = rnd.nextDouble();
                 // 
https://en.wikipedia.org/wiki/Exponential_distribution#Generating_exponential_variates
                 double delay = -Math.log(1 - u) / throughput;
                 time += delay;
                 events.put(time + lastEvent);
+                i++;
             }
             loops++;
         } while (System.currentTimeMillis() - t < 5000 &&
@@ -115,15 +117,18 @@ public class ConstantPoissonProcessGener
                 log.debug("Generated {} events ({} required, rate {}) in {} 
ms, restart was issued {} times",
                         events.position(), samples, throughput, t, loops);
             }
-            if(log.isInfoEnabled()) {
+            if (log.isInfoEnabled()) {
                 StringBuilder sb = new StringBuilder();
                 sb.append("Generated ").append(events.position()).append(" 
timings (");
                 if (this.durationProvider instanceof AbstractTestElement) {
                     sb.append(((AbstractTestElement) 
this.durationProvider).getName());
                 }
-                sb.append(" ").append(samples).append(" required, rate 
").append(throughput).append(", duration ").append(duration);
-                sb.append(", exact lim ").append(exactLimit).append(", 
i").append(i);
-                sb.append(") in ").append(t).append(" ms, restart was issued 
").append(loops).append(" times. ");
+                sb.append(" ").append(samples).append(" required, rate 
").append(throughput)
+                        .append(", duration ").append(duration)
+                        .append(", exact lim ").append(exactLimit)
+                        .append(", i").append(i)
+                        .append(") in ").append(t)
+                        .append(" ms, restart was issued 
").append(loops).append(" times. ");
                 sb.append("First 15 events will be fired at: ");
                 double prev = 0;
                 for (i = 0; i < events.position() && i < 15; i++) {
@@ -157,7 +162,8 @@ public class ConstantPoissonProcessGener
 
     @Override
     public double next() {
-        if (!events.hasRemaining() || throughputProvider.getThroughput() != 
lastThroughput) {
+        if (!events.hasRemaining()
+                || throughputProvider.getThroughput() != lastThroughput) {
             generateNext();
         }
         lastEvent = events.get();


Reply via email to