Search in sources :

Example 1 with Wrapped

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

the class TransactionAwareConnectionFactoryProxyUnitTests method shouldEmitBoundConnection.

@Test
void shouldEmitBoundConnection() {
    when(connectionMock1.beginTransaction()).thenReturn(Mono.empty());
    when(connectionMock1.commitTransaction()).thenReturn(Mono.empty());
    when(connectionMock1.close()).thenReturn(Mono.empty());
    TransactionalOperator rxtx = TransactionalOperator.create(tm);
    AtomicReference<Connection> transactionalConnection = new AtomicReference<>();
    TransactionAwareConnectionFactoryProxy proxyCf = new TransactionAwareConnectionFactoryProxy(connectionFactoryMock);
    ConnectionFactoryUtils.getConnection(connectionFactoryMock).doOnNext(transactionalConnection::set).flatMap(connection -> proxyCf.create().doOnNext(wrappedConnection -> assertThat(((Wrapped<?>) wrappedConnection).unwrap()).isSameAs(connection))).as(rxtx::transactional).flatMapMany(Connection::close).as(StepVerifier::create).verifyComplete();
    verifyNoInteractions(connectionMock2);
    verifyNoInteractions(connectionMock3);
    verify(connectionFactoryMock, times(1)).create();
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) StepVerifier(reactor.test.StepVerifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) BDDMockito.times(org.mockito.BDDMockito.times) Mono(reactor.core.publisher.Mono) AtomicReference(java.util.concurrent.atomic.AtomicReference) BDDMockito.when(org.mockito.BDDMockito.when) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) BDDMockito.verify(org.mockito.BDDMockito.verify) Wrapped(io.r2dbc.spi.Wrapped) BDDMockito.mock(org.mockito.BDDMockito.mock) BDDMockito.verifyNoInteractions(org.mockito.BDDMockito.verifyNoInteractions) Wrapped(io.r2dbc.spi.Wrapped) Connection(io.r2dbc.spi.Connection) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 2 with Wrapped

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

the class SingleConnectionFactoryUnitTests method shouldSuppressClose.

@Test
@SuppressWarnings("rawtypes")
void shouldSuppressClose() {
    SingleConnectionFactory factory = new SingleConnectionFactory("r2dbc:h2:mem:///foo", true);
    Connection connection = factory.create().block();
    StepVerifier.create(connection.close()).verifyComplete();
    assertThat(connection).isInstanceOf(Wrapped.class);
    assertThat(((Wrapped) connection).unwrap()).isInstanceOf(H2Connection.class);
    StepVerifier.create(connection.setTransactionIsolationLevel(IsolationLevel.READ_COMMITTED)).verifyComplete();
    factory.destroy();
}
Also used : Wrapped(io.r2dbc.spi.Wrapped) Connection(io.r2dbc.spi.Connection) H2Connection(io.r2dbc.h2.H2Connection) Test(org.junit.jupiter.api.Test)

Aggregations

Connection (io.r2dbc.spi.Connection)2 Wrapped (io.r2dbc.spi.Wrapped)2 Test (org.junit.jupiter.api.Test)2 H2Connection (io.r2dbc.h2.H2Connection)1 ConnectionFactory (io.r2dbc.spi.ConnectionFactory)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 BDDMockito.mock (org.mockito.BDDMockito.mock)1 BDDMockito.times (org.mockito.BDDMockito.times)1 BDDMockito.verify (org.mockito.BDDMockito.verify)1 BDDMockito.verifyNoInteractions (org.mockito.BDDMockito.verifyNoInteractions)1 BDDMockito.when (org.mockito.BDDMockito.when)1 TransactionalOperator (org.springframework.transaction.reactive.TransactionalOperator)1 Mono (reactor.core.publisher.Mono)1 StepVerifier (reactor.test.StepVerifier)1