diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Accounts.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Accounts.java index 36b25db51..c25468986 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Accounts.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Accounts.java @@ -48,6 +48,7 @@ public class Accounts { private final Timer getByUuidTimer = metricRegistry.timer(name(Accounts.class, "getByUuid" )); private final Timer getAllFromTimer = metricRegistry.timer(name(Accounts.class, "getAllFrom" )); private final Timer getAllFromOffsetTimer = metricRegistry.timer(name(Accounts.class, "getAllFromOffset")); + private final Timer deleteTimer = metricRegistry.timer(name(Accounts.class, "delete" )); private final Timer vacuumTimer = metricRegistry.timer(name(Accounts.class, "vacuum" )); private final FaultTolerantDatabase database; @@ -134,6 +135,16 @@ public class Accounts { })); } + public void delete(final UUID uuid) { + database.use(jdbi -> jdbi.useHandle(handle -> { + try (Timer.Context ignored = deleteTimer.time()) { + handle.createUpdate("DELETE FROM accounts WHERE " + UID + " = :uuid") + .bind("uuid", uuid) + .execute(); + } + })); + } + public void vacuum() { database.use(jdbi -> jdbi.useHandle(handle -> { try (Timer.Context ignored = vacuumTimer.time()) { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountsTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountsTest.java index 37dcc512b..0f57a1536 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountsTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountsTest.java @@ -188,6 +188,26 @@ public class AccountsTest { } } + @Test + public void testDelete() { + final Device deletedDevice = generateDevice (1); + final Account deletedAccount = generateAccount("+14151112222", UUID.randomUUID(), Collections.singleton(deletedDevice)); + final Device retainedDevice = generateDevice (1); + final Account retainedAccount = generateAccount("+14151112345", UUID.randomUUID(), Collections.singleton(retainedDevice)); + + accounts.create(deletedAccount); + accounts.create(retainedAccount); + + assertThat(accounts.get(deletedAccount.getUuid())).isPresent(); + assertThat(accounts.get(retainedAccount.getUuid())).isPresent(); + + accounts.delete(deletedAccount.getUuid()); + + assertThat(accounts.get(deletedAccount.getUuid())).isNotPresent(); + + verifyStoredState(retainedAccount.getNumber(), retainedAccount.getUuid(), accounts.get(retainedAccount.getUuid()).get(), retainedAccount); + } + @Test public void testVacuum() { Device device = generateDevice (1 );