jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1849600 - /jmeter/trunk/src/components/org/apache/jmeter/timers/poissonarrivals/ConstantPoissonProcessGenerator.java
Date Sun, 23 Dec 2018 10:36:51 GMT
Author: pmouawad
Date: Sun Dec 23 10:36:50 2018
New Revision: 1849600

URL: http://svn.apache.org/viewvc?rev=1849600&view=rev
Log:
Fix Sonar warning Equality tests should not be made with floating point values

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=1849600&r1=1849599&r2=1849600&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 Dec 23 10:36:50 2018
@@ -32,6 +32,8 @@ import org.slf4j.LoggerFactory;
 public class ConstantPoissonProcessGenerator implements EventProducer {
     private static final Logger log = LoggerFactory.getLogger(ConstantPoissonProcessGenerator.class);
 
+    private static final double PRECISION = 0.00001;
+
     private Random rnd = new Random();
     private ThroughputProvider throughputProvider;
     private int batchSize;
@@ -163,10 +165,14 @@ public class ConstantPoissonProcessGener
     @Override
     public double next() {
         if (!events.hasRemaining()
-                || throughputProvider.getThroughput() != lastThroughput) {
+                || !valuesAreEqualWithPrecision(throughputProvider.getThroughput(),lastThroughput))
{
             generateNext();
         }
         lastEvent = events.get();
         return lastEvent;
     }
+
+    private boolean valuesAreEqualWithPrecision(double throughput, double lastThroughput)
{
+        return Math.abs(throughput - lastThroughput) < PRECISION;
+    }
 }



Mime
View raw message