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 2019/09/07 13:25:08 UTC

[jmeter] branch master updated (340763e -> f2c5260)

This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git.


    from 340763e  Really use the range of port
     new 3f78a23  Add more log messages about the delays
     new f2c5260  Revert behaviour of TimerService#adjustDelay to that of 5.1.1

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/jmeter/sampler/TestAction.java | 23 +++++++----
 .../org/apache/jmeter/timers/TimerServiceTest.java | 33 +++++++++++++++-
 .../org/apache/jmeter/threads/JMeterThread.java    |  3 +-
 .../org/apache/jmeter/timers/TimerService.java     | 46 +++++++++++++++++++---
 4 files changed, 89 insertions(+), 16 deletions(-)


[jmeter] 02/02: Revert behaviour of TimerService#adjustDelay to that of 5.1.1

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit f2c5260abe7a3e1022793474c0a1e322dd0a2010
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Sat Sep 7 15:20:24 2019 +0200

    Revert behaviour of TimerService#adjustDelay to that of 5.1.1
    
    Changing the adjustDelay method to return -1 when the delay would be longer
    than the remaining scheduled duration, lead to bug 63711.
    
    This change reverts the default adjustDelay to the old behaviour and adds a
    flag to enable the "new" feature of returning -1 when the sleep time would
    be too long.
    
    Bugzilla Id: 63711
---
 .../org/apache/jmeter/timers/TimerServiceTest.java | 33 +++++++++++++++-
 .../org/apache/jmeter/threads/JMeterThread.java    |  3 +-
 .../org/apache/jmeter/timers/TimerService.java     | 46 +++++++++++++++++++---
 3 files changed, 74 insertions(+), 8 deletions(-)

diff --git a/src/components/src/test/java/org/apache/jmeter/timers/TimerServiceTest.java b/src/components/src/test/java/org/apache/jmeter/timers/TimerServiceTest.java
index 428efd2..0c46662 100644
--- a/src/components/src/test/java/org/apache/jmeter/timers/TimerServiceTest.java
+++ b/src/components/src/test/java/org/apache/jmeter/timers/TimerServiceTest.java
@@ -18,7 +18,9 @@
 
 package org.apache.jmeter.timers;
 
