diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java index dad679bfc..5d1fdbc49 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java @@ -1110,15 +1110,6 @@ public class AccountsManager extends RedisPubSubAdapter implemen }); } - public CompletableFuture updateDeviceAsync(final Account account, final byte deviceId, - final Consumer deviceUpdater) { - return updateAsync(account, a -> { - a.getDevice(deviceId).ifPresent(deviceUpdater); - // assume that all updaters passed to the public method actually modify the device - return true; - }); - } - public Optional getByE164(final String number) { return getByNumberTimer.record(() -> accounts.getByE164(number)); } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java index 7b64e8e32..f6e518a18 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java @@ -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 deviceUpdater = mock(Consumer.class); - @SuppressWarnings("unchecked") Consumer 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(); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java index 40783409a..121582a31 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java @@ -67,7 +67,6 @@ public class AccountsHelper { *
  • {@link AccountsManager#update(Account, Consumer)}
  • *
  • {@link AccountsManager#updateAsync(Account, Consumer)}
  • *
  • {@link AccountsManager#updateDevice(Account, byte, Consumer)}
  • - *
  • {@link AccountsManager#updateDeviceAsync(Account, byte, Consumer)}
  • * * * with multiple calls to the {@link Consumer}. 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 -> {});