Merge branch 'master' of github.com:redisson/redisson

pull/4104/head
Nikita Koksharov 3 years ago
commit 99e4e92f9b

@ -552,22 +552,25 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
public boolean tryRelease(String permitId) { public boolean tryRelease(String permitId) {
return get(tryReleaseAsync(permitId)); return get(tryReleaseAsync(permitId));
} }
@Override
public RFuture<Boolean> tryReleaseAsync(String permitId) { public RFuture<Boolean> tryReleaseAsync(String permitId) {
if (permitId == null) { if (permitId == null) {
throw new IllegalArgumentException("permitId can't be null"); throw new IllegalArgumentException("permitId can't be null");
} }
return commandExecutor.evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN, return commandExecutor.evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
"local removed = redis.call('zrem', KEYS[3], ARGV[1]);" + "local expire = redis.call('zscore', KEYS[3], ARGV[1]);" +
"if tonumber(removed) ~= 1 then " + "local removed = redis.call('zrem', KEYS[3], ARGV[1]);" +
"return 0;" + "if tonumber(removed) ~= 1 then " +
"end;" + "return 0;" +
"local value = redis.call('incrby', KEYS[1], ARGV[2]); " + "end;" +
"redis.call('publish', KEYS[2], value); " + "local value = redis.call('incrby', KEYS[1], ARGV[2]); " +
"return 1;", "redis.call('publish', KEYS[2], value); " +
Arrays.<Object>asList(getRawName(), getChannelName(), timeoutName), permitId, 1); "if tonumber(expire) <= tonumber(ARGV[3]) then " +
"return 0;" +
"end;" +
"return 1;",
Arrays.<Object>asList(getRawName(), getChannelName(), timeoutName), permitId, 1, System.currentTimeMillis());
} }
@Override @Override

@ -220,6 +220,16 @@ public class RedissonPermitExpirableSemaphoreTest extends BaseConcurrentTest {
}); });
} }
@Test
public void testReleaseExpired() throws InterruptedException {
RPermitExpirableSemaphore s = redisson.getPermitExpirableSemaphore("test");
s.trySetPermits(1);
String permitId = s.tryAcquire(100, 100, TimeUnit.MILLISECONDS);
Thread.sleep(200);
boolean released = s.tryRelease(permitId);
assertThat(released).isFalse();
}
@Test @Test
public void testConcurrency_SingleInstance() throws InterruptedException { public void testConcurrency_SingleInstance() throws InterruptedException {
final AtomicInteger lockedCounter = new AtomicInteger(); final AtomicInteger lockedCounter = new AtomicInteger();

Loading…
Cancel
Save