mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 12:28:05 +01:00
Use a Callable for tasks performed within the scope of a pessimistic lock
This commit is contained in:
committed by
Jon Chambers
parent
b95d08aaea
commit
a4b98f38a6
@@ -47,9 +47,8 @@ class AccountLockManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void withLock() throws InterruptedException {
|
||||
accountLockManager.withLock(List.of(FIRST_PNI, SECOND_PNI), () -> {
|
||||
}, executor);
|
||||
void withLock() throws Exception {
|
||||
accountLockManager.withLock(List.of(FIRST_PNI, SECOND_PNI), () -> null, executor);
|
||||
|
||||
verify(lockClient, times(2)).acquireLock(any());
|
||||
verify(lockClient, times(2)).releaseLock(any(ReleaseLockOptions.class));
|
||||
@@ -69,8 +68,7 @@ class AccountLockManagerTest {
|
||||
void withLockEmptyList() {
|
||||
final Runnable task = mock(Runnable.class);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> accountLockManager.withLock(Collections.emptyList(), () -> {
|
||||
},
|
||||
assertThrows(IllegalArgumentException.class, () -> accountLockManager.withLock(Collections.emptyList(), () -> null,
|
||||
executor));
|
||||
verify(task, never()).run();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
@@ -84,7 +85,7 @@ class AccountsManagerConcurrentModificationIntegrationTest {
|
||||
private Executor mutationExecutor = new ThreadPoolExecutor(20, 20, 5, TimeUnit.SECONDS, new LinkedBlockingDeque<>(20));
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws InterruptedException {
|
||||
void setup() throws Exception {
|
||||
|
||||
@SuppressWarnings("unchecked") final DynamicConfigurationManager<DynamicConfiguration> dynamicConfigurationManager =
|
||||
mock(DynamicConfigurationManager.class);
|
||||
@@ -108,10 +109,8 @@ class AccountsManagerConcurrentModificationIntegrationTest {
|
||||
final AccountLockManager accountLockManager = mock(AccountLockManager.class);
|
||||
|
||||
doAnswer(invocation -> {
|
||||
final Runnable task = invocation.getArgument(1);
|
||||
task.run();
|
||||
|
||||
return null;
|
||||
final Callable<?> task = invocation.getArgument(1);
|
||||
return task.call();
|
||||
}).when(accountLockManager).withLock(anyList(), any(), any());
|
||||
|
||||
when(accountLockManager.withLockAsync(anyList(), any(), any())).thenAnswer(invocation -> {
|
||||
|
||||
@@ -52,6 +52,7 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -153,7 +154,7 @@ class AccountsManagerTest {
|
||||
};
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws InterruptedException {
|
||||
void setup() throws Exception {
|
||||
accounts = mock(Accounts.class);
|
||||
keysManager = mock(KeysManager.class);
|
||||
messagesManager = mock(MessagesManager.class);
|
||||
@@ -213,10 +214,8 @@ class AccountsManagerTest {
|
||||
final AccountLockManager accountLockManager = mock(AccountLockManager.class);
|
||||
|
||||
doAnswer(invocation -> {
|
||||
final Runnable task = invocation.getArgument(1);
|
||||
task.run();
|
||||
|
||||
return null;
|
||||
final Callable<?> task = invocation.getArgument(1);
|
||||
return task.call();
|
||||
}).when(accountLockManager).withLock(anyList(), any(), any());
|
||||
|
||||
when(accountLockManager.withLockAsync(anyList(), any(), any())).thenAnswer(invocation -> {
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Supplier;
|
||||
@@ -81,12 +82,12 @@ class AccountsManagerUsernameIntegrationTest {
|
||||
private Accounts accounts;
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws InterruptedException {
|
||||
void setup() throws Exception {
|
||||
buildAccountsManager(1, 2, 10);
|
||||
}
|
||||
|
||||
private void buildAccountsManager(final int initialWidth, int discriminatorMaxWidth, int attemptsPerWidth)
|
||||
throws InterruptedException {
|
||||
throws Exception {
|
||||
@SuppressWarnings("unchecked") final DynamicConfigurationManager<DynamicConfiguration> dynamicConfigurationManager =
|
||||
mock(DynamicConfigurationManager.class);
|
||||
|
||||
@@ -115,10 +116,8 @@ class AccountsManagerUsernameIntegrationTest {
|
||||
final AccountLockManager accountLockManager = mock(AccountLockManager.class);
|
||||
|
||||
doAnswer(invocation -> {
|
||||
final Runnable task = invocation.getArgument(1);
|
||||
task.run();
|
||||
|
||||
return null;
|
||||
final Callable<?> task = invocation.getArgument(1);
|
||||
return task.call();
|
||||
}).when(accountLockManager).withLock(anyList(), any(), any());
|
||||
|
||||
when(accountLockManager.withLockAsync(anyList(), any(), any())).thenAnswer(invocation -> {
|
||||
|
||||
Reference in New Issue
Block a user