@Test
  public void testFailover() throws Exception {
    String dbInfoJsonString = mySqlConfigProps.getProperty(DB_INFO);
    JSONArray dbInfo = new JSONArray(dbInfoJsonString);
    JSONObject entry = dbInfo.getJSONObject(0);
    DbEndpoint origEndpoint = DbEndpoint.fromJson(entry);
    // Make two endpoints, one with bad url, writeable, remote; second with good url, writeable, local
    String localDc = "local", remoteDc = "remote";
    String badUrl = "jdbc:mysql://badhost/AccountMetadata";
    DbEndpoint localGoodEndpoint =
        new DbEndpoint(origEndpoint.getUrl(), localDc, false, origEndpoint.getUsername(), origEndpoint.getPassword());
    DbEndpoint remoteBadEndpoint =
        new DbEndpoint(badUrl, remoteDc, true, origEndpoint.getUsername(), origEndpoint.getPassword());
    JSONArray endpointsJson = new JSONArray().put(localGoodEndpoint.toJson()).put(remoteBadEndpoint.toJson());
    mySqlConfigProps.setProperty(DB_INFO, endpointsJson.toString());
    mySqlConfigProps.setProperty(ClusterMapConfig.CLUSTERMAP_DATACENTER_NAME, localDc);
    mySqlAccountStore = spy(new MySqlAccountStoreFactory(new VerifiableProperties(mySqlConfigProps),
        new MetricRegistry()).getMySqlAccountStore());
    when(mockMySqlAccountStoreFactory.getMySqlAccountStore()).thenReturn(mySqlAccountStore);
    // constructor does initial fetch which will fail on first endpoint and succeed on second
    AccountServiceMetricsWrapper accountServiceMetricsWrapper = new AccountServiceMetricsWrapper(new MetricRegistry());
    mySqlAccountService =
        new MySqlAccountService(accountServiceMetricsWrapper, accountServiceConfig, mockMySqlAccountStoreFactory,
            mockNotifier);
    MySqlMetrics storeMetrics = mySqlAccountStore.getMySqlDataAccessor().getMetrics();
    // At this point, should have at least one connection failure (bad endpoint) and one success
    long expectedConnectionFail = storeMetrics.connectionFailureCount.getCount();
    long expectedConnectionSuccess = storeMetrics.connectionSuccessCount.getCount();
    assertTrue(expectedConnectionFail > 0);
    assertTrue(expectedConnectionSuccess > 0);
    // Try to update, should fail to get connection
    Account account = makeTestAccountWithContainer();
    try {
      mySqlAccountService.updateAccounts(Collections.singletonList(account));
      fail("Expected failure due to no writeable accounts");
    } catch (AccountServiceException ase) {
      assertEquals(AccountServiceErrorCode.InternalError, ase.getErrorCode());
    }
    expectedConnectionFail++;
    assertEquals(1, accountServiceMetricsWrapper.getAccountServiceMetrics().updateAccountErrorCount.getCount());
    assertEquals(expectedConnectionFail, storeMetrics.connectionFailureCount.getCount());
    assertEquals(expectedConnectionSuccess, storeMetrics.connectionSuccessCount.getCount());
    mySqlAccountService.fetchAndUpdateCache();
  }
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/integration-test/java/com/github/ambry/account/MySqlAccountServiceIntegrationTest.java