Search in sources :

Example 1 with ConnectionFactoryMetadata

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

the class SingleConnectionFactoryUnitTests method releaseConnectionShouldNotCloseConnection.

@Test
void releaseConnectionShouldNotCloseConnection() {
    Connection connectionMock = mock(Connection.class);
    ConnectionFactoryMetadata metadata = mock(ConnectionFactoryMetadata.class);
    SingleConnectionFactory factory = new SingleConnectionFactory(connectionMock, metadata, true);
    Connection connection = factory.create().block();
    ConnectionFactoryUtils.releaseConnection(connection, factory).as(StepVerifier::create).verifyComplete();
    verify(connectionMock, never()).close();
}
Also used : Connection(io.r2dbc.spi.Connection) H2Connection(io.r2dbc.h2.H2Connection) ConnectionFactoryMetadata(io.r2dbc.spi.ConnectionFactoryMetadata) Test(org.junit.jupiter.api.Test)

Example 2 with ConnectionFactoryMetadata

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

the class SingleConnectionFactoryUnitTests method releaseConnectionShouldCloseUnrelatedConnection.

@Test
void releaseConnectionShouldCloseUnrelatedConnection() {
    Connection connectionMock = mock(Connection.class);
    Connection otherConnection = mock(Connection.class);
    ConnectionFactoryMetadata metadata = mock(ConnectionFactoryMetadata.class);
    when(otherConnection.close()).thenReturn(Mono.empty());
    SingleConnectionFactory factory = new SingleConnectionFactory(connectionMock, metadata, false);
    factory.create().as(StepVerifier::create).expectNextCount(1).verifyComplete();
    ConnectionFactoryUtils.releaseConnection(otherConnection, factory).as(StepVerifier::create).verifyComplete();
    verify(otherConnection).close();
}
Also used : Connection(io.r2dbc.spi.Connection) H2Connection(io.r2dbc.h2.H2Connection) StepVerifier(reactor.test.StepVerifier) ConnectionFactoryMetadata(io.r2dbc.spi.ConnectionFactoryMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

H2Connection (io.r2dbc.h2.H2Connection)2 Connection (io.r2dbc.spi.Connection)2 ConnectionFactoryMetadata (io.r2dbc.spi.ConnectionFactoryMetadata)2 Test (org.junit.jupiter.api.Test)2 StepVerifier (reactor.test.StepVerifier)1