From 73818fb3aeec3f21b2581001196cd4c2a2f3885a Mon Sep 17 00:00:00 2001 From: lukaskabc Date: Thu, 12 Sep 2024 13:26:29 +0200 Subject: [PATCH] [Performance #285] fix faulty test and ensure that the task is null after transferring out of throttled future --- .../cz/cvut/kbss/termit/util/throttle/ThrottledFuture.java | 1 + .../cvut/kbss/termit/util/throttle/ThrottledFutureTest.java | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/termit/util/throttle/ThrottledFuture.java b/src/main/java/cz/cvut/kbss/termit/util/throttle/ThrottledFuture.java index b3f5c76f..35947b40 100644 --- a/src/main/java/cz/cvut/kbss/termit/util/throttle/ThrottledFuture.java +++ b/src/main/java/cz/cvut/kbss/termit/util/throttle/ThrottledFuture.java @@ -148,6 +148,7 @@ protected ThrottledFuture update(Supplier task, @NonNull List> /** * Returns future with the task from the specified {@code throttledFuture}. * If possible, transfers the task from this object to the specified {@code throttledFuture}. + * If the task was successfully transferred, this future is canceled. * * @param target the future to update * @return target when current future is already being executed, was canceled or completed. diff --git a/src/test/java/cz/cvut/kbss/termit/util/throttle/ThrottledFutureTest.java b/src/test/java/cz/cvut/kbss/termit/util/throttle/ThrottledFutureTest.java index ff4f66f7..29c7f84c 100644 --- a/src/test/java/cz/cvut/kbss/termit/util/throttle/ThrottledFutureTest.java +++ b/src/test/java/cz/cvut/kbss/termit/util/throttle/ThrottledFutureTest.java @@ -281,8 +281,9 @@ void transferUpdatesSecondFutureWithTask() { verify(secondFuture).update(eq(firstTask), anyList()); // now verifies that the task in the first future is null - firstFuture.transfer(secondFuture); - verify(secondFuture).update(isNull(), anyList()); + Object task = ReflectionTestUtils.getField(firstFuture, "task"); + assertNull(task); + assertTrue(firstFuture.isCancelled()); } @Test