Skip to content

Commit e272679

Browse files
Fix tests
1 parent c33c277 commit e272679

File tree

7 files changed

+2290
-252
lines changed

7 files changed

+2290
-252
lines changed

google-cloud-spanner/src/main/resources/com/google/cloud/spanner/connection/ClientSideStatements.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,16 +754,19 @@
754754
}
755755
},
756756
{
757-
"name": "SET LOCAL DML_BATCH_UPDATE_COUNT = <INT64>",
757+
"name": "SET [LOCAL] DML_BATCH_UPDATE_COUNT = <INT64>",
758758
"executorName": "ClientSideStatementSetExecutor",
759759
"resultType": "NO_RESULT",
760760
"statementType": "SET_DML_BATCH_UPDATE_COUNT",
761-
"regex": "(?is)\\A\\s*set\\s+((?:session|local)\\s+)dml_batch_update_count\\s*(?:=)\\s*(.*)\\z",
761+
"regex": "(?is)\\A\\s*set\\s+((?:session|local)\\s+)?dml_batch_update_count\\s*(?:=)\\s*(.*)\\z",
762762
"method": "statementSetDmlBatchUpdateCount",
763763
"exampleStatements": [
764764
"set local dml_batch_update_count = 0",
765-
"set local dml_batch_update_count = 100"
765+
"set local dml_batch_update_count = 100",
766+
"set dml_batch_update_count = 1",
767+
"set dml_batch_update_count = 100"
766768
],
769+
"examplePrerequisiteStatements": ["set readonly = false", "set autocommit = false"],
767770
"setStatement": {
768771
"propertyName": "DML_BATCH_UPDATE_COUNT",
769772
"separator": "(?:=|\\s+TO\\s+)",

google-cloud-spanner/src/main/resources/com/google/cloud/spanner/connection/PG_ClientSideStatements.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@
967967
}
968968
},
969969
{
970-
"name": "SET LOCAL SPANNER.DML_BATCH_UPDATE_COUNT =|TO <bigint>",
970+
"name": "SET [LOCAL] SPANNER.DML_BATCH_UPDATE_COUNT =|TO <bigint>",
971971
"executorName": "ClientSideStatementSetExecutor",
972972
"resultType": "NO_RESULT",
973973
"statementType": "SET_DML_BATCH_UPDATE_COUNT",
@@ -977,8 +977,10 @@
977977
"set local spanner.dml_batch_update_count = 0",
978978
"set local spanner.dml_batch_update_count = 100",
979979
"set local spanner.dml_batch_update_count to 1",
980-
"set local spanner.dml_batch_update_count to 1"
980+
"set spanner.dml_batch_update_count to 1",
981+
"set spanner.dml_batch_update_count = 1"
981982
],
983+
"examplePrerequisiteStatements": ["set spanner.readonly = false", "set autocommit = false"],
982984
"setStatement": {
983985
"propertyName": "SPANNER.DML_BATCH_UPDATE_COUNT",
984986
"separator": "(?:=|\\s+TO\\s+)",

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ConnectionAsyncApiTest.java

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -341,29 +341,38 @@ public void testAutocommitRunBatch() {
341341

342342
@Test
343343
public void testDmlBatchUpdateCount() {
344-
SpannerPool.closeSpannerPool();
345-
try {
346-
try (Connection connection = createConnection()) {
347-
connection.execute(Statement.of("set local spanner.dml_batch_update_count = 1"));
348-
connection.execute(Statement.of("START BATCH DML"));
349-
List<Statement> statements = Arrays.asList(INSERT_STATEMENT, INSERT_STATEMENT);
350-
long[] updateCounts = connection.executeBatchUpdate(statements);
351-
assertThat(updateCounts).asList().containsExactly(1L, 1L);
352-
connection.execute(Statement.of("RUN BATCH"));
353-
connection.commit();
354-
355-
connection.execute(Statement.of("START BATCH DML"));
356-
statements = Arrays.asList(INSERT_STATEMENT, INSERT_STATEMENT);
357-
updateCounts = connection.executeBatchUpdate(statements);
358-
assertThat(updateCounts).asList().containsExactly(-1L, -1L);
359-
connection.execute(Statement.of("RUN BATCH"));
360-
connection.commit();
361-
}
362-
} finally {
363-
SpannerPool.closeSpannerPool();
364-
mockSpanner.putStatementResult(
365-
MockSpannerServiceImpl.StatementResult.detectDialectResult(Dialect.GOOGLE_STANDARD_SQL));
366-
}
344+
Arrays.asList(Dialect.POSTGRESQL, Dialect.GOOGLE_STANDARD_SQL)
345+
.forEach(
346+
dialect -> {
347+
String prefix = dialect == Dialect.POSTGRESQL ? "spanner." : "";
348+
mockSpanner.putStatementResult(
349+
MockSpannerServiceImpl.StatementResult.detectDialectResult(dialect));
350+
SpannerPool.closeSpannerPool();
351+
try {
352+
try (Connection connection = createConnection()) {
353+
connection.execute(
354+
Statement.of("set local " + prefix + "dml_batch_update_count = 1"));
355+
connection.execute(Statement.of("START BATCH DML"));
356+
List<Statement> statements = Arrays.asList(INSERT_STATEMENT, INSERT_STATEMENT);
357+
long[] updateCounts = connection.executeBatchUpdate(statements);
358+
assertThat(updateCounts).asList().containsExactly(1L, 1L);
359+
connection.execute(Statement.of("RUN BATCH"));
360+
connection.commit();
361+
362+
connection.execute(Statement.of("START BATCH DML"));
363+
statements = Arrays.asList(INSERT_STATEMENT, INSERT_STATEMENT);
364+
updateCounts = connection.executeBatchUpdate(statements);
365+
assertThat(updateCounts).asList().containsExactly(-1L, -1L);
366+
connection.execute(Statement.of("RUN BATCH"));
367+
connection.commit();
368+
}
369+
} finally {
370+
SpannerPool.closeSpannerPool();
371+
mockSpanner.putStatementResult(
372+
MockSpannerServiceImpl.StatementResult.detectDialectResult(
373+
Dialect.GOOGLE_STANDARD_SQL));
374+
}
375+
});
367376
}
368377

369378
@Test

0 commit comments

Comments
 (0)