use of com.github.ambry.account.HelixAccountService in project ambry by linkedin.
the class HelixAccountServiceTest method testSelectInactiveContainer.
/**
* Tests select INACTIVE {@link Container}s from DELETE_IN_PROGRESS {@link Container}s.
*/
@Test
public void testSelectInactiveContainer() throws Exception {
// generates store stats
int accountCount = 1;
int containerCount = 3;
StatsSnapshot statsSnapshot = generateStoreStats(accountCount, containerCount, random, StatsReportType.ACCOUNT_REPORT);
// a set that records the account ids that have already been taken.
Set<Short> accountIdSet = new HashSet<>();
// generate a single reference account and container that can be referenced by refAccount and refContainer respectively.
refAccountId = Utils.getRandomShort(random);
accountIdSet.add(refAccountId);
generateRefAccounts(idToRefAccountMap, idToRefContainerMap, accountIdSet, 2, 3);
accountService = mockHelixAccountServiceFactory.getAccountService();
accountService.updateAccounts(idToRefAccountMap.values());
assertAccountsInAccountService(idToRefAccountMap.values(), 2, accountService);
Set<Container> expectContainerSet = new HashSet<>();
List<Account> accountsToUpdate = new ArrayList<>();
int accountId = 0;
for (Account account : accountService.getAllAccounts()) {
AccountBuilder accountBuilder = new AccountBuilder((short) accountId, "A[" + accountId + "]", AccountStatus.ACTIVE);
int containerId = 0;
for (Container container : account.getAllContainers()) {
ContainerBuilder containerBuilder = new ContainerBuilder((short) containerId, "C[" + containerId + "]", ContainerStatus.DELETE_IN_PROGRESS, container.getDescription() + "--extra", (short) accountId);
accountBuilder.addOrUpdateContainer(containerBuilder.build());
containerId++;
}
accountsToUpdate.add(accountBuilder.build());
if (accountId == 1) {
expectContainerSet.addAll(accountsToUpdate.get(accountId).getAllContainers());
}
accountId++;
}
updateAccountsAndAssertAccountExistence(accountsToUpdate, 4, true);
Set<Container> inactiveContainerSet = AccountUtils.selectInactiveContainerCandidates(statsSnapshot, accountService.getContainersByStatus(ContainerStatus.DELETE_IN_PROGRESS));
assertEquals("Mismatch in container Set after detect", expectContainerSet, inactiveContainerSet);
((HelixAccountService) accountService).markContainersInactive(inactiveContainerSet);
Account testAccount0 = accountService.getAccountById((short) 0);
for (Container container : testAccount0.getAllContainers()) {
assertEquals("Based on the stats report, container has not been compacted yet", ContainerStatus.DELETE_IN_PROGRESS, container.getStatus());
}
Account testAccount1 = accountService.getAccountById((short) 1);
for (Container container : testAccount1.getAllContainers()) {
assertEquals("Based on the stats report, inactive container status needs to be set as INACTIVE", ContainerStatus.INACTIVE, container.getStatus());
}
}
Aggregations