From 74f243cc4d9ec46f041e765148bdcb8be5af8b10 Mon Sep 17 00:00:00 2001 From: Francesco Nigro Date: Tue, 1 Aug 2017 14:52:07 +0200 Subject: [PATCH] ARTEMIS-1312 TimedBuffer doubled timeout with blocking flush --- .../apache/activemq/artemis/core/io/buffer/TimedBuffer.java | 2 +- .../artemis/tests/unit/core/journal/impl/TimedBufferTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java index b74ada40d9..6ed3e7b36c 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java @@ -395,7 +395,7 @@ public final class TimedBuffer { } //it could wait until the timeout is expired final long timeFromTheLastFlush = System.nanoTime() - lastFlushTime; - final long timeToSleep = timeFromTheLastFlush - timeout; + final long timeToSleep = timeout - timeFromTheLastFlush; if (timeToSleep > 0) { sleepIfPossible(timeToSleep); } diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/TimedBufferTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/TimedBufferTest.java index 0e7f7c2029..3cb8d2e98f 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/TimedBufferTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/TimedBufferTest.java @@ -385,7 +385,7 @@ public class TimedBufferTest extends ActiveMQTestBase { @Test public void timeoutShouldMatchFlushIOPSWithNotBlockingFlush() { //use a large timeout in order to be reactive - final long timeout = TimeUnit.SECONDS.toNanos(2); + final long timeout = TimeUnit.MILLISECONDS.toNanos(100); assert ((int) timeout) > 0; //it is optimistic: the timeout and the blockingDeviceFlushTime are a perfect match final long deviceTime = timeout; @@ -426,7 +426,7 @@ public class TimedBufferTest extends ActiveMQTestBase { @Test public void timeoutShouldMatchFlushIOPSWithBlockingFlush() { //use a large timeout in order to be reactive - final long timeout = TimeUnit.SECONDS.toNanos(2); + final long timeout = TimeUnit.MILLISECONDS.toNanos(100); assert ((int) timeout) > 0; //it is optimistic: the timeout and the blockingDeviceFlushTime are a perfect match final long deviceTime = timeout;