Search in sources :

Example 21 with PoolableDataSource

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);
}
Also used : PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

Example 22 with PoolableDataSource

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;
}
Also used : Properties(java.util.Properties) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource)

Example 23 with PoolableDataSource

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);
    }
}
Also used : SQLException(java.sql.SQLException) JDBCObjectStore(com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

Example 24 with PoolableDataSource

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);
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) JDBCObjectStore(com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

Example 25 with PoolableDataSource

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;
}
Also used : Properties(java.util.Properties) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource)

Aggregations

PoolableDataSource (com.yahoo.athenz.common.server.db.PoolableDataSource)30 Test (org.testng.annotations.Test)22 Connection (java.sql.Connection)11 JDBCObjectStore (com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore)7 SQLException (java.sql.SQLException)7 JDBCObjectStore (com.yahoo.athenz.zms.store.jdbc.JDBCObjectStore)5 Properties (java.util.Properties)4 Principal (com.yahoo.athenz.auth.Principal)2 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)2 RolesProvider (com.yahoo.athenz.common.server.db.RolesProvider)2 NotificationManager (com.yahoo.athenz.common.server.notification.NotificationManager)2 ResourceException (com.yahoo.athenz.zms.ResourceException)2 File (java.io.File)1 IOException (java.io.IOException)1 X509Certificate (java.security.cert.X509Certificate)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1