You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by mc...@apache.org on 2017/07/25 09:43:10 UTC
svn commit: r1802907 -
/jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeShiftFunction.java
Author: mchassagneux
Date: Tue Jul 25 09:43:10 2017
New Revision: 1802907
URL: http://svn.apache.org/viewvc?rev=1802907&view=rev
Log:
Add JUnit test
Bugzilla Id: 61335
Modified:
jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeShiftFunction.java
Modified: jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeShiftFunction.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeShiftFunction.java?rev=1802907&r1=1802906&r2=1802907&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeShiftFunction.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeShiftFunction.java Tue Jul 25 09:43:10 2017
@@ -31,6 +31,7 @@ import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.TimeZone;
+import java.util.Random;
import org.apache.jmeter.engine.util.CompoundVariable;
import org.apache.jmeter.junit.JMeterTestCase;
@@ -136,5 +137,26 @@ public class TestTimeShiftFunction exten
value = function.execute(result, null);
assertThat(value, is(equalTo("")));
}
+
+
+ @Test
+ public void testRandomPeriod() throws Exception {
+ Random r = new Random();
+ int randomInt = r.ints(1, 60).limit(1).findFirst().getAsInt();
+ vars.put("random", String.valueOf( randomInt ) );
+ Collection<CompoundVariable> params = makeParams("YYYY-MM-dd'T'HH:mm:ss", "", "PT${random}M", "");
+ function.setParameters(params);
+ value = function.execute(result, null);
+ LocalDateTime randomFutureDate = LocalDateTime.parse(value);
+ LocalDateTime checkFutureDate = LocalDateTime.now().plusMinutes(randomInt);
+ assertThat(randomFutureDate, within(5, ChronoUnit.SECONDS, checkFutureDate) );
+ randomInt = r.ints(1, 60).limit(1).findFirst().getAsInt();
+ vars.put("random", String.valueOf( randomInt ) );
+ value = function.execute(result, null);
+ randomFutureDate = LocalDateTime.parse(value);
+ checkFutureDate = LocalDateTime.now().plusMinutes(randomInt);
+ assertThat(randomFutureDate, within(5, ChronoUnit.SECONDS, checkFutureDate) );
+
+ }
}