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);
}
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);
}
Aggregations