diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java index 33a9b6bf8238..c378b52b8170 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java @@ -176,6 +176,7 @@ public static Mono doReleaseConnection(Connection connection, ConnectionFa if (conHolder != null && connectionEquals(conHolder, connection)) { // It's the transactional Connection: Don't close it. conHolder.released(); + return Mono.empty(); } return Mono.from(connection.close()); }).onErrorResume(NoTransactionException.class, ex -> Mono.from(connection.close())); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java index 83a0d13e9431..15fafccafe8a 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,14 +54,16 @@ class TransactionAwareConnectionFactoryProxyUnitTests { R2dbcTransactionManager tm; + @BeforeEach - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) void before() { when(connectionFactoryMock.create()).thenReturn((Mono) Mono.just(connectionMock1), (Mono) Mono.just(connectionMock2), (Mono) Mono.just(connectionMock3)); tm = new R2dbcTransactionManager(connectionFactoryMock); } + @Test void createShouldWrapConnection() { new TransactionAwareConnectionFactoryProxy(connectionFactoryMock).create() @@ -143,14 +145,15 @@ void shouldEmitBoundConnection() { 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(rxtx::transactional) .as(StepVerifier::create) .verifyComplete(); + verify(connectionFactoryMock, times(1)).create(); + verify(connectionMock1, times(1)).close(); verifyNoInteractions(connectionMock2); verifyNoInteractions(connectionMock3); - verify(connectionFactoryMock, times(1)).create(); } }