Change return type of set permits to void

Signed-off-by: maddie-boisvert <maddie.boisvert@gmail.com>
pull/4719/head
maddie-boisvert 2 years ago
parent 55e2e23b31
commit d685fcc418

@ -700,13 +700,13 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
} }
@Override @Override
public int setPermits(int permits) { public void setPermits(int permits) {
return get(setPermitsAsync(permits)); get(setPermitsAsync(permits));
} }
@Override @Override
public RFuture<Integer> setPermitsAsync(int permits) { public RFuture<Void> setPermitsAsync(int permits) {
return commandExecutor.evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER, return commandExecutor.evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_VOID,
"local available = redis.call('get', KEYS[1]); " + "local available = redis.call('get', KEYS[1]); " +
"if (available == false) then " + "if (available == false) then " +
"redis.call('set', KEYS[1], ARGV[1]); " + "redis.call('set', KEYS[1], ARGV[1]); " +
@ -718,10 +718,8 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
"if (maximum == ARGV[1]) then " + "if (maximum == ARGV[1]) then " +
"return 0;" + "return 0;" +
"end;" + "end;" +
"local delta = tonumber(ARGV[1]) - maximum; " + "redis.call('incrby', KEYS[1], tonumber(ARGV[1]) - maximum); " +
"redis.call('incrby', KEYS[1], delta); " + "redis.call('publish', KEYS[2], ARGV[1]);",
"redis.call('publish', KEYS[2], ARGV[1]); " +
"return delta;",
Arrays.<Object>asList(getRawName(), getChannelName(), timeoutName), permits); Arrays.<Object>asList(getRawName(), getChannelName(), timeoutName), permits);
} }

@ -131,14 +131,13 @@ public interface RPermitExpirableSemaphore extends RExpirable, RPermitExpirableS
boolean trySetPermits(int permits); boolean trySetPermits(int permits);
/** /**
* Sets the number of permits to the provided value and returns the number of permits added. * Sets the number of permits to the provided value.
* Calculates the <code>delta</code> between the given <code>permits</code> value and the * Calculates the <code>delta</code> between the given <code>permits</code> value and the
* current number of permits, then increases the number of available permits by <code>delta</code>. * current number of permits, then increases the number of available permits by <code>delta</code>.
* *
* @param permits - number of permits * @param permits - number of permits
* @return delta - number of permits that were added, will be negative if permits were removed
*/ */
int setPermits(int permits); void setPermits(int permits);
/** /**
* Increases or decreases the number of available permits by defined value. * Increases or decreases the number of available permits by defined value.

@ -128,14 +128,13 @@ public interface RPermitExpirableSemaphoreAsync extends RExpirableAsync {
RFuture<Boolean> trySetPermitsAsync(int permits); RFuture<Boolean> trySetPermitsAsync(int permits);
/** /**
* Sets the number of permits to the provided value and returns the number of permits added. * Sets the number of permits to the provided value.
* Calculates the <code>delta</code> between the given <code>permits</code> vaue and the * Calculates the <code>delta</code> between the given <code>permits</code> value and the
* current number of permits, then increases the number of available permits by <code>delta</code>. * current number of permits, then increases the number of available permits by <code>delta</code>.
* *
* @param permits - number of permits * @param permits - number of permits
* @return delta - number of permits that were added, will be negative if permits were removed
*/ */
RFuture<Integer> setPermitsAsync(int permits); RFuture<Void> setPermitsAsync(int permits);
/** /**
* Increases or decreases the number of available permits by defined value. * Increases or decreases the number of available permits by defined value.

@ -183,7 +183,7 @@ public class RedissonPermitExpirableSemaphoreTest extends BaseConcurrentTest {
@Test @Test
public void testSetPermits() throws InterruptedException { public void testSetPermits() throws InterruptedException {
RPermitExpirableSemaphore s = redisson.getPermitExpirableSemaphore("test"); RPermitExpirableSemaphore s = redisson.getPermitExpirableSemaphore("test");
assertThat(s.setPermits(10)).isEqualTo(10); s.setPermits(10);
assertThat(s.getPermits()).isEqualTo(10); assertThat(s.getPermits()).isEqualTo(10);
assertThat(s.availablePermits()).isEqualTo(10); assertThat(s.availablePermits()).isEqualTo(10);
assertThat(s.claimedPermits()).isEqualTo(0); assertThat(s.claimedPermits()).isEqualTo(0);
@ -195,19 +195,19 @@ public class RedissonPermitExpirableSemaphoreTest extends BaseConcurrentTest {
assertThat(s.claimedPermits()).isEqualTo(0); assertThat(s.claimedPermits()).isEqualTo(0);
// attempts to set max permits succeeds // attempts to set max permits succeeds
assertThat(s.setPermits(15)).isEqualTo(5); s.setPermits(15);
assertThat(s.getPermits()).isEqualTo(15); assertThat(s.getPermits()).isEqualTo(15);
assertThat(s.availablePermits()).isEqualTo(15); assertThat(s.availablePermits()).isEqualTo(15);
assertThat(s.claimedPermits()).isEqualTo(0); assertThat(s.claimedPermits()).isEqualTo(0);
// setting to existing value succeeds // setting to existing value succeeds
assertThat(s.setPermits(15)).isEqualTo(0); s.setPermits(15);
assertThat(s.getPermits()).isEqualTo(15); assertThat(s.getPermits()).isEqualTo(15);
assertThat(s.availablePermits()).isEqualTo(15); assertThat(s.availablePermits()).isEqualTo(15);
assertThat(s.claimedPermits()).isEqualTo(0); assertThat(s.claimedPermits()).isEqualTo(0);
// decreasing max permits succeeds // decreasing max permits succeeds
assertThat(s.setPermits(5)).isEqualTo(-10); s.setPermits(5);
assertThat(s.getPermits()).isEqualTo(5); assertThat(s.getPermits()).isEqualTo(5);
assertThat(s.availablePermits()).isEqualTo(5); assertThat(s.availablePermits()).isEqualTo(5);
assertThat(s.claimedPermits()).isEqualTo(0); assertThat(s.claimedPermits()).isEqualTo(0);
@ -225,14 +225,14 @@ public class RedissonPermitExpirableSemaphoreTest extends BaseConcurrentTest {
assertThat(s.claimedPermits()).isEqualTo(3); assertThat(s.claimedPermits()).isEqualTo(3);
// decreasing the max to the number of claimed permits is allowed // decreasing the max to the number of claimed permits is allowed
assertThat(s.setPermits(3)).isEqualTo(-2); s.setPermits(3);
assertThat(s.getPermits()).isEqualTo(3); assertThat(s.getPermits()).isEqualTo(3);
assertThat(s.availablePermits()).isEqualTo(0); assertThat(s.availablePermits()).isEqualTo(0);
assertThat(s.claimedPermits()).isEqualTo(3); assertThat(s.claimedPermits()).isEqualTo(3);
// decreasing the max to below the number of claimed permits is allowed // decreasing the max to below the number of claimed permits is allowed
// and results in a negative number of available permits // and results in a negative number of available permits
assertThat(s.setPermits(2)).isEqualTo(-1); s.setPermits(2);
assertThat(s.getPermits()).isEqualTo(2); assertThat(s.getPermits()).isEqualTo(2);
assertThat(s.availablePermits()).isEqualTo(-1); assertThat(s.availablePermits()).isEqualTo(-1);
assertThat(s.claimedPermits()).isEqualTo(3); assertThat(s.claimedPermits()).isEqualTo(3);

Loading…
Cancel
Save