Search in sources :

Example 1 with MySqlDataAccessor

use of com.github.ambry.mysql.MySqlDataAccessor in project ambry by linkedin.

the class DatabaseTest method perfTest.

private static void perfTest(VerifiableProperties verifiableProperties) throws Exception {
    MySqlDataAccessor dataAccessor = new MySqlAccountStoreFactory(verifiableProperties, new MetricRegistry()).getMySqlAccountStore().getMySqlDataAccessor();
    AccountDao accountDao = new AccountDao(dataAccessor);
    // Use high account id to avoid conflict
    short startAccountId = 30000;
    int numAccounts = 10;
    int numContainers = 1000;
    cleanup(dataAccessor.getDatabaseConnection(true), startAccountId);
    ContainerBuilder builder = new ContainerBuilder((short) 0, "", Container.ContainerStatus.ACTIVE, "Test", (short) 0);
    long t0 = System.currentTimeMillis();
    int containersAdded = 0;
    List<AccountUpdateInfo> accountUpdateInfos = new ArrayList<>();
    for (short accountId = startAccountId; accountId < startAccountId + numAccounts; accountId++) {
        Account account = new AccountBuilder(accountId, "Account-" + accountId, Account.AccountStatus.ACTIVE).build();
        List<Container> containers = new ArrayList<>();
        for (short containerId = 1; containerId <= numContainers; containerId++) {
            containers.add(builder.setId(containerId).setParentAccountId(accountId).setName("Container-" + containerId).setTtlRequired(true).build());
            containersAdded++;
        }
        accountUpdateInfos.add(new AccountUpdateInfo(account, true, false, containers, new ArrayList<>()));
    }
    accountDao.updateAccounts(accountUpdateInfos, 100);
    long t1 = System.currentTimeMillis();
    long insertTime = t1 - t0;
    logger.info("Added {} containers in {} ms", containersAdded, insertTime);
    // Query containers since t0 (should be all)
    List<Container> allContainers = accountDao.getNewContainers(t0);
    long t2 = System.currentTimeMillis();
    logger.info("Queried {} containers in {} ms", allContainers.size(), t2 - t1);
    // Query containers since t2 (should be none)
    allContainers = accountDao.getNewContainers(t2);
    long t3 = System.currentTimeMillis();
    logger.info("Queried {} containers in {} ms", allContainers.size(), t3 - t2);
}
Also used : MySqlDataAccessor(com.github.ambry.mysql.MySqlDataAccessor) MetricRegistry(com.codahale.metrics.MetricRegistry) ArrayList(java.util.ArrayList) AccountDao(com.github.ambry.account.mysql.AccountDao) MySqlAccountStoreFactory(com.github.ambry.account.mysql.MySqlAccountStoreFactory) AccountUpdateInfo(com.github.ambry.account.AccountUtils.AccountUpdateInfo)

Example 2 with MySqlDataAccessor

use of com.github.ambry.mysql.MySqlDataAccessor in project ambry by linkedin.

the class AccountDaoTest method getDataAccessor.

/**
 * Utility to get a {@link MySqlDataAccessor}.
 * @param mockConnection the connection to use.
 * @return the {@link MySqlDataAccessor}.
 * @throws SQLException
 */
static MySqlDataAccessor getDataAccessor(Connection mockConnection, MySqlMetrics metrics) throws SQLException {
    Driver mockDriver = mock(Driver.class);
    when(mockDriver.connect(anyString(), any(Properties.class))).thenReturn(mockConnection);
    MySqlUtils.DbEndpoint dbEndpoint = new MySqlUtils.DbEndpoint("jdbc:mysql://localhost/AccountMetadata", "dc1", true, "ambry", "ambry");
    return new MySqlDataAccessor(Collections.singletonList(dbEndpoint), mockDriver, metrics);
}
Also used : MySqlDataAccessor(com.github.ambry.mysql.MySqlDataAccessor) Driver(java.sql.Driver) Properties(java.util.Properties) MySqlUtils(com.github.ambry.mysql.MySqlUtils)

Aggregations

MySqlDataAccessor (com.github.ambry.mysql.MySqlDataAccessor)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 AccountUpdateInfo (com.github.ambry.account.AccountUtils.AccountUpdateInfo)1 AccountDao (com.github.ambry.account.mysql.AccountDao)1 MySqlAccountStoreFactory (com.github.ambry.account.mysql.MySqlAccountStoreFactory)1 MySqlUtils (com.github.ambry.mysql.MySqlUtils)1 Driver (java.sql.Driver)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1