Fixed - RSemaphore.addPermits() method doesn't work #3038

pull/3048/head
Nikita Koksharov 4 years ago
parent 0a30cd7655
commit 64ee853db3

@ -497,10 +497,12 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
return addPermitsAsync(-permits);
}
@Override
public void addPermits(int permits) {
get(reducePermitsAsync(permits));
get(addPermitsAsync(permits));
}
@Override
public RFuture<Void> addPermitsAsync(int permits) {
return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_VOID,
"local value = redis.call('get', KEYS[1]); " +

@ -35,6 +35,21 @@ public class RedissonSemaphoreTest extends BaseConcurrentTest {
assertThat(s.availablePermits()).isEqualTo(10);
}
@Test
public void testAddPermits() throws InterruptedException {
RSemaphore s = redisson.getSemaphore("test");
s.trySetPermits(10);
s.acquire(10);
assertThat(s.availablePermits()).isEqualTo(0);
s.addPermits(4);
assertThat(s.availablePermits()).isEqualTo(4);
s.release(10);
assertThat(s.availablePermits()).isEqualTo(14);
s.acquire(5);
assertThat(s.availablePermits()).isEqualTo(9);
}
@Test
public void testReducePermits() throws InterruptedException {
RSemaphore s = redisson.getSemaphore("test");

Loading…
Cancel
Save