mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 20:38:04 +01:00
Remove AccountsManager#updateDeviceAsync
This commit is contained in:
committed by
Jon Chambers
parent
8df3f3c150
commit
de458c3e6a
@@ -719,38 +719,6 @@ class AccountsManagerTest {
|
||||
verify(unknownDeviceUpdater, never()).accept(any(Device.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateDeviceAsync() {
|
||||
final UUID uuid = UUID.randomUUID();
|
||||
Account account = AccountsHelper.generateTestAccount("+14152222222", uuid, UUID.randomUUID(), new ArrayList<>(), new byte[UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH]);
|
||||
|
||||
when(accounts.getByAccountIdentifierAsync(uuid)).thenReturn(CompletableFuture.completedFuture(
|
||||
Optional.of(AccountsHelper.generateTestAccount("+14152222222", uuid, UUID.randomUUID(), new ArrayList<>(), new byte[UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH]))));
|
||||
|
||||
assertTrue(account.getDevices().isEmpty());
|
||||
|
||||
Device enabledDevice = new Device();
|
||||
enabledDevice.setFetchesMessages(true);
|
||||
enabledDevice.setLastSeen(System.currentTimeMillis());
|
||||
final byte deviceId = account.getNextDeviceId();
|
||||
enabledDevice.setId(deviceId);
|
||||
account.addDevice(enabledDevice);
|
||||
|
||||
@SuppressWarnings("unchecked") Consumer<Device> deviceUpdater = mock(Consumer.class);
|
||||
@SuppressWarnings("unchecked") Consumer<Device> unknownDeviceUpdater = mock(Consumer.class);
|
||||
|
||||
account = accountsManager.updateDeviceAsync(account, deviceId, deviceUpdater).join();
|
||||
account = accountsManager.updateDeviceAsync(account, deviceId, d -> d.setName("deviceName".getBytes(StandardCharsets.UTF_8))).join();
|
||||
|
||||
assertArrayEquals("deviceName".getBytes(StandardCharsets.UTF_8), account.getDevice(deviceId).orElseThrow().getName());
|
||||
|
||||
verify(deviceUpdater, times(1)).accept(any(Device.class));
|
||||
|
||||
accountsManager.updateDeviceAsync(account, account.getNextDeviceId(), unknownDeviceUpdater).join();
|
||||
|
||||
verify(unknownDeviceUpdater, never()).accept(any(Device.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveDevice() {
|
||||
final Device primaryDevice = new Device();
|
||||
|
||||
@@ -67,7 +67,6 @@ public class AccountsHelper {
|
||||
* <li>{@link AccountsManager#update(Account, Consumer)}</li>
|
||||
* <li>{@link AccountsManager#updateAsync(Account, Consumer)}</li>
|
||||
* <li>{@link AccountsManager#updateDevice(Account, byte, Consumer)}</li>
|
||||
* <li>{@link AccountsManager#updateDeviceAsync(Account, byte, Consumer)}</li>
|
||||
* </ul>
|
||||
*
|
||||
* with multiple calls to the {@link Consumer<Account>}. This simulates retries from {@link org.whispersystems.textsecuregcm.storage.ContestedOptimisticLockException}.
|
||||
@@ -112,17 +111,6 @@ public class AccountsHelper {
|
||||
|
||||
return copyAndMarkStale(account);
|
||||
});
|
||||
|
||||
when(mockAccountsManager.updateDeviceAsync(any(), anyByte(), any())).thenAnswer(answer -> {
|
||||
final Account account = answer.getArgument(0, Account.class);
|
||||
final byte deviceId = answer.getArgument(1, Byte.class);
|
||||
|
||||
for (int i = 0; i < retryCount; i++) {
|
||||
account.getDevice(deviceId).ifPresent(answer.getArgument(2, Consumer.class));
|
||||
}
|
||||
|
||||
return CompletableFuture.completedFuture(copyAndMarkStale(account));
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -149,14 +137,6 @@ public class AccountsHelper {
|
||||
return markStale ? copyAndMarkStale(account) : account;
|
||||
});
|
||||
|
||||
when(mockAccountsManager.updateDeviceAsync(any(), anyByte(), any())).thenAnswer(answer -> {
|
||||
final Account account = answer.getArgument(0, Account.class);
|
||||
final byte deviceId = answer.getArgument(1, Byte.class);
|
||||
account.getDevice(deviceId).ifPresent(answer.getArgument(2, Consumer.class));
|
||||
|
||||
return CompletableFuture.completedFuture(markStale ? copyAndMarkStale(account) : account);
|
||||
});
|
||||
|
||||
when(mockAccountsManager.updateDeviceLastSeen(any(), any(), anyLong())).thenAnswer(answer -> {
|
||||
answer.getArgument(1, Device.class).setLastSeen(answer.getArgument(2, Long.class));
|
||||
return mockAccountsManager.update(answer.getArgument(0, Account.class), account -> {});
|
||||
|
||||
Reference in New Issue
Block a user