Search in sources :

Example 6 with JDBCObjectStore

use of com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore 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 7 with JDBCObjectStore

use of com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore 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)

Aggregations

PoolableDataSource (com.yahoo.athenz.common.server.db.PoolableDataSource)7 JDBCObjectStore (com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore)7 Test (org.testng.annotations.Test)5 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)1