From commits-return-7721-apmail-jmeter-commits-archive=jmeter.apache.org@jmeter.apache.org Tue Jul 25 20:09:50 2017 Return-Path: X-Original-To: apmail-jmeter-commits-archive@minotaur.apache.org Delivered-To: apmail-jmeter-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EEF4519E1D for ; Tue, 25 Jul 2017 20:09:49 +0000 (UTC) Received: (qmail 23166 invoked by uid 500); 25 Jul 2017 20:09:49 -0000 Delivered-To: apmail-jmeter-commits-archive@jmeter.apache.org Received: (qmail 23134 invoked by uid 500); 25 Jul 2017 20:09:49 -0000 Mailing-List: contact commits-help@jmeter.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jmeter.apache.org Delivered-To: mailing list commits@jmeter.apache.org Received: (qmail 23125 invoked by uid 99); 25 Jul 2017 20:09:49 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Jul 2017 20:09:49 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id CE3CF3A0B3F for ; Tue, 25 Jul 2017 20:09:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1802992 - /jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeShift.java Date: Tue, 25 Jul 2017 20:09:46 -0000 To: commits@jmeter.apache.org From: pmouawad@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170725200948.CE3CF3A0B3F@svn01-us-west.apache.org> Author: pmouawad Date: Tue Jul 25 20:09:46 2017 New Revision: 1802992 URL: http://svn.apache.org/viewvc?rev=1802992&view=rev Log: Bug 61341 Add locale parameter to timeShift function Clarify and simplify code Bugzilla Id: 61341 Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeShift.java Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeShift.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeShift.java?rev=1802992&r1=1802991&r2=1802992&view=diff ============================================================================== --- jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeShift.java (original) +++ jmeter/trunk/src/functions/org/apache/jmeter/functions/TimeShift.java Tue Jul 25 20:09:46 2017 @@ -80,7 +80,7 @@ public class TimeShift extends AbstractF private ZoneId systemDefaultZoneID = ZoneId.systemDefault(); - class LocaleFormatObject { + private static final class LocaleFormatObject { private String format; private Locale locale; @@ -113,6 +113,14 @@ public class TimeShift extends AbstractF return format.equals(otherError.getFormat()) && locale.getDisplayName().equals(otherError.getLocale().getDisplayName()); } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "LocaleFormatObject [format=" + format + ", locale=" + locale + "]"; + } } @@ -127,7 +135,6 @@ public class TimeShift extends AbstractF /** {@inheritDoc} */ @Override public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { - String dateString; String amountToShift = amountToShiftCompound.execute().trim(); String dateToShift = dateToShiftCompound.execute().trim(); LocalDateTime localDateTimeToShift = LocalDateTime.now(systemDefaultZoneID); @@ -152,7 +159,8 @@ public class TimeShift extends AbstractF ZoneId.systemDefault()); } } catch (DateTimeParseException | NumberFormatException ex) { - log.error("Failed to parse the date '{}' to shift", dateToShift, ex); // $NON-NLS-1$ + log.error("Failed to parse the date '{}' to shift with formatter '{}'", + dateToShift, formatter, ex); // $NON-NLS-1$ } } @@ -165,7 +173,7 @@ public class TimeShift extends AbstractF log.error("Failed to parse the amount duration '{}' to shift (see https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#parse-java.lang.CharSequence-) ", amountToShift, ex); // $NON-NLS-1$ } } - + String dateString; if (formatter != null) { dateString = localDateTimeToShift.format(formatter); } else { @@ -183,7 +191,6 @@ public class TimeShift extends AbstractF } private DateTimeFormatter createFormatter(LocaleFormatObject format) { - log.debug("Create a new instance of DateTimeFormatter for format '{}' in the cache", format); return new DateTimeFormatterBuilder().appendPattern(format.getFormat()).parseDefaulting(ChronoField.NANO_OF_SECOND, 0) .parseDefaulting(ChronoField.MILLI_OF_SECOND, 0).parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0) @@ -193,12 +200,6 @@ public class TimeShift extends AbstractF } - protected static Cache buildCache() { - Caffeine cacheBuilder = Caffeine.newBuilder(); - cacheBuilder.maximumSize(100); - return cacheBuilder.build(); - } - /** {@inheritDoc} */ @Override public void setParameters(Collection parameters) throws InvalidVariableException { @@ -213,14 +214,15 @@ public class TimeShift extends AbstractF variableName = ((CompoundVariable) values[3]).execute().trim(); } else { String localeAsString = ((CompoundVariable) values[3]).execute().trim(); - if (!localeAsString.equals("")) { + if (!localeAsString.trim().isEmpty()) { locale = LocaleUtils.toLocale(localeAsString); } variableName = ((CompoundVariable) values[4]).execute().trim(); } // Create the cache if (dateTimeFormatterCache == null) { - dateTimeFormatterCache = buildCache(); + dateTimeFormatterCache = Caffeine.newBuilder() + .maximumSize(100).build(); } }