use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.
the class JDBCObjectStoreTest method testGetConnectionReadWriteOnly.
@Test
public void testGetConnectionReadWriteOnly() throws SQLException {
PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
Connection mockConn = Mockito.mock(Connection.class);
Mockito.doReturn(mockConn).when(mockDataSrc).getConnection();
JDBCObjectStore store = new JDBCObjectStore(mockDataSrc, null);
store.setOperationTimeout(60);
assertNotNull(store.getConnection(true, true));
// without read store we should also get a connection for a read
// only operation
assertNotNull(store.getConnection(true, true));
store.clearConnections();
}
use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.
the class JDBCObjectStore method getConnection.
@Override
public ObjectStoreConnection getConnection(boolean autoCommit, boolean readWrite) {
final String caller = "getConnection";
try {
PoolableDataSource src = readWrite ? rwSrc : roSrc;
JDBCConnection jdbcConn = new JDBCConnection(src.getConnection(), autoCommit);
jdbcConn.setOperationTimeout(opTimeout);
return jdbcConn;
} catch (Exception ex) {
if (!readWrite) {
return getConnection(autoCommit, true);
}
throw ZMSUtils.error(ResourceException.SERVICE_UNAVAILABLE, ex.getMessage(), caller);
}
}
use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.
the class DataSourceFactoryTest method testCreateDataSourceWithFactoryInvalidTTL.
@Test
public void testCreateDataSourceWithFactoryInvalidTTL() {
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TTL, "abc");
// we ignore the invalid ttl and everything else should work fine
MockConnectionFactory connectionFactory = new MockConnectionFactory();
PoolableDataSource src = DataSourceFactory.create(connectionFactory);
assertNotNull(src);
System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TTL);
}
use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.
the class AWSCertRecordStoreFactory method create.
@Override
public CertRecordStore create(PrivateKeyStore keyStore) {
rdsUser = System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_USER);
rdsIamRole = System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_IAM_ROLE);
rdsMaster = System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_MASTER_INSTANCE);
rdsPort = Integer.parseInt(System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_MASTER_PORT, "3306"));
final String rdsEngine = System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_ENGINE, "mysql");
final String rdsDatabase = System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_DATABASE, "zts_store");
final String jdbcStore = String.format("jdbc:%s://%s:%d/%s", rdsEngine, rdsMaster, rdsPort, rdsDatabase);
String rdsToken = getAuthToken(rdsMaster, rdsPort, rdsUser, rdsIamRole);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Connecting to {} with auth token {}", jdbcStore, rdsToken);
}
mysqlConnectionProperties.setProperty(ZTSConsts.DB_PROP_VERIFY_SERVER_CERT, System.getProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_VERIFY_SERVER_CERT, "true"));
mysqlConnectionProperties.setProperty(ZTSConsts.DB_PROP_USE_SSL, System.getProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_USE_SSL, "true"));
mysqlConnectionProperties.setProperty(ZTSConsts.DB_PROP_USER, rdsUser);
mysqlConnectionProperties.setProperty(ZTSConsts.DB_PROP_PASSWORD, rdsToken);
PoolableDataSource dataSource = DataSourceFactory.create(jdbcStore, mysqlConnectionProperties);
long credsRefreshTime = Integer.parseInt(System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_CREDS_REFRESH_TIME, "300"));
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1);
scheduledThreadPool.scheduleAtFixedRate(new CredentialsUpdater(), credsRefreshTime, credsRefreshTime, TimeUnit.SECONDS);
return new JDBCCertRecordStore(dataSource);
}
use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.
the class JDBCObjectStoreTest method testGetConnection.
@Test
public void testGetConnection() throws SQLException {
PoolableDataSource mockDataRwSrc = Mockito.mock(PoolableDataSource.class);
Connection rwMockConn = Mockito.mock(Connection.class);
Mockito.doReturn(rwMockConn).when(mockDataRwSrc).getConnection();
PoolableDataSource mockDataRoSrc = Mockito.mock(PoolableDataSource.class);
Connection roMockConn = Mockito.mock(Connection.class);
Mockito.doReturn(roMockConn).when(mockDataRoSrc).getConnection();
JDBCObjectStore store = new JDBCObjectStore(mockDataRwSrc, mockDataRoSrc);
JDBCConnection jdbcConn = (JDBCConnection) store.getConnection(true, true);
assertEquals(jdbcConn.con, rwMockConn);
jdbcConn = (JDBCConnection) store.getConnection(true, false);
assertEquals(jdbcConn.con, roMockConn);
}
Aggregations