+import org.hamcrest.BaseMatcher;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.Description;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -27,14 +29,41 @@ public class TimerServiceTest {
     TimerService sut = TimerService.getInstance();
 
     @Test
-    public void testBigInitialDelay() {
+    public void testBigInitialDelayAndDontWait() {
         long now = System.currentTimeMillis();
-        long adjustedDelay = sut.adjustDelay(Long.MAX_VALUE, now + 1000L);
+        long adjustedDelay = sut.adjustDelay(Long.MAX_VALUE, now + 1000L, false);
         Assert.assertThat("TimerService should return -1 as delay would lead to a time after end time",
                 Long.valueOf(adjustedDelay), CoreMatchers.is(Long.valueOf(-1)));
     }
 
     @Test
+    public void testBigInitialDelayAndWait() {
+        long now = System.currentTimeMillis();
+        long adjustedDelay = sut.adjustDelay(Long.MAX_VALUE, now + 1000L);
+        Assert.assertThat("TimerService should return -1 as delay would lead to a time after end time",
+                Long.valueOf(adjustedDelay), isAlmost(1000L, 200L));
+    }
+
+    private BaseMatcher<Long> isAlmost(long value, long precision) {
+        return new BaseMatcher<Long>() {
+
+            @Override
+            public boolean matches(Object item) {
+                if (item instanceof Long) {
+                    Long other = (Long) item;
+                    return Math.abs(other.longValue() - value) < precision;
+                }
+                return false;
+            }
+
+            @Override
+            public void describeTo(Description description) {
+                description.appendText("the number is within a precision of " + precision + " near " + value);
+            }
+      };
+    }
+
+    @Test
     public void testSmallInitialDelay() {
         long now = System.currentTimeMillis();
         Assert.assertThat("TimerService should not change the delay as the end time is far away",
diff --git a/src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java b/src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java
index 258c901..6fc1194 100644
--- a/src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java
+++ b/src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java
@@ -494,6 +494,7 @@ public class JMeterThread implements Runnable, Interruptible {
                 // checks the scheduler to stop the iteration
                 stopSchedulerIfNeeded();
             }
+
         } catch (JMeterStopTestException e) { // NOSONAR
             if (log.isInfoEnabled()) {
                 log.info("Stopping Test: {}", e.toString());
@@ -969,7 +970,7 @@ public class JMeterThread implements Runnable, Interruptible {
                 if (scheduler) {
                     // We reduce pause to ensure end of test is not delayed by a sleep ending after test scheduled end
                     // See Bug 60049
-                    totalDelay = TIMER_SERVICE.adjustDelay(totalDelay, endTime);
+                    totalDelay = TIMER_SERVICE.adjustDelay(totalDelay, endTime, false);
                     if (totalDelay < 0) {
                         log.debug("The delay would be longer than the scheduled period, so stop thread now.");
                         running = false;
diff --git a/src/core/src/main/java/org/apache/jmeter/timers/TimerService.java b/src/core/src/main/java/org/apache/jmeter/timers/TimerService.java
index 2fec09e..1b54571 100644
--- a/src/core/src/main/java/org/apache/jmeter/timers/TimerService.java
+++ b/src/core/src/main/java/org/apache/jmeter/timers/TimerService.java
@@ -47,28 +47,64 @@ public class TimerService {
 
     /**
      * Adjust delay so that initialDelay does not exceed end of test
-     * @param initialDelay initial delay in millis
+     * @param initialDelay initial delay in milliseconds
      * @return initialDelay or adjusted delay
      */
     public long adjustDelay(final long initialDelay) {
+        return adjustDelay(initialDelay, true);
+    }
+
+    /**
+     * Adjust delay so that initialDelay does not exceed end of test<br>
+     * If {@code runTillEnd} is {@code false} the delay will be shortened
+     * to {@code -1} if the delay would be longer than the remaining run time.
+     *
+     * @param initialDelay initial delay in milliseconds
+     * @param runTillEnd adjust delay to match the scheduled end
+     * @return initialDelay or adjusted delay
+     */
+    public long adjustDelay(final long initialDelay, boolean runTillEnd) {
         JMeterThread thread = JMeterContextService.getContext().getThread();
         long endTime = thread != null ? thread.getEndTime() : 0;
-        return adjustDelay(initialDelay, endTime);
+        return adjustDelay(initialDelay, endTime, runTillEnd);
     }
 
+
     /**
-     * Adjust delay so that initialDelay does not exceed end of test
-     * @param initialDelay initial delay in millis
+     * Adjust delay so that initialDelay does not exceed end of test<
+     *
+     * @param initialDelay initial delay in milliseconds
      * @param endTime End time of JMeterThread
-     * @return initialDelay or {@code -1} if delay is too long
+     * @return initialDelay or a shortened delay if delay is longer than the test is
+     *         scheduled
      */
     public long adjustDelay(final long initialDelay, long endTime) {
+        return adjustDelay(initialDelay, endTime, true);
+    }
+
+    /**
+     * Adjust delay so that initialDelay does not exceed end of test<br>
+     * If {@code runTillEnd} is {@code false} the delay will be shortened
+     * to {@code -1} if the delay would be longer than the remaining run time.
+     *
+     * @param initialDelay initial delay in milliseconds
+     * @param endTime End time of JMeterThread
+     * @param runTillEnd adjust delay to match the scheduled end
+     * @return initialDelay or a shortened delay if delay is longer than the test is
+     *         scheduled
+     */
+    public long adjustDelay(final long initialDelay, long endTime, boolean runTillEnd) {
         if (endTime > 0) {
             long now = System.currentTimeMillis();
             if (initialDelay > endTime - now) {
+                if (runTillEnd) {
+                    // shorten the delay to match endTime
+                    return endTime - now;
+                }
                 return -1;
             }
         }
         return initialDelay;
     }
+
 }


[jmeter] 01/02: Add more log messages about the delays

Posted by fs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 3f78a23e4f91e17dde1c3cac86f60b828de36b05
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Sat Sep 7 15:09:58 2019 +0200

    Add more log messages about the delays
    
    while on the bug 63711 it helped me to debug the error and I think it can be of
    value for others, too. While at it a typo was fixed (looop -> loop) and a bit of
    whitespace was added.
    
    Bugzilla Id: 63711
---
 .../java/org/apache/jmeter/sampler/TestAction.java | 23 ++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/components/src/main/java/org/apache/jmeter/sampler/TestAction.java b/src/components/src/main/java/org/apache/jmeter/sampler/TestAction.java
index c6d5d2b..210a2f9 100644
--- a/src/components/src/main/java/org/apache/jmeter/sampler/TestAction.java
+++ b/src/components/src/main/java/org/apache/jmeter/sampler/TestAction.java
@@ -69,7 +69,7 @@ public class TestAction extends AbstractSampler implements Interruptible {
      */
     public static final int START_NEXT_ITERATION_CURRENT_LOOP = 4;
     /**
-     * Break Current Looop
+     * Break Current Loop
      */
     public static final int BREAK_CURRENT_LOOP = 5;
 
@@ -143,11 +143,11 @@ public class TestAction extends AbstractSampler implements Interruptible {
     private void pause(String timeInMillis) {
         long millis;
         try {
-            if(!StringUtils.isEmpty(timeInMillis)) {
-                millis=Long.parseLong(timeInMillis);
+            if (!StringUtils.isEmpty(timeInMillis)) {
+                millis = Long.parseLong(timeInMillis);
             } else {
                 log.warn("Duration value is empty, defaulting to 0");
-                millis=0L;
+                millis = 0L;
             }
         } catch (NumberFormatException e){
             log.warn("Could not parse number: '{}'", timeInMillis);
@@ -155,12 +155,19 @@ public class TestAction extends AbstractSampler implements Interruptible {
         }
         try {
             pauseThread = Thread.currentThread();
-            if(millis>0) {
-                TimeUnit.MILLISECONDS.sleep(TIMER_SERVICE.adjustDelay(millis));
-            } else if(millis<0) {
-                throw new IllegalArgumentException("Configured sleep is negative:"+millis);
+            if (millis > 0) {
+                long adjustDelay = TIMER_SERVICE.adjustDelay(millis);
+                if (log.isDebugEnabled()) {
+                    log.debug("Sleeping in Flow Control Action for {} ms (asked for {} ms)",
+                            Long.valueOf(adjustDelay),
+                            Long.valueOf(millis));
+                }
+                TimeUnit.MILLISECONDS.sleep(adjustDelay);
+            } else if (millis < 0) {
+                throw new IllegalArgumentException("Configured sleep is negative:" + millis);
             } // else == 0 we do nothing
         } catch (InterruptedException e) {
+            log.debug("Flow Control Action got interrupted");
             Thread.currentThread().interrupt();
         } finally {
             pauseThread = null;