23
23
import io .r2dbc .spi .ConnectionFactory ;
24
24
import io .r2dbc .spi .IsolationLevel ;
25
25
import io .r2dbc .spi .R2dbcBadGrammarException ;
26
- import io .r2dbc .spi .R2dbcTimeoutException ;
27
26
import io .r2dbc .spi .Statement ;
28
27
import org .junit .jupiter .api .BeforeEach ;
29
28
import org .junit .jupiter .api .Test ;
56
55
* Unit tests for {@link R2dbcTransactionManager}.
57
56
*
58
57
* @author Mark Paluch
58
+ * @author Juergen Hoeller
59
59
*/
60
60
class R2dbcTransactionManagerUnitTests {
61
61
@@ -67,7 +67,7 @@ class R2dbcTransactionManagerUnitTests {
67
67
68
68
69
69
@ BeforeEach
70
- @ SuppressWarnings ({ "unchecked" , "rawtypes" })
70
+ @ SuppressWarnings ({"unchecked" , "rawtypes" })
71
71
void before () {
72
72
when (connectionFactoryMock .create ()).thenReturn ((Mono ) Mono .just (connectionMock ));
73
73
when (connectionMock .beginTransaction (any (io .r2dbc .spi .TransactionDefinition .class ))).thenReturn (Mono .empty ());
@@ -96,7 +96,6 @@ void testSimpleTransaction() {
96
96
.verifyComplete ();
97
97
98
98
assertThat (commits ).hasValue (1 );
99
- verify (connectionMock ).isAutoCommit ();
100
99
verify (connectionMock ).beginTransaction (any (io .r2dbc .spi .TransactionDefinition .class ));
101
100
verify (connectionMock ).commitTransaction ();
102
101
verify (connectionMock ).close ();
@@ -185,7 +184,6 @@ void doesNotSetIsolationLevelIfMatch() {
185
184
186
185
@ Test
187
186
void doesNotSetAutoCommitDisabled () {
188
- when (connectionMock .isAutoCommit ()).thenReturn (false );
189
187
when (connectionMock .commitTransaction ()).thenReturn (Mono .empty ());
190
188
191
189
DefaultTransactionDefinition definition = new DefaultTransactionDefinition ();
@@ -203,29 +201,6 @@ void doesNotSetAutoCommitDisabled() {
203
201
verify (connectionMock ).commitTransaction ();
204
202
}
205
203
206
- @ Test
207
- void restoresAutoCommit () {
208
- when (connectionMock .isAutoCommit ()).thenReturn (true );
209
- when (connectionMock .setAutoCommit (anyBoolean ())).thenReturn (Mono .empty ());
210
- when (connectionMock .commitTransaction ()).thenReturn (Mono .empty ());
211
-
212
- DefaultTransactionDefinition definition = new DefaultTransactionDefinition ();
213
-
214
- TransactionalOperator operator = TransactionalOperator .create (tm , definition );
215
-
216
- ConnectionFactoryUtils .getConnection (connectionFactoryMock ).as (
217
- operator ::transactional )
218
- .as (StepVerifier ::create )
219
- .expectNextCount (1 )
220
- .verifyComplete ();
221
-
222
- verify (connectionMock ).beginTransaction (any (io .r2dbc .spi .TransactionDefinition .class ));
223
- verify (connectionMock ).setAutoCommit (false );
224
- verify (connectionMock ).setAutoCommit (true );
225
- verify (connectionMock ).commitTransaction ();
226
- verify (connectionMock ).close ();
227
- }
228
-
229
204
@ Test
230
205
void appliesReadOnly () {
231
206
when (connectionMock .commitTransaction ()).thenReturn (Mono .empty ());
@@ -246,7 +221,6 @@ void appliesReadOnly() {
246
221
.expectNextCount (1 )
247
222
.verifyComplete ();
248
223
249
- verify (connectionMock ).isAutoCommit ();
250
224
verify (connectionMock ).beginTransaction (any (io .r2dbc .spi .TransactionDefinition .class ));
251
225
verify (connectionMock ).createStatement ("SET TRANSACTION READ ONLY" );
252
226
verify (connectionMock ).commitTransaction ();
@@ -268,7 +242,6 @@ void testCommitFails() {
268
242
.as (StepVerifier ::create )
269
243
.verifyError (BadSqlGrammarException .class );
270
244
271
- verify (connectionMock ).isAutoCommit ();
272
245
verify (connectionMock ).beginTransaction (any (io .r2dbc .spi .TransactionDefinition .class ));
273
246
verify (connectionMock ).createStatement ("foo" );
274
247
verify (connectionMock ).commitTransaction ();
@@ -299,7 +272,6 @@ void testRollback() {
299
272
300
273
assertThat (commits ).hasValue (0 );
301
274
assertThat (rollbacks ).hasValue (1 );
302
- verify (connectionMock ).isAutoCommit ();
303
275
verify (connectionMock ).beginTransaction (any (io .r2dbc .spi .TransactionDefinition .class ));
304
276
verify (connectionMock ).rollbackTransaction ();
305
277
verify (connectionMock ).close ();
@@ -322,7 +294,6 @@ void testRollbackFails() {
322
294
}).as (StepVerifier ::create )
323
295
.verifyError (BadSqlGrammarException .class );
324
296
325
- verify (connectionMock ).isAutoCommit ();
326
297
verify (connectionMock ).beginTransaction (any (io .r2dbc .spi .TransactionDefinition .class ));
327
298
verify (connectionMock ).createStatement ("foo" );
328
299
verify (connectionMock , never ()).commitTransaction ();
@@ -338,10 +309,7 @@ void testConnectionReleasedWhenRollbackFails() {
338
309
339
310
TransactionalOperator operator = TransactionalOperator .create (tm );
340
311
341
- when (connectionMock .isAutoCommit ()).thenReturn (true );
342
- when (connectionMock .setAutoCommit (true )).thenReturn (Mono .defer (() -> Mono .error (new R2dbcTimeoutException ("SET AUTOCOMMIT = 1 timed out" ))));
343
312
when (connectionMock .setTransactionIsolationLevel (any ())).thenReturn (Mono .empty ());
344
- when (connectionMock .setAutoCommit (false )).thenReturn (Mono .empty ());
345
313
346
314
operator .execute (reactiveTransaction -> ConnectionFactoryUtils .getConnection (connectionFactoryMock )
347
315
.doOnNext (connection -> {
@@ -352,7 +320,6 @@ void testConnectionReleasedWhenRollbackFails() {
352
320
.hasCause (new R2dbcBadGrammarException ("Rollback should fail" ))
353
321
);
354
322
355
- verify (connectionMock ).isAutoCommit ();
356
323
verify (connectionMock ).beginTransaction (any (io .r2dbc .spi .TransactionDefinition .class ));
357
324
verify (connectionMock , never ()).commitTransaction ();
358
325
verify (connectionMock ).rollbackTransaction ();
@@ -380,7 +347,6 @@ void testTransactionSetRollbackOnly() {
380
347
}).as (StepVerifier ::create )
381
348
.verifyComplete ();
382
349
383
- verify (connectionMock ).isAutoCommit ();
384
350
verify (connectionMock ).beginTransaction (any (io .r2dbc .spi .TransactionDefinition .class ));
385
351
verify (connectionMock ).rollbackTransaction ();
386
352
verify (connectionMock ).close ();
0 commit comments