jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ago...@apache.org
Subject svn commit: r1811260 - in /jmeter/trunk: src/functions/org/apache/jmeter/functions/RandomDate.java xdocs/changes.xml
Date Thu, 05 Oct 2017 21:01:26 GMT
Author: agomes
Date: Thu Oct  5 21:01:25 2017
New Revision: 1811260

URL: http://svn.apache.org/viewvc?rev=1811260&view=rev
Log:
Bug61588 - Better log message for RandomDate function

Modified:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/RandomDate.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/RandomDate.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/RandomDate.java?rev=1811260&r1=1811259&r2=1811260&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/RandomDate.java (original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/RandomDate.java Thu Oct  5 21:01:25
2017
@@ -153,7 +153,7 @@ public class RandomDate extends Abstract
                 formatter = dateRandomFormatterCache.get(lfo, key -> createFormatter((LocaleFormatObject)
key));
             } catch (IllegalArgumentException ex) {
                 log.error(
-                        "Format date pattern '{}' is invalid (see https://docs.oracle.com/javase/8/docs/api/java
   ime/format/DateTimeFormatter.html)",
+                        "Format date pattern '{}' is invalid (see https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html)",
                         format, ex); // $NON-NLS-1$
                 return "";
             }
@@ -163,7 +163,7 @@ public class RandomDate extends Abstract
                 formatter = dateRandomFormatterCache.get(lfo, key -> createFormatter((LocaleFormatObject)
key));
             } catch (IllegalArgumentException ex) {
                 log.error(
-                        "Format date pattern '{}' is invalid (see https://docs.oracle.com/javase/8/docs/api/java
   ime/format/DateTimeFormatter.html)",
+                        "Format date pattern '{}' is invalid (see https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html)",
                         format, ex); // $NON-NLS-1$
                 return "";
             }
@@ -174,13 +174,13 @@ public class RandomDate extends Abstract
             try {
                 localStartDate = LocalDate.parse(dateStart, formatter).toEpochDay();
             } catch (DateTimeParseException | NumberFormatException ex) {
-                log.error("Failed to parse the date '{}' to shift with formatter '{}'", dateStart,
formatter, ex); // $NON-NLS-1$
+                log.error("Failed to parse Start Date '{}'", dateStart, ex); // $NON-NLS-1$
             }
         } else {
             try {
                 localStartDate = LocalDate.now(systemDefaultZoneID).toEpochDay();
             } catch (DateTimeParseException | NumberFormatException ex) {
-                log.error("Failed to parse the date '{}' to shift with formatter '{}'", dateStart,
formatter, ex); // $NON-NLS-1$
+                log.error("Failed to create current date '{}'", dateStart, ex); // $NON-NLS-1$
             }
         }
 
@@ -188,23 +188,27 @@ public class RandomDate extends Abstract
         try {
             localEndDate = LocalDate.parse(dateEnd, formatter).toEpochDay();
         } catch (DateTimeParseException | NumberFormatException ex) {
-            log.error("Failed to parse the date '{}' to shift with formatter '{}'", dateEnd,
formatter, ex); // $NON-NLS-1$
+            log.error("Failed to parse End date '{}'", dateEnd, ex); // $NON-NLS-1$
         }
 
         // Generate the random date
         String dateString = "";
-        long randomDay = ThreadLocalRandom.current().nextLong(localStartDate, localEndDate);
-        try {
-            dateString = LocalDate.ofEpochDay(randomDay).format(formatter);
-        } catch (DateTimeParseException | NumberFormatException ex) {
-            log.error("Failed to parse the date '{}' to shift with formatter '{}'", randomDay,
formatter, ex); // $NON-NLS-1$
-        }
+        if (localEndDate < localStartDate) {
+            log.error("End Date '{}' must be greater than Start Date '{}'", dateEnd, dateStart);
// $NON-NLS-1$
+        } else {
+            long randomDay = ThreadLocalRandom.current().nextLong(localStartDate, localEndDate);
+            try {
+                dateString = LocalDate.ofEpochDay(randomDay).format(formatter);
+            } catch (DateTimeParseException | NumberFormatException ex) {
+                log.error("Failed to generate random date '{}'", randomDay, ex); // $NON-NLS-1$
+            }
 
-        variableName = ((CompoundVariable) values[4]).execute().trim();
-        if (!StringUtils.isEmpty(variableName)) {
-            JMeterVariables vars = getVariables();
-            if (vars != null) {// vars will be null on TestPlan
-                vars.put(variableName, dateString);
+            variableName = ((CompoundVariable) values[4]).execute().trim();
+            if (!StringUtils.isEmpty(variableName)) {
+                JMeterVariables vars = getVariables();
+                if (vars != null) {// vars will be null on TestPlan
+                    vars.put(variableName, dateString);
+                }
             }
         }
         return dateString;

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1811260&r1=1811259&r2=1811260&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Thu Oct  5 21:01:25 2017
@@ -150,6 +150,7 @@ Summary
 
 <h3>Functions</h3>
 <ul>
+    <li><bug>61588</bug>Better log message for RandomDate function</li>
 </ul>
 
 <h3>I18N</h3>



Mime
View raw message