Fixed - The drainToAsync method returns an incorrect value

Signed-off-by: seakider <seakider@gmail.com>
pull/6142/head
seakider 5 months ago
parent 14d8962fd3
commit fcbb2fa08e

@ -324,10 +324,6 @@ public class RedissonBoundedBlockingQueue<V> extends RedissonQueue<V> implements
@Override
public int drainTo(Collection<? super V> c, int maxElements) {
if (maxElements <= 0) {
return 0;
}
return get(drainToAsync(c, maxElements));
}
@ -336,7 +332,10 @@ public class RedissonBoundedBlockingQueue<V> extends RedissonQueue<V> implements
if (c == null) {
throw new NullPointerException();
}
if (maxElements <= 0) {
return new CompletableFutureWrapper<>(0);
}
return commandExecutor.evalWriteAsync(getRawName(), codec, new RedisCommand<Object>("EVAL", new ListDrainToDecoder(c)),
"local elemNum = math.min(ARGV[1], redis.call('llen', KEYS[1])) - 1;" +
"local vals = redis.call('lrange', KEYS[1], 0, elemNum); " +

@ -621,6 +621,20 @@ public class RedissonBoundedBlockingQueueTest extends RedisDockerTest {
assertThat(queue.remainingCapacity()).isEqualTo(100);
Assertions.assertEquals(0, queue.size());
}
@Test
public void testDrainToAsync() throws ExecutionException, InterruptedException {
RBoundedBlockingQueue<Integer> queue = redisson.getBoundedBlockingQueue("queue");
queue.trySetCapacity(100);
for (int i = 0 ; i < 100; i++) {
assertThat(queue.offer(i)).isTrue();
}
Assertions.assertEquals(100, queue.size());
Set<Integer> batch = new HashSet<Integer>();
RFuture<Integer> future = queue.drainToAsync(batch, 0);
Assertions.assertEquals(future.get(), 0);
Assertions.assertEquals(batch.size(), 0);
}
@Test
public void testBlockingQueue() {

Loading…
Cancel
Save