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);
}
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();
}
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);
}
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);
}
Aggregations