use of com.github.ambry.mysql.MySqlMetrics in project ambry by linkedin.
the class MySqlAccountServiceIntegrationTest method testFailover.
@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
AccountServiceMetrics accountServiceMetrics = new AccountServiceMetrics(new MetricRegistry());
mySqlAccountService = new MySqlAccountService(accountServiceMetrics, 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, accountServiceMetrics.updateAccountErrorCount.getCount());
assertEquals(expectedConnectionFail, storeMetrics.connectionFailureCount.getCount());
assertEquals(expectedConnectionSuccess, storeMetrics.connectionSuccessCount.getCount());
mySqlAccountService.fetchAndUpdateCache();
}
use of com.github.ambry.mysql.MySqlMetrics in project ambry by linkedin.
the class MySqlAccountServiceIntegrationTest method testBadCredentials.
@Test
public void testBadCredentials() throws Exception {
DbEndpoint endpoint = new DbEndpoint("jdbc:mysql://localhost/AccountMetadata", "dc1", true, "baduser", "badpassword");
try {
new MySqlAccountStore(Collections.singletonList(endpoint), endpoint.getDatacenter(), new MySqlMetrics(MySqlAccountStore.class, new MetricRegistry()), accountServiceConfig);
fail("Store creation should fail with bad credentials");
} catch (SQLException e) {
assertTrue(MySqlDataAccessor.isCredentialError(e));
}
}
Aggregations