You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2012/09/28 16:01:00 UTC
svn commit: r1391471 - in /jmeter/trunk:
src/functions/org/apache/jmeter/functions/TimeFunction.java
test/src/org/apache/jmeter/functions/TestTimeFunction.java
xdocs/changes.xml xdocs/usermanual/functions.xml
Author: sebb
Date: Fri Sep 28 14:00:59 2012
New Revision: 1391471
URL: http://svn.apache.org/viewvc?rev=1391471&view=rev
Log:
__time() function : add another option to __time() to provide *seconds* since epoch
Added /dddd division option
Bugzilla Id: 51527
Modified:
jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeFunction.java
jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeFunction.java
jmeter/trunk/xdocs/changes.xml
jmeter/trunk/xdocs/usermanual/functions.xml
Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeFunction.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeFunction.java?rev=1391471&r1=1391470&r2=1391471&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeFunction.java (original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeFunction.java Fri Sep 28 14:00:59 2012
@@ -85,8 +85,13 @@ public class TimeFunction extends Abstra
if (fmt == null) {
fmt = format;// Not found
}
- SimpleDateFormat df = new SimpleDateFormat(fmt);// Not synchronised, so can't be shared
- datetime = df.format(new Date());
+ if (fmt.matches("/\\d+")) { // divisor is a positive number
+ long div = Long.parseLong(fmt.substring(1)); // should never case NFE
+ datetime = Long.toString((System.currentTimeMillis() / div));
+ } else {
+ SimpleDateFormat df = new SimpleDateFormat(fmt);// Not synchronised, so can't be shared
+ datetime = df.format(new Date());
+ }
}
if (variable.length() > 0) {
Modified: jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeFunction.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeFunction.java?rev=1391471&r1=1391470&r2=1391471&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeFunction.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/functions/TestTimeFunction.java Fri Sep 28 14:00:59 2012
@@ -167,4 +167,22 @@ public class TestTimeFunction extends JM
Locale.setDefault(locale);
assertEquals("AD",value);
}
+
+ public void testDivisor() throws Exception {
+ params.add(new CompoundVariable("/1000"));
+ variable.setParameters(params);
+ long before = System.currentTimeMillis()/1000;
+ value = variable.execute(result, null);
+ long now= Long.parseLong(value);
+ long after = System.currentTimeMillis()/1000;
+ assertTrue(now >= before && now <= after);
+ }
+
+ public void testDivisorNoMatch() throws Exception {
+ params.add(new CompoundVariable("/1000 ")); // trailing space
+ variable.setParameters(params);
+ value = variable.execute(result, null);
+ assertEquals("/1000 ", value);
+ }
+
}
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1391471&r1=1391470&r2=1391471&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Fri Sep 28 14:00:59 2012
@@ -205,6 +205,7 @@ Cookie Manager has now the default HC3.1
<h3>Functions</h3>
<ul>
+<li><bugzilla>51527</bugzilla> - __time() function : add another option to __time() to provide *seconds* since epoch</li>
</ul>
<h3>I18N</h3>
Modified: jmeter/trunk/xdocs/usermanual/functions.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/functions.xml?rev=1391471&r1=1391470&r2=1391471&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jmeter/trunk/xdocs/usermanual/functions.xml Fri Sep 28 14:00:59 2012
@@ -898,12 +898,16 @@ If omitted, <b>,</b> is used. Note that
<properties>
<property name="Format" required="No">
- The format to be passed to SimpleDateFormat.
+ The format to be passed to SimpleDateFormat.
The function supports various shorthand aliases, see below.
+ If ommitted, the function returns the current time in milliseconds since the epoch.
</property>
<property name="Name of variable" required="No">The name of the variable to set.</property>
</properties>
-<p>If the format string is omitted, then the function returns the current time in milliseconds.
+<p>If the format string is omitted, then the function returns the current time in milliseconds since the epoch.
+In versions of JMeter after 2.7, if the format matches "/ddd" (where ddd are decimal digits),
+then the function returns the current time in milliseconds divided by the value of ddd.
+For example, "/1000" returns the current time in seconds since the epoch.
Otherwise, the current time is passed to SimpleDateFormat.
The following shorthand aliases are provided:
</p>