36
36
import io .r2dbc .spi .ConnectionFactory ;
37
37
import io .r2dbc .spi .ConnectionFactoryOptions ;
38
38
import io .r2dbc .spi .Option ;
39
+ import io .r2dbc .spi .Result ;
39
40
import io .r2dbc .spi .Statement ;
40
41
import io .r2dbc .spi .test .TestKit ;
41
42
import java .nio .charset .StandardCharsets ;
57
58
import reactor .test .StepVerifier ;
58
59
59
60
/**
60
- * Tests bringing in " TCK" Example.java from r2dbc-spi- test.
61
+ * R2DBC TCK test implementation .
61
62
*/
62
- public class SpannerExample implements TestKit <String > {
63
+ public class SpannerTestKit implements TestKit <String > {
63
64
64
65
private static final ConnectionFactory connectionFactory =
65
66
ConnectionFactories .get (ConnectionFactoryOptions .builder ()
@@ -69,7 +70,7 @@ public class SpannerExample implements TestKit<String> {
69
70
.option (DATABASE , TEST_DATABASE )
70
71
.build ());
71
72
72
- private static final Logger logger = LoggerFactory .getLogger (SpannerExample .class );
73
+ private static final Logger logger = LoggerFactory .getLogger (SpannerTestKit .class );
73
74
74
75
private static final JdbcOperations jdbcOperations ;
75
76
@@ -432,4 +433,48 @@ public void bindNull() {
432
433
.expectNextCount (1 ).as ("rows inserted" )
433
434
.verifyComplete ();
434
435
}
436
+
437
+ @ Override
438
+ @ Test
439
+ public void changeAutoCommitCommitsTransaction () {
440
+ Mono .from (getConnectionFactory ().create ())
441
+ .flatMapMany (connection ->
442
+ Flux .from (connection .setAutoCommit (false ))
443
+ .thenMany (connection .beginTransaction ())
444
+ // DML syntax fix adding column list
445
+ .thenMany (connection .createStatement (
446
+ "INSERT INTO test (value) VALUES(200)" ).execute ())
447
+ .flatMap (Result ::getRowsUpdated )
448
+ .thenMany (connection .setAutoCommit (true ))
449
+ .thenMany (connection .createStatement ("SELECT value FROM test" ).execute ())
450
+ .flatMap (it -> it .map ((row , metadata ) -> row .get ("value" )))
451
+ .concatWith (close (connection ))
452
+ )
453
+ .as (StepVerifier ::create )
454
+ // Cloud Spanner only has a 64 bit "integer"
455
+ .expectNext (200L )
456
+ .as ("autoCommit(true) committed the transaction. Expecting a value to be present" )
457
+ .verifyComplete ();
458
+ }
459
+
460
+ @ Override
461
+ @ Test
462
+ public void sameAutoCommitLeavesTransactionUnchanged () {
463
+ Mono .from (getConnectionFactory ().create ())
464
+ .flatMapMany (connection ->
465
+ Flux .from (connection .setAutoCommit (false ))
466
+ .thenMany (connection .beginTransaction ())
467
+ .thenMany (connection .createStatement (
468
+ "INSERT INTO test (value) VALUES(200)" ).execute ())
469
+ .flatMap (Result ::getRowsUpdated )
470
+ .thenMany (connection .setAutoCommit (false ))
471
+ .thenMany (connection .rollbackTransaction ())
472
+ .thenMany (connection .createStatement ("SELECT value FROM test" ).execute ())
473
+ .flatMap (it -> it .map ((row , metadata ) -> row .get ("value" )))
474
+ .concatWith (close (connection ))
475
+ )
476
+ .as (StepVerifier ::create )
477
+ .verifyComplete ();
478
+ }
479
+
435
480
}
0 commit comments