Search in sources :

Example 1 with R2dbcBadGrammarException

use of io.r2dbc.spi.R2dbcBadGrammarException in project spring-framework by spring-projects.

the class ConnectionFactoryUtilsUnitTests method shouldTranslateBadSqlGrammarException.

@Test
public void shouldTranslateBadSqlGrammarException() {
    Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "", new R2dbcBadGrammarException());
    assertThat(exception).isInstanceOf(BadSqlGrammarException.class);
}
Also used : R2dbcBadGrammarException(io.r2dbc.spi.R2dbcBadGrammarException) R2dbcDataIntegrityViolationException(io.r2dbc.spi.R2dbcDataIntegrityViolationException) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) R2dbcException(io.r2dbc.spi.R2dbcException) R2dbcRollbackException(io.r2dbc.spi.R2dbcRollbackException) R2dbcTransientResourceException(io.r2dbc.spi.R2dbcTransientResourceException) UncategorizedR2dbcException(org.springframework.r2dbc.UncategorizedR2dbcException) R2dbcTimeoutException(io.r2dbc.spi.R2dbcTimeoutException) R2dbcBadGrammarException(io.r2dbc.spi.R2dbcBadGrammarException) QueryTimeoutException(org.springframework.dao.QueryTimeoutException) BadSqlGrammarException(org.springframework.r2dbc.BadSqlGrammarException) R2dbcPermissionDeniedException(io.r2dbc.spi.R2dbcPermissionDeniedException) TransientDataAccessResourceException(org.springframework.dao.TransientDataAccessResourceException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) PermissionDeniedDataAccessException(org.springframework.dao.PermissionDeniedDataAccessException) R2dbcNonTransientResourceException(io.r2dbc.spi.R2dbcNonTransientResourceException) Test(org.junit.jupiter.api.Test)

Example 2 with R2dbcBadGrammarException

use of io.r2dbc.spi.R2dbcBadGrammarException in project spring-framework by spring-projects.

the class R2dbcTransactionManagerUnitTests method testBeginFails.

@Test
void testBeginFails() {
    reset(connectionFactoryMock);
    when(connectionFactoryMock.create()).thenReturn(Mono.error(new R2dbcBadGrammarException("fail")));
    when(connectionMock.rollbackTransaction()).thenReturn(Mono.empty());
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    definition.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
    TransactionalOperator operator = TransactionalOperator.create(tm, definition);
    ConnectionFactoryUtils.getConnection(connectionFactoryMock).as(operator::transactional).as(StepVerifier::create).expectErrorSatisfies(actual -> assertThat(actual).isInstanceOf(CannotCreateTransactionException.class).hasCauseInstanceOf(R2dbcBadGrammarException.class)).verify();
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) TransactionDefinition(org.springframework.transaction.TransactionDefinition) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IllegalTransactionStateException(org.springframework.transaction.IllegalTransactionStateException) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) BDDMockito.when(org.mockito.BDDMockito.when) BDDMockito.verify(org.mockito.BDDMockito.verify) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionSynchronization(org.springframework.transaction.reactive.TransactionSynchronization) BDDMockito.never(org.mockito.BDDMockito.never) R2dbcBadGrammarException(io.r2dbc.spi.R2dbcBadGrammarException) TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) Mono(reactor.core.publisher.Mono) BDDMockito.verifyNoMoreInteractions(org.mockito.BDDMockito.verifyNoMoreInteractions) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) TransactionSynchronizationManager(org.springframework.transaction.reactive.TransactionSynchronizationManager) IsolationLevel(io.r2dbc.spi.IsolationLevel) Assertions.fail(org.assertj.core.api.Assertions.fail) BDDMockito.mock(org.mockito.BDDMockito.mock) Statement(io.r2dbc.spi.Statement) BDDMockito.reset(org.mockito.BDDMockito.reset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) R2dbcBadGrammarException(io.r2dbc.spi.R2dbcBadGrammarException) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 3 with R2dbcBadGrammarException

use of io.r2dbc.spi.R2dbcBadGrammarException in project spring-framework by spring-projects.

the class R2dbcTransactionManagerUnitTests method testCommitFails.

