[GitHub] jmeter issue #293: Prevent use of the same array in CollectionProperty (clos...
Github user emilianbold commented on the issue: https://github.com/apache/jmeter/pull/293 It's unclear to me why it's so important to use the same kind of collection class. So I tried to keep the patch low-impact. Instead of null or an empty list it could return a new ArrayList with the objects. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter issue #293: Prevent use of the same array in CollectionProperty (clos...
Github user FSchumacher commented on the issue: https://github.com/apache/jmeter/pull/293 Great, I wonder if we should change the return value from `null` to `Collections.emptyList()` in case of an Exception, too. I will add a test case to the bugzilla entry for `normalizeList`. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter pull request #291: Add time shifting function
Github user FSchumacher commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113539922 --- Diff: src/functions/org/apache/jmeter/functions/TimeShiftingFunction.java --- @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.jmeter.functions; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.Year; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.jmeter.engine.util.CompoundVariable; +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.samplers.Sampler; +import org.apache.jmeter.threads.JMeterVariables; +import org.apache.jmeter.util.JMeterUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * timeShifting Function permit to shift a date + * + * Parameters: - format date @see + * https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html + * (optional - defaults to epoch time in millisecond) - date to shift formated + * as first param (optional - defaults now) - amount of (seconds / minutes / + * hours / days / months ) to add (optional - default nothing is add ) - + * variable name ( optional ) + * + * Returns: - Returns a formated date with the specified number of (seconds / + * minutes / hours / days / months ) added. - value is also saved in the + * variable for later re-use. + * + * @since 3.3 + */ +public class TimeShiftingFunction extends AbstractFunction { +private static final Logger log = LoggerFactory.getLogger(TimeShiftingFunction.class); + +private static final String KEY = "__timeShifting"; // $NON-NLS-1$ + +private static final List desc = new LinkedList<>(); + +static { +desc.add(JMeterUtils.getResString("time_format_shift")); //$NON-NLS-1$ +desc.add(JMeterUtils.getResString("date_to_shift")); //$NON-NLS-1$ +desc.add(JMeterUtils.getResString("value_to_shift")); //$NON-NLS-1$ +desc.add(JMeterUtils.getResString("function_name_paropt")); //$NON-NLS-1$ +} + +// Ensure that these are set, even if no paramters are provided +private String format = ""; //$NON-NLS-1$ +private String dateToShift = ""; //$NON-NLS-1$ +private String shift = ""; //$NON-NLS-1$ +private String variable = ""; //$NON-NLS-1$ --- End diff -- What do you think of `variableName`? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter pull request #291: Add time shifting function
Github user FSchumacher commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113539229 --- Diff: test/src/org/apache/jmeter/functions/TestTimeShiftingFunction.java --- @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.jmeter.functions; + +import static org.apache.jmeter.functions.FunctionTestHelper.makeParams; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import java.util.Collection; +import java.util.LinkedList; + +import org.apache.jmeter.engine.util.CompoundVariable; +import org.apache.jmeter.junit.JMeterTestCase; +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.threads.JMeterContext; +import org.apache.jmeter.threads.JMeterContextService; +import org.apache.jmeter.threads.JMeterVariables; +import org.junit.Before; +import org.junit.Test; + +public class TestTimeShiftingFunction extends JMeterTestCase { +private Function function; + +private SampleResult result; + +private Collection params; + +private JMeterVariables vars; + +private JMeterContext jmctx = null; + +private String value; + +@Before +public void setUp() { +jmctx = JMeterContextService.getContext(); +vars = new JMeterVariables(); +jmctx.setVariables(vars); +jmctx.setPreviousResult(result); +params = new LinkedList<>(); +result = new SampleResult(); +function = new TimeShiftingFunction(); +} + +@Test +public void testDatePlusOneDay() throws Exception { +Collection params = makeParams("-dd-MM","2017-01-01","1d",""); +function.setParameters(params); +value = function.execute(result, null); +assertTrue(value.equalsIgnoreCase("2017-02-01")); +} + +@Test +public void testDatePlusOneDayInVariable() throws Exception { +Collection params = makeParams("-dd-MM","2017-01-01","1d","VAR"); +function.setParameters(params); +function.execute(result, null); +assertTrue(vars.get("VAR").equalsIgnoreCase("2017-02-01")); +} + +@Test +public void testDateLessOneDay() throws Exception { +Collection params = makeParams("-dd-MM","2017-01-01","-1d",""); +function.setParameters(params); +value = function.execute(result, null); +assertTrue(value.equalsIgnoreCase("2016-31-12")); +} + +@Test +public void testDatePlusOneHour() throws Exception { +Collection params = makeParams("HH:mm:ss","14:00:00","1H",""); +function.setParameters(params); +value = function.execute(result, null); +assertTrue(value.equalsIgnoreCase("15:00:00")); +} + +@Test +public void testDateLessOneMinute() throws Exception { +Collection params = makeParams("HH:mm:ss","14:00:00","-1m",""); +function.setParameters(params); +value = function.execute(result, null); +assertTrue(value.equalsIgnoreCase("13:59:00")); +} + +@Test +public void testDefault() throws Exception { +Collection params = makeParams("","","",""); +function.setParameters(params); +long before = Instant.now().toEpochMilli(); +value = function.execute(result, null); +long after = Instant.now().toEpochMilli(); +long now = Long.parseLong(value); +assertTrue(now >= before && now <= after); --- End diff -- If we use assertThat
[GitHub] jmeter pull request #291: Add time shifting function
Github user FSchumacher commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113539786 --- Diff: src/functions/org/apache/jmeter/functions/TimeShiftingFunction.java --- @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.jmeter.functions; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.Year; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.jmeter.engine.util.CompoundVariable; +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.samplers.Sampler; +import org.apache.jmeter.threads.JMeterVariables; +import org.apache.jmeter.util.JMeterUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * timeShifting Function permit to shift a date + * + * Parameters: - format date @see + * https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html + * (optional - defaults to epoch time in millisecond) - date to shift formated + * as first param (optional - defaults now) - amount of (seconds / minutes / + * hours / days / months ) to add (optional - default nothing is add ) - + * variable name ( optional ) + * + * Returns: - Returns a formated date with the specified number of (seconds / + * minutes / hours / days / months ) added. - value is also saved in the + * variable for later re-use. + * + * @since 3.3 + */ +public class TimeShiftingFunction extends AbstractFunction { +private static final Logger log = LoggerFactory.getLogger(TimeShiftingFunction.class); + +private static final String KEY = "__timeShifting"; // $NON-NLS-1$ + +private static final List desc = new LinkedList<>(); + +static { +desc.add(JMeterUtils.getResString("time_format_shift")); //$NON-NLS-1$ +desc.add(JMeterUtils.getResString("date_to_shift")); //$NON-NLS-1$ +desc.add(JMeterUtils.getResString("value_to_shift")); //$NON-NLS-1$ +desc.add(JMeterUtils.getResString("function_name_paropt")); //$NON-NLS-1$ +} + +// Ensure that these are set, even if no paramters are provided +private String format = ""; //$NON-NLS-1$ +private String dateToShift = ""; //$NON-NLS-1$ +private String shift = ""; //$NON-NLS-1$ --- End diff -- I would name it `amountToShift`. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter pull request #291: Add time shifting function
Github user FSchumacher commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113540245 --- Diff: src/functions/org/apache/jmeter/functions/TimeShiftingFunction.java --- @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.jmeter.functions; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.Year; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.jmeter.engine.util.CompoundVariable; +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.samplers.Sampler; +import org.apache.jmeter.threads.JMeterVariables; +import org.apache.jmeter.util.JMeterUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * timeShifting Function permit to shift a date + * + * Parameters: - format date @see + * https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html + * (optional - defaults to epoch time in millisecond) - date to shift formated + * as first param (optional - defaults now) - amount of (seconds / minutes / + * hours / days / months ) to add (optional - default nothing is add ) - + * variable name ( optional ) + * + * Returns: - Returns a formated date with the specified number of (seconds / + * minutes / hours / days / months ) added. - value is also saved in the + * variable for later re-use. + * + * @since 3.3 + */ +public class TimeShiftingFunction extends AbstractFunction { +private static final Logger log = LoggerFactory.getLogger(TimeShiftingFunction.class); + +private static final String KEY = "__timeShifting"; // $NON-NLS-1$ + +private static final List desc = new LinkedList<>(); --- End diff -- Would it be possible to use `Arrays.asList(JMeterUtils.getResString(...), ...)`? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter pull request #291: Add time shifting function
Github user FSchumacher commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113540671 --- Diff: src/functions/org/apache/jmeter/functions/TimeShiftingFunction.java --- @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.jmeter.functions; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.Year; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.jmeter.engine.util.CompoundVariable; +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.samplers.Sampler; +import org.apache.jmeter.threads.JMeterVariables; +import org.apache.jmeter.util.JMeterUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * timeShifting Function permit to shift a date + * + * Parameters: - format date @see + * https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html + * (optional - defaults to epoch time in millisecond) - date to shift formated + * as first param (optional - defaults now) - amount of (seconds / minutes / + * hours / days / months ) to add (optional - default nothing is add ) - + * variable name ( optional ) + * + * Returns: - Returns a formated date with the specified number of (seconds / --- End diff -- formated => formatted --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter pull request #291: Add time shifting function
Github user FSchumacher commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113538522 --- Diff: xdocs/usermanual/functions.xml --- @@ -1499,6 +1502,36 @@ becomes: + + + +The timeShifting function returns a date in various formats with the specified amount of seconds/minutes/hours/days/months added --- End diff -- "in various formats" => "in configured format" or "in the given format" as the function will return one value, only. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter pull request #291: Add time shifting function
Github user FSchumacher commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113540403 --- Diff: src/core/org/apache/jmeter/resources/messages.properties --- @@ -1179,6 +1180,7 @@ throughput_control_perthread_label=Per User throughput_control_title=Throughput Controller throughput_control_tplabel=Throughput time_format=Format string for SimpleDateFormat (optional) +time_format_shift=Format string for DateTimeFormatter (optional) ( defaut unix timestamp in millisecond ) --- End diff -- defaut => default --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter pull request #291: Add time shifting function
Github user FSchumacher commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113541037 --- Diff: xdocs/usermanual/functions.xml --- @@ -1499,6 +1502,36 @@ becomes: + + + +The timeShifting function returns a date in various formats with the specified amount of seconds/minutes/hours/days/months added + + + +The format to be passed to DateTimeFormatter. +If omitted, the function use milliseconds since epoch format. + + +Indicate the date with the format from first paramater to shift +If omitted, the date is set to now + + +Indicate the specified amount of seconds/minutes/hours/days/mounths to add according to this usage : + +5s for Second value +5m for Minute value +5H for Hour value +5d for Day value +5M for Month value + +To shift in the pass, you just have to indicate -5d to remove 5 days. --- End diff -- Would it be useful, to specify more complex amount of times like `5d7H` or `5 days 7 minutes`? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter pull request #291: Add time shifting function
Github user FSchumacher commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113539596 --- Diff: src/functions/org/apache/jmeter/functions/TimeShiftingFunction.java --- @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.jmeter.functions; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.Year; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.jmeter.engine.util.CompoundVariable; +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.samplers.Sampler; +import org.apache.jmeter.threads.JMeterVariables; +import org.apache.jmeter.util.JMeterUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * timeShifting Function permit to shift a date + * + * Parameters: - format date @see + * https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html + * (optional - defaults to epoch time in millisecond) - date to shift formated + * as first param (optional - defaults now) - amount of (seconds / minutes / + * hours / days / months ) to add (optional - default nothing is add ) - + * variable name ( optional ) + * + * Returns: - Returns a formated date with the specified number of (seconds / + * minutes / hours / days / months ) added. - value is also saved in the + * variable for later re-use. + * + * @since 3.3 + */ +public class TimeShiftingFunction extends AbstractFunction { +private static final Logger log = LoggerFactory.getLogger(TimeShiftingFunction.class); + +private static final String KEY = "__timeShifting"; // $NON-NLS-1$ + +private static final List desc = new LinkedList<>(); + +static { +desc.add(JMeterUtils.getResString("time_format_shift")); //$NON-NLS-1$ +desc.add(JMeterUtils.getResString("date_to_shift")); //$NON-NLS-1$ +desc.add(JMeterUtils.getResString("value_to_shift")); //$NON-NLS-1$ +desc.add(JMeterUtils.getResString("function_name_paropt")); //$NON-NLS-1$ +} + +// Ensure that these are set, even if no paramters are provided +private String format = ""; //$NON-NLS-1$ +private String dateToShift = ""; //$NON-NLS-1$ +private String shift = ""; //$NON-NLS-1$ +private String variable = ""; //$NON-NLS-1$ + +public TimeShiftingFunction() { +super(); +} + +/** {@inheritDoc} */ +@Override +public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { +String dateString; +LocalDateTime localDateTimeToShift = LocalDateTime.now(ZoneId.systemDefault()); +DateTimeFormatter formatter = null; +if (!StringUtils.isEmpty(format)) { +try { +formatter = new DateTimeFormatterBuilder().appendPattern(format) +.parseDefaulting(ChronoField.NANO_OF_SECOND, 0).parseDefaulting(ChronoField.MILLI_OF_SECOND, 0) +.parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0).parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0) +.parseDefaulting(ChronoField.HOUR_OF_DAY, 0).parseDefaulting(ChronoField.DAY_OF_MONTH, 1) +.parseDefaulting(ChronoField.MONTH_OF_YEAR, 1) +.parseDefaulting(ChronoField.YEAR_OF_ERA, Year.now().getValue()) +.toFormatter(JMeterUtils.getLocale()); +} catch (IllegalArgumentException ex) { +
[GitHub] jmeter pull request #291: Add time shifting function
Github user FSchumacher commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113536574 --- Diff: xdocs/usermanual/functions.xml --- @@ -1499,6 +1502,36 @@ becomes: + + + +The timeShifting function returns a date in various formats with the specified amount of seconds/minutes/hours/days/months added + + + +The format to be passed to DateTimeFormatter. +If omitted, the function use milliseconds since epoch format. + + +Indicate the date with the format from first paramater to shift +If omitted, the date is set to now + + +Indicate the specified amount of seconds/minutes/hours/days/mounths to add according to this usage : --- End diff -- mounths => months seconds, minutes, ... or months As a side note, in english microtypography there is no space in front of a colon, as is in french microtypography. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter pull request #291: Add time shifting function
Github user FSchumacher commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113537173 --- Diff: xdocs/usermanual/functions.xml --- @@ -1499,6 +1502,36 @@ becomes: + + + +The timeShifting function returns a date in various formats with the specified amount of seconds/minutes/hours/days/months added + + + +The format to be passed to DateTimeFormatter. +If omitted, the function use milliseconds since epoch format. --- End diff -- use => uses --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter pull request #291: Add time shifting function
Github user undera commented on a diff in the pull request: https://github.com/apache/jmeter/pull/291#discussion_r113537870 --- Diff: src/functions/org/apache/jmeter/functions/TimeShiftingFunction.java --- @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.jmeter.functions; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.Year; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.jmeter.engine.util.CompoundVariable; +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.samplers.Sampler; +import org.apache.jmeter.threads.JMeterVariables; +import org.apache.jmeter.util.JMeterUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * timeShifting Function permit to shift a date + * + * Parameters: - format date @see + * https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html + * (optional - defaults to epoch time in millisecond) - date to shift formated + * as first param (optional - defaults now) - amount of (seconds / minutes / + * hours / days / months ) to add (optional - default nothing is add ) - + * variable name ( optional ) + * + * Returns: - Returns a formated date with the specified number of (seconds / + * minutes / hours / days / months ) added. - value is also saved in the + * variable for later re-use. + * + * @since 3.3 + */ +public class TimeShiftingFunction extends AbstractFunction { +private static final Logger log = LoggerFactory.getLogger(TimeShiftingFunction.class); + +private static final String KEY = "__timeShifting"; // $NON-NLS-1$ --- End diff -- "timeShifting" is unusual style for function name. Usually functions are called like "__timeShift", without continuous tense --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter issue #293: Prevent use of the same array in CollectionProperty (clos...
Github user emilianbold commented on the issue: https://github.com/apache/jmeter/pull/293 Done. The new patch is much cleaner. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter issue #293: Prevent use of the same array in CollectionProperty (clos...
Github user emilianbold commented on the issue: https://github.com/apache/jmeter/pull/293 Ammeding the commit as we speak. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter issue #293: Prevent use of the same array in CollectionProperty (clos...
Github user pmouawad commented on the issue: https://github.com/apache/jmeter/pull/293 @FSchumacher , I agree. Let's commit the patch without the new method. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter issue #293: Prevent use of the same array in CollectionProperty (clos...
Github user FSchumacher commented on the issue: https://github.com/apache/jmeter/pull/293 As Emilan suggested, we could change normalizeList to always create a new collection, instead of introducing a new method, that has configurable behaviour. I consider the current behaviour to be a bug. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter issue #291: Add time shifting function
Github user pmouawad commented on the issue: https://github.com/apache/jmeter/pull/291 Thanks for the changes. Looks good to me for commit. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter issue #292: Display the result of the function when generate it
Github user pmouawad commented on the issue: https://github.com/apache/jmeter/pull/292 Hi @max3163 , Interesting idea. Does your implementation handle all functions ? Thanks --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter issue #293: Prevent use of the same array in CollectionProperty (clos...
Github user pmouawad commented on the issue: https://github.com/apache/jmeter/pull/293 Thanks for analysis and patch. It was a hard one !. @FSchumacher , I don't understand your comment , what exactly do you want to change ? Thanks --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter issue #293: Prevent use of the same array in CollectionProperty (clos...
Github user FSchumacher commented on the issue: https://github.com/apache/jmeter/pull/293 Great. Thanks for your analysis and your fix. I tend to change the behaviour of normalizeList, even if it is a change in the unwritten contract. The current behaviour seems wrong to me. It was probably meant to save space. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
Re: [GitHub] jmeter pull request #293: Prevent use of the same array in CollectionPropert...
I'm also on the mailing list if somebody has anything to remark about this patch. --emi On Wed, Apr 26, 2017 at 6:04 PM, emilianboldwrote: > GitHub user emilianbold opened a pull request: > > https://github.com/apache/jmeter/pull/293 > > Prevent use of the same array in CollectionProperty (close #58743) > > CollectionProperty constructor receives an empty ObjectTableModel.objects > collection but normalizeList will return it as-is instead of creating a > new empty collection. > > The two classes share the same array but add different kind of classes. > > NOTE: Basically the bug is in AbstractProperty.normalizeList because it > should never reuse the same instance. I've done the patch as you see it > because it has the lowest impact and does not change the normalizeList API > (perhaps reusing is expected in some cases?) > > Let me know if I should redo the patch by just changing normalizeList! > > Constructor stacktrace: > at > org.apache.jmeter.testelement.property.CollectionProperty.(CollectionProperty.java:40) > at > org.apache.jmeter.testelement.property.AbstractProperty.makeProperty(AbstractProperty.java:395) > at > org.apache.jmeter.testelement.property.AbstractProperty.createProperty(AbstractProperty.java:368) > at > org.apache.jmeter.testbeans.gui.TestBeanGUI.setPropertyInElement(TestBeanGUI.java:277) > at > org.apache.jmeter.testbeans.gui.TestBeanGUI.modifyTestElement(TestBeanGUI.java:266) > at > org.apache.jmeter.gui.tree.JMeterTreeModel.addComponent(JMeterTreeModel.java:148) > at org.apache.jmeter.gui.action.AddToTree.doAction(AddToTree.java:70) > at > org.apache.jmeter.gui.action.ActionRouter.performAction(ActionRouter.java:74) > at > org.apache.jmeter.gui.action.ActionRouter.lambda$actionPerformed$28(ActionRouter.java:59) > at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) > > > You can merge this pull request into a Git repository by running: > > $ git pull https://github.com/emilianbold/jmeter trunk > > Alternatively you can review and apply these changes as the patch at: > > https://github.com/apache/jmeter/pull/293.patch > > To close this pull request, make a commit to your master/trunk branch > with (at least) the following in the commit message: > > This closes #293 > > > commit 2b829035f144c49e565d99ed0ca8f83ba6f85cf4 > Author: Emilian Bold > Date: 2017-04-26T14:57:58Z > > Prevent use of the same array in CollectionProperty (close #58743) > > CollectionProperty constructor receives an empty ObjectTableModel.objects > collection but normalizeList will return it as-is instead of creating a > new empty collection. > > The two classes share the same array but add different kind of classes. > > > > > --- > If your project is set up for it, you can reply to this email and have your > reply appear on GitHub as well. If your project does not have this feature > enabled and wishes so, or if the feature is enabled but not working, please > contact infrastructure at infrastruct...@apache.org or file a JIRA ticket > with INFRA. > ---
[GitHub] jmeter pull request #293: Prevent use of the same array in CollectionPropert...
GitHub user emilianbold opened a pull request: https://github.com/apache/jmeter/pull/293 Prevent use of the same array in CollectionProperty (close #58743) CollectionProperty constructor receives an empty ObjectTableModel.objects collection but normalizeList will return it as-is instead of creating a new empty collection. The two classes share the same array but add different kind of classes. NOTE: Basically the bug is in AbstractProperty.normalizeList because it should never reuse the same instance. I've done the patch as you see it because it has the lowest impact and does not change the normalizeList API (perhaps reusing is expected in some cases?) Let me know if I should redo the patch by just changing normalizeList! Constructor stacktrace: at org.apache.jmeter.testelement.property.CollectionProperty.(CollectionProperty.java:40) at org.apache.jmeter.testelement.property.AbstractProperty.makeProperty(AbstractProperty.java:395) at org.apache.jmeter.testelement.property.AbstractProperty.createProperty(AbstractProperty.java:368) at org.apache.jmeter.testbeans.gui.TestBeanGUI.setPropertyInElement(TestBeanGUI.java:277) at org.apache.jmeter.testbeans.gui.TestBeanGUI.modifyTestElement(TestBeanGUI.java:266) at org.apache.jmeter.gui.tree.JMeterTreeModel.addComponent(JMeterTreeModel.java:148) at org.apache.jmeter.gui.action.AddToTree.doAction(AddToTree.java:70) at org.apache.jmeter.gui.action.ActionRouter.performAction(ActionRouter.java:74) at org.apache.jmeter.gui.action.ActionRouter.lambda$actionPerformed$28(ActionRouter.java:59) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) You can merge this pull request into a Git repository by running: $ git pull https://github.com/emilianbold/jmeter trunk Alternatively you can review and apply these changes as the patch at: https://github.com/apache/jmeter/pull/293.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #293 commit 2b829035f144c49e565d99ed0ca8f83ba6f85cf4 Author: Emilian BoldDate: 2017-04-26T14:57:58Z Prevent use of the same array in CollectionProperty (close #58743) CollectionProperty constructor receives an empty ObjectTableModel.objects collection but normalizeList will return it as-is instead of creating a new empty collection. The two classes share the same array but add different kind of classes. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] jmeter pull request #292: Display the result of the function when generate i...
GitHub user max3163 opened a pull request: https://github.com/apache/jmeter/pull/292 Display the result of the function when generate it A little modification to display the result of a generated function in the function helper panel. You can merge this pull request into a Git repository by running: $ git pull https://github.com/max3163/jmeter displayResultFunction Alternatively you can review and apply these changes as the patch at: https://github.com/apache/jmeter/pull/292.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #292 commit f785e725313b727b1a30cae7c8c89a727019653e Author: Chassagneux Maxime <4163...@airfrance.fr> Date: 2017-04-26T08:22:24Z Display the result of the function when generate it --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---