Fixed - RPermitExpirableSemaphore.release(java.util.List) shouldn't release permits if one of them doesn't exist #6343

Signed-off-by: xuxiaolei <seakider@gmail.com>
pull/6348/head
seakider 3 months ago committed by xuxiaolei
parent ee3d4c2e37
commit 4d6ed7d72b

@ -736,12 +736,10 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
throw new CompletionException(e);
}
// if (res == permitsIds.size()) {
// return null;
// }
if (res != 0) {
if (res == permitsIds.size()) {
return null;
}
throw new CompletionException(new IllegalArgumentException("Permits with ids " + permitsIds + " have already been released or don't exist"));
});
return new CompletableFutureWrapper<>(f);

@ -556,11 +556,12 @@ public class RedissonPermitExpirableSemaphoreTest extends BaseConcurrentTest {
}
@Test
public void testReleaseManyWithout() throws InterruptedException {
public void testReleaseManyNotExistOrExpired() throws InterruptedException {
RPermitExpirableSemaphore s = redisson.getPermitExpirableSemaphore("test");
s.trySetPermits(10);
List<String> timedPermitsIds = s.acquire(2,100, TimeUnit.MILLISECONDS);
List<String> timedPermitsIds = s.acquire(2, 100, TimeUnit.MILLISECONDS);
List<String> permitsIds = s.tryAcquire(8);
List<String> permitsIdsFirstPart = permitsIds.subList(0, 2);
int released = s.tryRelease(permitsIdsFirstPart);
@ -572,12 +573,10 @@ public class RedissonPermitExpirableSemaphoreTest extends BaseConcurrentTest {
Assertions.assertThrows(RedisException.class, () -> s.release(timedPermitsIds));
assertThat(s.availablePermits()).isEqualTo(4);
List<String> permitsIdsThirdPart = permitsIds.subList(4, 6);
permitsIdsThirdPart.addAll(permitsIdsFirstPart);
Assertions.assertThrows(RedisException.class, () -> s.release(permitsIdsThirdPart));
List<String> permitsIdsSecondPart = permitsIds.subList(2, 4);
permitsIdsSecondPart.addAll(permitsIdsFirstPart);
Assertions.assertThrows(RedisException.class, () -> s.release(permitsIdsSecondPart));
assertThat(s.availablePermits()).isEqualTo(4);
}
@Test

Loading…
Cancel
Save