Skip to content

Commit aa53171

Browse files
authored
Fix TCK test failures (#175)
Two reasons for failures: 1) Cloud Spanner requires that columns be enumerated in insert statement. 2) Cloud Spanner's "Integer" type is 64 bit, so it maps to a Java Long. Also: renamed from Example to TestKit to conform to new naming convension.
1 parent 107c976 commit aa53171

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerExample.java renamed to src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerTestKit.java

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import io.r2dbc.spi.ConnectionFactory;
3737
import io.r2dbc.spi.ConnectionFactoryOptions;
3838
import io.r2dbc.spi.Option;
39+
import io.r2dbc.spi.Result;
3940
import io.r2dbc.spi.Statement;
4041
import io.r2dbc.spi.test.TestKit;
4142
import java.nio.charset.StandardCharsets;
@@ -57,9 +58,9 @@
5758
import reactor.test.StepVerifier;
5859

5960
/**
60-
* Tests bringing in "TCK" Example.java from r2dbc-spi-test.
61+
* R2DBC TCK test implementation.
6162
*/
62-
public class SpannerExample implements TestKit<String> {
63+
public class SpannerTestKit implements TestKit<String> {
6364

6465
private static final ConnectionFactory connectionFactory =
6566
ConnectionFactories.get(ConnectionFactoryOptions.builder()
@@ -69,7 +70,7 @@ public class SpannerExample implements TestKit<String> {
6970
.option(DATABASE, TEST_DATABASE)
7071
.build());
7172

72-
private static final Logger logger = LoggerFactory.getLogger(SpannerExample.class);
73+
private static final Logger logger = LoggerFactory.getLogger(SpannerTestKit.class);
7374

7475
private static final JdbcOperations jdbcOperations;
7576

@@ -432,4 +433,48 @@ public void bindNull() {
432433
.expectNextCount(1).as("rows inserted")
433434
.verifyComplete();
434435
}
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+
435480
}

0 commit comments

Comments
 (0)