Search in sources :

Example 16 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCWorkloadRecordStoreTest method testGetConnection.

@Test
public void testGetConnection() throws SQLException {
    PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
    Connection mockConn = Mockito.mock(Connection.class);
    Mockito.doReturn(mockConn).when(mockDataSrc).getConnection();
    JDBCWorkloadRecordStore store = new JDBCWorkloadRecordStore(mockDataSrc);
    assertNotNull(store.getConnection());
    store.setOperationTimeout(20);
    store.clearConnections();
}
Also used : Connection(java.sql.Connection) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

Example 17 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.jdbc.JDBCObjectStore) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

Example 18 with PoolableDataSource

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

Example 19 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCObjectStoreTest method testGetConnectionReadOnly.

@Test
public void testGetConnectionReadOnly() throws SQLException {
    PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
    Connection mockConn = Mockito.mock(Connection.class);
    Mockito.doReturn(mockConn).when(mockDataSrc).getConnection();
    JDBCObjectStore store = new JDBCObjectStore(null, mockDataSrc);
    assertNotNull(store.getConnection(true, false));
}
Also used : Connection(java.sql.Connection) JDBCObjectStore(com.yahoo.athenz.zms.store.jdbc.JDBCObjectStore) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

Example 20 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.jdbc.JDBCObjectStore) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

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