use of com.github.ambry.account.Account in project ambry by linkedin.
the class HelixAccountServiceTest method testNonConflictingUpdateCaseA.
/**
* Tests updating a {@link Account}, which has the same id and name as an existing record, and will replace the
* existing record. This test corresponds to case A specified in the JavaDoc of {@link AccountService}.
* @throws Exception Any unexpected exception.
*/
@Test
public void testNonConflictingUpdateCaseA() throws Exception {
accountService = mockHelixAccountServiceFactory.getAccountService();
// write two accounts (1, "a") and (2, "b")
writeAccountsForConflictTest();
Account accountToUpdate = accountService.getAccountById((short) 1);
Collection<Account> nonConflictAccounts = Collections.singleton(new AccountBuilder(accountToUpdate).status(AccountStatus.ACTIVE).build());
updateAccountsAndAssertAccountExistence(nonConflictAccounts, 2, true);
}
use of com.github.ambry.account.Account in project ambry by linkedin.
the class HelixAccountServiceTest method testReadConflictAccountDataFromHelixPropertyStoreCase2.
/**
* Tests reading conflicting {@link Account} metadata from {@link org.apache.helix.store.HelixPropertyStore}.
* @throws Exception Any unexpected exception.
*/
@Test
public void testReadConflictAccountDataFromHelixPropertyStoreCase2() throws Exception {
List<Account> conflictAccounts = new ArrayList<>();
Account account1 = new AccountBuilder((short) 1, "a", AccountStatus.INACTIVE).build();
Account account2 = new AccountBuilder((short) 2, "a", AccountStatus.INACTIVE).build();
Account account3 = new AccountBuilder((short) 2, "b", AccountStatus.INACTIVE).build();
Account account4 = new AccountBuilder((short) 3, "b", AccountStatus.INACTIVE).build();
conflictAccounts.add(account1);
conflictAccounts.add(account2);
conflictAccounts.add(account3);
conflictAccounts.add(account4);
readAndUpdateBadRecord(conflictAccounts);
}
use of com.github.ambry.account.Account in project ambry by linkedin.
the class HelixAccountServiceTest method writeAccountsToHelixPropertyStore.
/**
* Pre-populates a collection of {@link Account}s to the underlying {@link org.apache.helix.store.HelixPropertyStore}
* using {@link com.github.ambry.clustermap.HelixStoreOperator} (not through the {@link HelixAccountService}). This method
* does not check any conflict among the {@link Account}s to write.
* @throws Exception Any unexpected exception.
*/
private void writeAccountsToHelixPropertyStore(Collection<Account> accounts, boolean shouldNotify) throws Exception {
HelixStoreOperator storeOperator = new HelixStoreOperator(mockHelixAccountServiceFactory.getHelixStore(ZK_CONNECT_STRING, storeConfig));
ZNRecord zNRecord = new ZNRecord(String.valueOf(System.currentTimeMillis()));
Map<String, String> accountMap = new HashMap<>();
for (Account account : accounts) {
accountMap.put(String.valueOf(account.getId()), objectMapper.writeValueAsString(new AccountBuilder(account).snapshotVersion(refAccount.getSnapshotVersion() + 1).build()));
}
if (useNewZNodePath) {
String blobID = RouterStore.writeAccountMapToRouter(accountMap, mockRouter);
List<String> list = Collections.singletonList(new RouterStore.BlobIDAndVersion(blobID, 1).toJson());
zNRecord.setListField(RouterStore.ACCOUNT_METADATA_BLOB_IDS_LIST_KEY, list);
storeOperator.write(RouterStore.ACCOUNT_METADATA_BLOB_IDS_PATH, zNRecord);
} else {
zNRecord.setMapField(LegacyMetadataStore.ACCOUNT_METADATA_MAP_KEY, accountMap);
// Write account metadata into HelixPropertyStore.
storeOperator.write(LegacyMetadataStore.FULL_ACCOUNT_METADATA_PATH, zNRecord);
}
if (shouldNotify) {
notifier.publish(ACCOUNT_METADATA_CHANGE_TOPIC, FULL_ACCOUNT_METADATA_CHANGE_MESSAGE);
}
}
use of com.github.ambry.account.Account in project ambry by linkedin.
the class AccountDao method convertAccountsResultSet.
/**
* Convert a query result set to a list of accounts.
* @param resultSet the result set.
* @return a list of {@link Account}s.
* @throws SQLException
*/
private List<Account> convertAccountsResultSet(ResultSet resultSet) throws SQLException {
List<Account> accounts = new ArrayList<>();
while (resultSet.next()) {
String accountJson = resultSet.getString(ACCOUNT_INFO);
Timestamp lastModifiedTime = resultSet.getTimestamp(LAST_MODIFIED_TIME);
int version = resultSet.getInt(VERSION);
try {
Account account = new AccountBuilder(objectMapper.readValue(accountJson, Account.class)).lastModifiedTime(lastModifiedTime.getTime()).snapshotVersion(version).build();
accounts.add(account);
} catch (IOException e) {
throw new SQLException(String.format("Faild to deserialize string [{}] to account object", accountJson), e);
}
}
return accounts;
}
use of com.github.ambry.account.Account in project ambry by linkedin.
the class HelixAccountServiceTest method assertAccountUpdateConsumers.
/**
* Asserts the {@link Account}s received by the {@link Consumer} are as expected.
* @param expectedAccounts The expected collection of {@link Account}s that should be received by the {@link Consumer}s.
* @param expectedNumberOfConsumers The expected number of {@link Consumer}s.
* @param accountsInConsumers A list of collection of {@link Account}s, where each collection of {@link Account}s are
* received by one {@link Consumer}.
*/
private void assertAccountUpdateConsumers(Set<Account> expectedAccounts, int expectedNumberOfConsumers, List<Collection<Account>> accountsInConsumers) throws Exception {
assertEquals("Wrong number of consumers", expectedNumberOfConsumers, accountsInConsumers.size());
for (Collection<Account> accounts : accountsInConsumers) {
assertEquals("Wrong number of updated accounts received by consumers", expectedAccounts.size(), accounts.size());
for (Account account : accounts) {
assertTrue("Account update not received by consumers", expectedAccounts.contains(account));
}
TestUtils.assertException(UnsupportedOperationException.class, () -> accounts.add(InMemoryUnknownAccountService.UNKNOWN_ACCOUNT), null);
}
}
Aggregations