@Test
  public void testUpdateAccounts() throws Exception {

    when(mockMySqlAccountStore.getNewAccounts(0)).thenReturn(new ArrayList<>());
    mySqlAccountService = getAccountService();
    Container testContainer =
        new ContainerBuilder((short) 1, "testContainer", Container.ContainerStatus.ACTIVE, "testContainer",
            (short) 1).build();
    Account testAccount = new AccountBuilder((short) 1, "testAccount", Account.AccountStatus.ACTIVE).containers(
        Collections.singleton(testContainer)).build();

    // 1. Addition of new account. Verify account is added to cache and written to mysql store.
    mySqlAccountService.updateAccounts(Collections.singletonList(testAccount));
    Account finalTestAccount = testAccount;
    verify(mockMySqlAccountStore, atLeastOnce()).updateAccounts(argThat(accountsInfo -> {
      Account account = accountsInfo.get(0).getAccount();
      return account.equals(finalTestAccount);
    }));
    List<Account> accounts = new ArrayList<>(mySqlAccountService.getAllAccounts());
    assertEquals("Mismatch in number of accounts", 1, accounts.size());
    assertEquals("Mismatch in account retrieved by ID", testAccount,
        mySqlAccountService.getAccountById(testAccount.getId()));
    assertEquals("Mismatch in account retrieved by name", testAccount,
        mySqlAccountService.getAccountByName(testAccount.getName()));

    // 2. Update existing account by changing aclInheritedByContainer to true. Verify account is updated in cache and written to mysql store.
    testAccount = new AccountBuilder(testAccount).aclInheritedByContainer(true).build();
    mySqlAccountService.updateAccounts(Collections.singletonList(testAccount));
    Account finalTestAccount0 = testAccount;
    verify(mockMySqlAccountStore, atLeastOnce()).updateAccounts(argThat(accountsInfo -> {
      AccountUtils.AccountUpdateInfo accountUpdateInfo = accountsInfo.get(0);
      return accountUpdateInfo.getAccount().equals(finalTestAccount0) && !accountUpdateInfo.isAdded()
          && accountUpdateInfo.isUpdated() && accountUpdateInfo.getAddedContainers().isEmpty()
          && accountUpdateInfo.getUpdatedContainers().isEmpty();
    }));
    assertEquals("Mismatch in account retrieved by ID", testAccount,
        mySqlAccountService.getAccountById(testAccount.getId()));

    // 3. Update existing account by adding new container. Verify account is updated in cache and written to mysql store.
    Container testContainer2 =
        new ContainerBuilder((short) 2, "testContainer2", Container.ContainerStatus.ACTIVE, "testContainer2", (short) 1)
            .build();
    testAccount = new AccountBuilder(testAccount).addOrUpdateContainer(testContainer2).build();
    mySqlAccountService.updateAccounts(Collections.singletonList(testAccount));
    Account finalTestAccount1 = testAccount;
    verify(mockMySqlAccountStore, atLeastOnce()).updateAccounts(argThat(accountsInfo -> {
      AccountUtils.AccountUpdateInfo accountUpdateInfo = accountsInfo.get(0);
      return accountUpdateInfo.getAccount().equals(finalTestAccount1) && !accountUpdateInfo.isAdded()
          && !accountUpdateInfo.isUpdated() && accountUpdateInfo.getAddedContainers()
          .equals(Collections.singletonList(testContainer2)) && accountUpdateInfo.getUpdatedContainers().isEmpty();
    }));
    assertEquals("Mismatch in account retrieved by ID", testAccount,
        mySqlAccountService.getAccountById(testAccount.getId()));

    // 4. Update existing container. Verify container is updated in cache and written to mysql store.
    testContainer = new ContainerBuilder(testContainer).setMediaScanDisabled(true).setCacheable(true).build();
    testAccount = new AccountBuilder(testAccount).addOrUpdateContainer(testContainer).build();
    mySqlAccountService.updateAccounts(Collections.singletonList(testAccount));
    Container finalTestContainer =
        new ContainerBuilder(testContainer).setSnapshotVersion(testContainer.getSnapshotVersion() + 1).build();
    Account finalTestAccount2 = testAccount;
    verify(mockMySqlAccountStore, atLeastOnce()).updateAccounts(argThat(accountsInfo -> {
      AccountUtils.AccountUpdateInfo accountUpdateInfo = accountsInfo.get(0);
      return accountUpdateInfo.getAccount().equals(finalTestAccount2) && !accountUpdateInfo.isAdded()
          && !accountUpdateInfo.isUpdated() && accountUpdateInfo.getAddedContainers().isEmpty()
          && accountUpdateInfo.getUpdatedContainers().equals(Collections.singletonList(finalTestContainer));
    }));
    assertEquals("Mismatch in account retrieved by ID", testAccount,
        mySqlAccountService.getAccountById(testAccount.getId()));
    assertTrue("Sync time not updated",
        mySqlAccountService.accountServiceMetrics.timeInSecondsSinceLastSyncGauge.getValue() < 10);
    assertEquals("Unexpected container count", 2,
        mySqlAccountService.accountServiceMetrics.containerCountGauge.getValue().intValue());
  }
Tests creating and updating accounts through {@link MySqlAccountService}:
1. add a new {@link Account};
2. update existing {@link Account} by adding new {@link Container} to an existing {@link Account};
ambry-account/src/test/java/com/github/ambry/account/MySqlAccountServiceTest.java