|
2 | 2 |
|
3 | 3 | import static com.google.common.truth.Truth.assertThat; |
4 | 4 |
|
| 5 | +import com.google.cloud.spanner.Dialect; |
5 | 6 | import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult; |
6 | 7 | import com.google.common.collect.ImmutableList; |
7 | 8 | import com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest; |
| 9 | +import com.google.spanner.v1.BeginTransactionRequest; |
| 10 | +import com.google.spanner.v1.ExecuteSqlRequest; |
8 | 11 | import java.sql.Connection; |
9 | 12 | import java.sql.SQLException; |
| 13 | +import java.sql.Statement; |
10 | 14 | import liquibase.Liquibase; |
11 | 15 | import org.junit.jupiter.api.Test; |
12 | 16 | import org.junit.jupiter.api.parallel.Execution; |
@@ -34,6 +38,29 @@ void testCreateTableStatement() throws SQLException { |
34 | 38 | receivedRequestWithNonLiquibaseToken.set(false); |
35 | 39 | } |
36 | 40 |
|
| 41 | + |
| 42 | + @Test |
| 43 | + void testAutocommitDmlMode() throws SQLException { |
| 44 | + mockSpanner.putStatementResult(StatementResult.update(com.google.cloud.spanner.Statement.of("update foo set bar=1 where true"), 10000L)); |
| 45 | + |
| 46 | + // Configure the mock server to return POSTGRESQL as the dialect that is used by the database. |
| 47 | + mockSpanner.putStatementResult(StatementResult.detectDialectResult(Dialect.POSTGRESQL)); |
| 48 | + |
| 49 | + try (Connection con = createConnection(); Statement stmt = con.createStatement()) { |
| 50 | + stmt.execute("set spanner.autocommit_dml_mode='partitioned_non_atomic'"); |
| 51 | + stmt.execute("update foo set bar=1 where true"); |
| 52 | + } |
| 53 | + assertThat(mockSpanner.getRequestsOfType(BeginTransactionRequest.class)).hasSize(1); |
| 54 | + BeginTransactionRequest request = mockSpanner.getRequestsOfType(BeginTransactionRequest.class).get(0); |
| 55 | + assertThat(request.getOptions().hasPartitionedDml()).isTrue(); |
| 56 | + |
| 57 | + // This test does not use Liquibase but JDBC directly, so it is expected to send requests that |
| 58 | + // do not contain a Liquibase client lib token. |
| 59 | + assertThat(receivedRequestWithNonLiquibaseToken.get()).isTrue(); |
| 60 | + // Clear the flag to prevent the check after each test to fail. |
| 61 | + receivedRequestWithNonLiquibaseToken.set(false); |
| 62 | + } |
| 63 | + |
37 | 64 | @Test |
38 | 65 | void testInitLiquibase() throws Exception { |
39 | 66 | mockSpanner.putStatementResult( |
|
0 commit comments