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

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

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

@ -34,7 +34,22 @@ public class RedissonSemaphoreTest extends BaseConcurrentTest {
assertThat(s.trySetPermits(15)).isFalse(); assertThat(s.trySetPermits(15)).isFalse();
assertThat(s.availablePermits()).isEqualTo(10); 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 @Test
public void testReducePermits() throws InterruptedException { public void testReducePermits() throws InterruptedException {
RSemaphore s = redisson.getSemaphore("test"); RSemaphore s = redisson.getSemaphore("test");

Loading…
Cancel
Save