Search in sources :

Example 6 with DataSource

use of org.unidal.dal.jdbc.datasource.DataSource in project x-pipe by ctripcorp.

the class DalTransactionManagerTest method testStartTransaction.

@Test
public void testStartTransaction() throws SQLException {
    DataSource ds = mock(DataSource.class);
    when(ds.getConnection()).thenReturn(mock(Connection.class));
    when(m_dataSourceManager.getDataSource("")).thenReturn(ds);
    assertEquals(dalTM.getThreadLocalTransactionInfo().get().isInTransaction(), false);
    dalTM.startTransaction("");
    assertEquals(dalTM.getThreadLocalTransactionInfo().get().getRecursiveLayer(), 1);
    assertEquals(dalTM.getThreadLocalTransactionInfo().get().isInTransaction(), true);
    dalTM.startTransaction("");
    assertEquals(dalTM.getThreadLocalTransactionInfo().get().getRecursiveLayer(), 2);
}
Also used : Connection(java.sql.Connection) DataSource(org.unidal.dal.jdbc.datasource.DataSource) Test(org.junit.Test) AbstractConsoleTest(com.ctrip.xpipe.redis.console.AbstractConsoleTest)

Aggregations

DataSource (org.unidal.dal.jdbc.datasource.DataSource)6 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)3 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)2 Test (org.junit.Test)2 DalRuntimeException (org.unidal.dal.jdbc.DalRuntimeException)2 DataSourceManager (org.unidal.dal.jdbc.datasource.DataSourceManager)2 TableProvider (org.unidal.dal.jdbc.mapping.TableProvider)1