Allow the account cleaner to operate on multiple accounts in parallel

This commit is contained in:
Jon Chambers
2022-11-10 12:53:52 -05:00
committed by Jon Chambers
parent ae57853ec4
commit cb50b44d8f
3 changed files with 45 additions and 9 deletions

View File

@@ -15,7 +15,10 @@ import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.whispersystems.textsecuregcm.storage.AccountsManager.DeletionReason;
@@ -32,6 +35,8 @@ class AccountCleanerTest {
private final Device undeletedDisabledDevice = mock(Device.class );
private final Device undeletedEnabledDevice = mock(Device.class );
private ExecutorService deletionExecutor;
@BeforeEach
void setup() {
@@ -61,11 +66,19 @@ class AccountCleanerTest {
when(undeletedEnabledAccount.getNumber()).thenReturn("+14153333333");
when(undeletedEnabledAccount.getLastSeen()).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(364));
when(undeletedEnabledAccount.getUuid()).thenReturn(UUID.randomUUID());
deletionExecutor = Executors.newFixedThreadPool(2);
}
@AfterEach
void tearDown() throws InterruptedException {
deletionExecutor.shutdown();
deletionExecutor.awaitTermination(2, TimeUnit.SECONDS);
}
@Test
void testAccounts() throws AccountDatabaseCrawlerRestartException, InterruptedException {
AccountCleaner accountCleaner = new AccountCleaner(accountsManager);
AccountCleaner accountCleaner = new AccountCleaner(accountsManager, deletionExecutor);
accountCleaner.onCrawlStart();
accountCleaner.timeAndProcessCrawlChunk(Optional.empty(), Arrays.asList(deletedDisabledAccount, undeletedDisabledAccount, undeletedEnabledAccount));
accountCleaner.onCrawlEnd(Optional.empty());