/** * Tests starting up a {@link HelixAccountService}, when the corresponding {@code ZooKeeper} has account metadata * already stored on it. * @throws Exception Any unexpected exception. */ @Test public void testStartUpWithMetadataExists() throws Exception { // pre-populate account metadata in ZK. writeAccountsToHelixPropertyStore(idToRefAccountMap.values(), false); // When start, the helixAccountService should get the account metadata. accountService = mockHelixAccountServiceFactory.getAccountService(); assertAccountsInAccountService(idToRefAccountMap.values(), NUM_REF_ACCOUNT, accountService); }
/** * Tests creating a number of new {@link Account} through {@link HelixAccountService}, where there is no {@link ZNRecord} * exists on the {@code ZooKeeper}. */ @Test public void testCreateAccount() { accountService = mockHelixAccountServiceFactory.getAccountService(); assertEquals("The number of account in HelixAccountService is incorrect", 0, accountService.getAllAccounts().size()); boolean res = accountService.updateAccounts(idToRefAccountMap.values()); assertTrue("Failed to update accounts", res); assertAccountsInAccountService(idToRefAccountMap.values(), NUM_REF_ACCOUNT, accountService); }
/** * Updates a collection of {@link Account}s through {@link HelixAccountService}, and verifies that the * {@link Account}s have been successfully updated, so they can be queried through {@link HelixAccountService}. * @param accounts A collection of {@link Account}s to update through {@link HelixAccountService}. */ private void updateAccountsAndAssertAccountExistence(Collection<Account> accounts, int expectedAccountCount, boolean shouldUpdateSucceed) throws Exception { Collection<Account> expectedOldState = accountService.getAllAccounts(); boolean hasUpdateAccountSucceed = accountService.updateAccounts(accounts); assertEquals("Wrong update return status", shouldUpdateSucceed, hasUpdateAccountSucceed); if (shouldUpdateSucceed) { assertAccountsInAccountService(accounts, expectedAccountCount, accountService); if (helixConfigProps.containsKey(HelixAccountServiceConfig.BACKUP_DIRECTORY_KEY)) { Path oldStateBackup = Files.list(accountBackupDir) .filter(path -> path.getFileName().toString().endsWith(OLD_STATE_SUFFIX)) .max(Comparator.naturalOrder()) .get(); checkBackupFile(expectedOldState, oldStateBackup); String newStateFilename = oldStateBackup.getFileName().toString().replace(OLD_STATE_SUFFIX, NEW_STATE_SUFFIX); Path newStateBackup = oldStateBackup.getParent().resolve(newStateFilename); checkBackupFile(accountService.getAllAccounts(), newStateBackup); } else { assertEquals("No backup files should exist.", 0, Files.list(accountBackupDir).count()); } } else { assertEquals("Wrong number of accounts in accountService", expectedAccountCount, accountService.getAllAccounts().size()); } }
assertAccountsInAccountService(idToRefAccountMap.values(), NUM_REF_ACCOUNT, accountService);
assertAccountsInAccountService(idToRefAccountMap.values(), NUM_REF_ACCOUNT, accountService);