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 AccountContainerTest method testAccountBuilder.
/**
* Tests building an {@link Account} using {@link AccountBuilder}.
* @throws JSONException
*/
@Test
public void testAccountBuilder() throws JSONException {
// build an account with arguments supplied
AccountBuilder accountBuilder = new AccountBuilder(refAccountId, refAccountName, refAccountStatus, refQuotaResourceType).snapshotVersion(refAccountSnapshotVersion).aclInheritedByContainer(refAccountAclInheritedByContainer);
Account accountByBuilder = accountBuilder.build();
assertAccountAgainstReference(accountByBuilder, false, false);
// set containers
for (int i = 0; i < CONTAINER_COUNT; i++) {
Container container = containerFromJson(containerJsonList.get(i), refAccountId);
accountBuilder.addOrUpdateContainer(container);
}
accountByBuilder = accountBuilder.build();
assertAccountAgainstReference(accountByBuilder, true, true);
// build an account from existing account
accountBuilder = new AccountBuilder(accountByBuilder);
Account account2ByBuilder = accountBuilder.build();
assertAccountAgainstReference(account2ByBuilder, true, true);
// clear containers
Account account3ByBuilder = new AccountBuilder(account2ByBuilder).containers(null).build();
assertAccountAgainstReference(account3ByBuilder, false, false);
assertTrue("Container list should be empty.", account3ByBuilder.getAllContainers().isEmpty());
}
Aggregations