mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 11:46:53 +00:00
Add support for pessimistic locking of phone-number-less accounts
This commit is contained in:
1 parent
850286dbfc
commit
d7447b111d
2 files changed
+65
-16
No files matched your search
+26
@@ -6,10 +6,13 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.amazonaws.services.dynamodbv2.AcquireLockOptions;
|
||||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBLockClient;
|
||||
import com.amazonaws.services.dynamodbv2.ReleaseLockOptions;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -28,6 +31,7 @@ class AccountLockManagerTest {
|
||||
|
||||
private static final UUID FIRST_PNI = UUID.randomUUID();
|
||||
private static final UUID SECOND_PNI = UUID.randomUUID();
|
||||
private static final UUID ACI = UUID.randomUUID();
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@@ -71,4 +75,26 @@ class AccountLockManagerTest {
|
||||
executor));
|
||||
verify(task, never()).run();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withLockPniAccount() throws Exception {
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getAccountIdentifier()).thenReturn(ACI);
|
||||
when(account.getPhoneNumberIdentifierOptional()).thenReturn(Optional.of(FIRST_PNI));
|
||||
|
||||
accountLockManager.withSingleAccountLock(account, () -> null, executor);
|
||||
verify(lockClient, times(1)).acquireLock(
|
||||
AcquireLockOptions.builder(FIRST_PNI.toString()).withAcquireReleasedLocksConsistently(true).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void withLockNoPniAccount() throws Exception {
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getAccountIdentifier()).thenReturn(ACI);
|
||||
when(account.getPhoneNumberIdentifierOptional()).thenReturn(Optional.empty());
|
||||
|
||||
accountLockManager.withSingleAccountLock(account, () -> null, executor);
|
||||
verify(lockClient, times(1)).acquireLock(
|
||||
AcquireLockOptions.builder(ACI.toString()).withAcquireReleasedLocksConsistently(true).build());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user