use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.
the class DataSourceFactoryTest method testCreateDataSourceWithFactory.
@Test
public void testCreateDataSourceWithFactory() {
System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TTL, "10000");
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 JDBCCertRecordStoreFactory method create.
@Override
public CertRecordStore create(PrivateKeyStore keyStore) {
final String jdbcStore = System.getProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_STORE);
final String jdbcUser = System.getProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_USER);
final String password = System.getProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_PASSWORD, "");
final String jdbcAppName = System.getProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_APP_NAME, JDBC);
String jdbcPassword = keyStore.getApplicationSecret(jdbcAppName, password);
Properties props = new Properties();
props.setProperty(ZTSConsts.DB_PROP_USER, jdbcUser);
props.setProperty(ZTSConsts.DB_PROP_PASSWORD, jdbcPassword);
props.setProperty(ZTSConsts.DB_PROP_VERIFY_SERVER_CERT, System.getProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_VERIFY_SERVER_CERT, "false"));
props.setProperty(ZTSConsts.DB_PROP_USE_SSL, System.getProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_USE_SSL, "false"));
PoolableDataSource src = DataSourceFactory.create(jdbcStore, props);
// set default timeout for our connections
JDBCCertRecordStore certStore = new JDBCCertRecordStore(src);
int opTimeout = Integer.parseInt(System.getProperty(ZTSConsts.ZTS_PROP_CERT_OP_TIMEOUT, "10"));
certStore.setOperationTimeout(opTimeout);
return certStore;
}
use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.
the class JDBCObjectStoreTest method testGetConnectionException.
@Test
public void testGetConnectionException() throws SQLException {
PoolableDataSource mockDataRwSrc = Mockito.mock(PoolableDataSource.class);
Mockito.doThrow(new SQLException()).when(mockDataRwSrc).getConnection();
PoolableDataSource mockDataRoSrc = Mockito.mock(PoolableDataSource.class);
Mockito.doThrow(new SQLException()).when(mockDataRoSrc).getConnection();
try {
JDBCObjectStore store = new JDBCObjectStore(mockDataRwSrc, mockDataRoSrc);
store.getConnection(true, true);
fail();
} catch (RuntimeException ex) {
assertTrue(true);
}
try {
JDBCObjectStore store = new JDBCObjectStore(mockDataRwSrc, mockDataRoSrc);
store.getConnection(true, true);
fail();
} catch (RuntimeException ex) {
assertTrue(true);
}
}
use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.
the class JDBCObjectStoreTest method testGetReadWriteConnectionException.
@Test
public void testGetReadWriteConnectionException() throws SQLException {
PoolableDataSource mockDataRwSrc = Mockito.mock(PoolableDataSource.class);
Connection mockConn = Mockito.mock(Connection.class);
Mockito.doReturn(mockConn).when(mockDataRwSrc).getConnection();
PoolableDataSource mockDataRoSrc = Mockito.mock(PoolableDataSource.class);
Mockito.doThrow(new SQLException()).when(mockDataRoSrc).getConnection();
JDBCObjectStore store = new JDBCObjectStore(mockDataRwSrc, mockDataRoSrc);
// we should get back same read-write connection for both cases
JDBCConnection jdbcConn = (JDBCConnection) store.getConnection(true, true);
assertEquals(jdbcConn.con, mockConn);
jdbcConn = (JDBCConnection) store.getConnection(true, false);
assertEquals(jdbcConn.con, mockConn);
}
use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.
the class JDBCSSHRecordStoreFactory method create.
@Override
public SSHRecordStore create(PrivateKeyStore keyStore) {
final String jdbcStore = System.getProperty(ZTSConsts.ZTS_PROP_SSH_JDBC_STORE);
final String jdbcUser = System.getProperty(ZTSConsts.ZTS_PROP_SSH_JDBC_USER);
final String password = System.getProperty(ZTSConsts.ZTS_PROP_SSH_JDBC_PASSWORD, "");
final String jdbcAppName = System.getProperty(ZTSConsts.ZTS_PROP_SSH_JDBC_APP_NAME, JDBC);
String jdbcPassword = keyStore.getApplicationSecret(jdbcAppName, password);
Properties props = new Properties();
props.setProperty(ZTSConsts.DB_PROP_USER, jdbcUser);
props.setProperty(ZTSConsts.DB_PROP_PASSWORD, jdbcPassword);
props.setProperty(ZTSConsts.DB_PROP_VERIFY_SERVER_CERT, System.getProperty(ZTSConsts.ZTS_PROP_SSH_JDBC_VERIFY_SERVER_CERT, "false"));
props.setProperty(ZTSConsts.DB_PROP_USE_SSL, System.getProperty(ZTSConsts.ZTS_PROP_SSH_JDBC_USE_SSL, "false"));
PoolableDataSource src = DataSourceFactory.create(jdbcStore, props);
// set default timeout for our connections
JDBCSSHRecordStore certStore = new JDBCSSHRecordStore(src);
int opTimeout = Integer.parseInt(System.getProperty(ZTSConsts.ZTS_PROP_SSH_OP_TIMEOUT, "10"));
certStore.setOperationTimeout(opTimeout);
return certStore;
}
Aggregations