@Test
void testCommitFails() {
    when(connectionMock.commitTransaction()).thenReturn(Mono.defer(() -> Mono.error(new R2dbcBadGrammarException("Commit should fail"))));
    when(connectionMock.rollbackTransaction()).thenReturn(Mono.empty());
    TransactionalOperator operator = TransactionalOperator.create(tm);
    ConnectionFactoryUtils.getConnection(connectionFactoryMock).doOnNext(connection -> connection.createStatement("foo")).then().as(operator::transactional).as(StepVerifier::create).verifyError(IllegalTransactionStateException.class);
    verify(connectionMock).isAutoCommit();
    verify(connectionMock).beginTransaction();
    verify(connectionMock).createStatement("foo");
    verify(connectionMock).commitTransaction();
    verify(connectionMock).close();
    verifyNoMoreInteractions(connectionMock);
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) R2dbcBadGrammarException(io.r2dbc.spi.R2dbcBadGrammarException) Test(org.junit.jupiter.api.Test)

Example 4 with R2dbcBadGrammarException

use of io.r2dbc.spi.R2dbcBadGrammarException in project spring-framework by spring-projects.

the class R2dbcTransactionManagerUnitTests method testRollbackFails.

@Test
@SuppressWarnings("unchecked")
void testRollbackFails() {
    when(connectionMock.rollbackTransaction()).thenReturn(Mono.defer(() -> Mono.error(new R2dbcBadGrammarException("Commit should fail"))), Mono.empty());
    TransactionalOperator operator = TransactionalOperator.create(tm);
    operator.execute(reactiveTransaction -> {
        reactiveTransaction.setRollbackOnly();
        return ConnectionFactoryUtils.getConnection(connectionFactoryMock).doOnNext(connection -> connection.createStatement("foo")).then();
    }).as(StepVerifier::create).verifyError(IllegalTransactionStateException.class);
    verify(connectionMock).isAutoCommit();
    verify(connectionMock).beginTransaction();
    verify(connectionMock).createStatement("foo");
    verify(connectionMock, never()).commitTransaction();
    verify(connectionMock).rollbackTransaction();
    verify(connectionMock).close();
    verifyNoMoreInteractions(connectionMock);
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) TransactionDefinition(org.springframework.transaction.TransactionDefinition) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IllegalTransactionStateException(org.springframework.transaction.IllegalTransactionStateException) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) BDDMockito.when(org.mockito.BDDMockito.when) BDDMockito.verify(org.mockito.BDDMockito.verify) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionSynchronization(org.springframework.transaction.reactive.TransactionSynchronization) BDDMockito.never(org.mockito.BDDMockito.never) R2dbcBadGrammarException(io.r2dbc.spi.R2dbcBadGrammarException) TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) Mono(reactor.core.publisher.Mono) BDDMockito.verifyNoMoreInteractions(org.mockito.BDDMockito.verifyNoMoreInteractions) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) TransactionSynchronizationManager(org.springframework.transaction.reactive.TransactionSynchronizationManager) IsolationLevel(io.r2dbc.spi.IsolationLevel) Assertions.fail(org.assertj.core.api.Assertions.fail) BDDMockito.mock(org.mockito.BDDMockito.mock) Statement(io.r2dbc.spi.Statement) BDDMockito.reset(org.mockito.BDDMockito.reset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) R2dbcBadGrammarException(io.r2dbc.spi.R2dbcBadGrammarException) Test(org.junit.jupiter.api.Test)

Aggregations

R2dbcBadGrammarException (io.r2dbc.spi.R2dbcBadGrammarException)4 Test (org.junit.jupiter.api.Test)4 TransactionalOperator (org.springframework.transaction.reactive.TransactionalOperator)3 Connection (io.r2dbc.spi.Connection)2 ConnectionFactory (io.r2dbc.spi.ConnectionFactory)2 IsolationLevel (io.r2dbc.spi.IsolationLevel)2 Statement (io.r2dbc.spi.Statement)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.fail (org.assertj.core.api.Assertions.fail)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.anyBoolean (org.mockito.ArgumentMatchers.anyBoolean)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 BDDMockito.mock (org.mockito.BDDMockito.mock)2 BDDMockito.never (org.mockito.BDDMockito.never)2 BDDMockito.reset (org.mockito.BDDMockito.reset)2 BDDMockito.verify (org.mockito.BDDMockito.verify)2 BDDMockito.verifyNoMoreInteractions (org.mockito.BDDMockito.verifyNoMoreInteractions)2 BDDMockito.when (org.mockito.BDDMockito.when)2