Search in sources :

Example 6 with ConcurrencyFailureException

use of cn.taketoday.dao.ConcurrencyFailureException in project today-infrastructure by TAKETODAY.

the class JdbcTransactionManagerTests method testTransactionWithDataAccessExceptionOnCommit.

@Test
public void testTransactionWithDataAccessExceptionOnCommit() throws Exception {
    willThrow(new SQLException("Cannot commit")).given(con).commit();
    tm.setExceptionTranslator((task, sql, ex) -> new ConcurrencyFailureException(task));
    TransactionTemplate tt = new TransactionTemplate(tm);
    assertThatExceptionOfType(ConcurrencyFailureException.class).isThrownBy(() -> tt.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
        // something transactional
        }
    }));
    boolean condition = !TransactionSynchronizationManager.hasResource(ds);
    assertThat(condition).as("Hasn't thread connection").isTrue();
    verify(con).close();
}
Also used : SQLException(java.sql.SQLException) UncategorizedSQLException(cn.taketoday.jdbc.UncategorizedSQLException) ConcurrencyFailureException(cn.taketoday.dao.ConcurrencyFailureException) TransactionTemplate(cn.taketoday.transaction.support.TransactionTemplate) TransactionStatus(cn.taketoday.transaction.TransactionStatus) TransactionCallbackWithoutResult(cn.taketoday.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ConcurrencyFailureException (cn.taketoday.dao.ConcurrencyFailureException)6 SQLException (java.sql.SQLException)6 Test (org.junit.jupiter.api.Test)6 UncategorizedSQLException (cn.taketoday.jdbc.UncategorizedSQLException)4 TransactionStatus (cn.taketoday.transaction.TransactionStatus)4 TransactionCallbackWithoutResult (cn.taketoday.transaction.support.TransactionCallbackWithoutResult)4 TransactionTemplate (cn.taketoday.transaction.support.TransactionTemplate)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 DataAccessResourceFailureException (cn.taketoday.dao.DataAccessResourceFailureException)2 DataIntegrityViolationException (cn.taketoday.dao.DataIntegrityViolationException)2 InvalidDataAccessApiUsageException (cn.taketoday.dao.InvalidDataAccessApiUsageException)2 PermissionDeniedDataAccessException (cn.taketoday.dao.PermissionDeniedDataAccessException)2 QueryTimeoutException (cn.taketoday.dao.QueryTimeoutException)2 RecoverableDataAccessException (cn.taketoday.dao.RecoverableDataAccessException)2 TransientDataAccessResourceException (cn.taketoday.dao.TransientDataAccessResourceException)2 BadSqlGrammarException (cn.taketoday.jdbc.BadSqlGrammarException)2 InOrder (org.mockito.InOrder)2