You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2018/08/22 15:25:41 UTC

svn commit: r1838646 - in /jmeter/trunk: src/core/org/apache/jmeter/timers/TimerService.java test/src/org/apache/jmeter/timers/TimerServiceTest.java xdocs/changes.xml

Author: fschumacher
Date: Wed Aug 22 15:25:41 2018
New Revision: 1838646

URL: http://svn.apache.org/viewvc?rev=1838646&view=rev
Log:
Part of 62637 Avoid Integer overrun when dealing with very large values in TimerService#adjustDelay

Bugzilla 62637

Added:
    jmeter/trunk/test/src/org/apache/jmeter/timers/TimerServiceTest.java   (with props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/timers/TimerService.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/timers/TimerService.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/timers/TimerService.java?rev=1838646&r1=1838645&r2=1838646&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/timers/TimerService.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/timers/TimerService.java Wed Aug 22 15:25:41 2018
@@ -65,7 +65,7 @@ public class TimerService {
     public long adjustDelay(final long initialDelay, long endTime) {
         if (endTime > 0) {
             long now = System.currentTimeMillis();
-            if(now + initialDelay > endTime) {
+            if (initialDelay > endTime - now) {
                 return endTime - now;
             }
         }

Added: jmeter/trunk/test/src/org/apache/jmeter/timers/TimerServiceTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/timers/TimerServiceTest.java?rev=1838646&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/timers/TimerServiceTest.java (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/timers/TimerServiceTest.java Wed Aug 22 15:25:41 2018
@@ -0,0 +1,37 @@
+/*
+ * 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.timers;
+
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TimerServiceTest {
+
+    TimerService sut = TimerService.getInstance();
+
+    @Test
+    public void testBigInitialDelay() {
+        long now = System.currentTimeMillis();
+        long adjustedDelay = sut.adjustDelay(Long.MAX_VALUE, now + 1000L);
+        // As #adjustDelay uses System#currentTimeMillis we can't be sure, that the value is exact 1000L
+        Assert.assertThat(Math.abs(adjustedDelay - 1000L) < 150L, CoreMatchers.is(true));
+    }
+
+}

Propchange: jmeter/trunk/test/src/org/apache/jmeter/timers/TimerServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1838646&r1=1838645&r2=1838646&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Wed Aug 22 15:25:41 2018
@@ -267,6 +267,7 @@ this behaviour, set <code>httpclient.res
   <li><bug>62478</bug>Escape commata in parameters when constructing function strings in the GUI function helper. Reported by blue414 (blue414 at 163.com)</li>
   <li><bug>62463</bug>Fix usage of ports, when <code>client.rmi.localport</code> is set for distributed runs.</li>
   <li><bug>62545</bug>Don't use a colon as part of the "tab" string when indenting JSON in RenderAsJSON.</li>
+  <li>Part of <bug>62637</bug> Avoid Integer overrun when dealing with very large values in <code>TimerService#adjustDelay</code></li>
 </ul>
 
  <!--  =================== Thanks =================== -->