Skip to content

Commit

Permalink
deps: bump Spanner to 6.23.3 (#862)
Browse files Browse the repository at this point in the history
Bumps Spanner to 6.23.3 and modifies SQL script test files to reflect the changes for client side statements for PG.

Replaces #788
  • Loading branch information
olavloite committed May 24, 2022
1 parent 61ba9be commit b7b8efa
Show file tree
Hide file tree
Showing 25 changed files with 19,569 additions and 4,288 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -62,7 +62,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-bom</artifactId>
<version>6.21.2</version>
<version>6.23.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Expand Up @@ -26,7 +26,6 @@
import com.google.cloud.spanner.connection.AbstractSqlScriptVerifier.GenericConnectionProvider;
import com.google.cloud.spanner.connection.ConnectionImplTest;
import com.google.cloud.spanner.connection.ConnectionOptions;
import com.google.cloud.spanner.connection.SqlScriptVerifier;
import com.google.cloud.spanner.jdbc.JdbcSqlScriptVerifier.JdbcGenericConnection;
import java.sql.SQLException;
import org.junit.Test;
Expand Down Expand Up @@ -62,7 +61,7 @@ public GenericConnection getConnection() {
ConnectionOptions options = mock(ConnectionOptions.class);
when(options.getUri()).thenReturn(ConnectionImplTest.URI);
com.google.cloud.spanner.connection.Connection spannerConnection =
ConnectionImplTest.createConnection(options);
ConnectionImplTest.createConnection(options, dialect);
when(spannerConnection.getDialect()).thenReturn(dialect);
when(options.getConnection()).thenReturn(spannerConnection);
try {
Expand All @@ -82,7 +81,8 @@ public GenericConnection getConnection() {
@Test
public void testGeneratedScript() throws Exception {
JdbcSqlScriptVerifier verifier = new JdbcSqlScriptVerifier(new TestConnectionProvider(dialect));
String prefix = dialect == Dialect.POSTGRESQL ? "PostgreSQL/" : "";
verifier.verifyStatementsInFile(
"ConnectionImplGeneratedSqlScriptTest.sql", SqlScriptVerifier.class, false);
prefix + "ConnectionImplGeneratedSqlScriptTest.sql", getClass(), false);
}
}
Expand Up @@ -76,7 +76,7 @@ private com.google.cloud.spanner.ResultSet createSelect1ResultSet() {

private JdbcConnection createConnection(ConnectionOptions options) throws SQLException {
com.google.cloud.spanner.connection.Connection spannerConnection =
ConnectionImplTest.createConnection(options);
ConnectionImplTest.createConnection(options, dialect);
when(spannerConnection.getDialect()).thenReturn(dialect);
when(options.getConnection()).thenReturn(spannerConnection);
return new JdbcConnection(
Expand Down Expand Up @@ -157,10 +157,13 @@ public void testRollback() throws SQLException {
// verify that there is no transaction started anymore
assertThat(connection.getSpannerConnection().isTransactionStarted()).isFalse();
// verify that there is no commit timestamp
try (ResultSet rs =
connection.createStatement().executeQuery("show variable commit_timestamp")) {
String showCommitTimestamp =
dialect == Dialect.POSTGRESQL
? "show spanner.commit_timestamp"
: "show variable commit_timestamp";
try (ResultSet rs = connection.createStatement().executeQuery(showCommitTimestamp)) {
assertThat(rs.next()).isTrue();
assertThat(rs.getTimestamp("COMMIT_TIMESTAMP")).isNull();
assertThat(rs.getTimestamp(1)).isNull();
}
}
}
Expand Down
Expand Up @@ -46,6 +46,7 @@ public static Object[] data() {
@Test
public void testTimeoutScript() throws Exception {
JdbcSqlScriptVerifier verifier = new JdbcSqlScriptVerifier(new TestConnectionProvider(dialect));
verifier.verifyStatementsInFile("TimeoutSqlScriptTest.sql", getClass(), false);
String prefix = dialect == Dialect.POSTGRESQL ? "PostgreSQL/" : "";
verifier.verifyStatementsInFile(prefix + "TimeoutSqlScriptTest.sql", getClass(), false);
}
}
Expand Up @@ -110,12 +110,19 @@ public Dialect getDialect() {
return dialect.dialect;
}

private String getNamespace() {
return getDialect() == Dialect.POSTGRESQL ? "SPANNER." : "";
}

private void verifyOptimizerVersion(Connection connection, String expectedVersion)
throws SQLException {
try (ResultSet rs =
connection.createStatement().executeQuery("SHOW VARIABLE OPTIMIZER_VERSION")) {
connection
.createStatement()
.executeQuery(String.format("SHOW VARIABLE %sOPTIMIZER_VERSION", getNamespace()))) {
assertThat(rs.next()).isTrue();
assertThat(rs.getString("OPTIMIZER_VERSION")).isEqualTo(expectedVersion);
assertThat(rs.getString(String.format("%sOPTIMIZER_VERSION", getNamespace())))
.isEqualTo(expectedVersion);
assertThat(rs.next()).isFalse();
}
}
Expand Down Expand Up @@ -153,7 +160,9 @@ public void connectionUrlWithInvalidOptimizerVersion() throws SQLException {
public void setOptimizerVersion() throws SQLException {
try (Connection connection = createConnection(env, database)) {
verifyOptimizerVersion(connection, "");
connection.createStatement().execute("SET OPTIMIZER_VERSION='1'");
connection
.createStatement()
.execute(String.format("SET %sOPTIMIZER_VERSION='1'", getNamespace()));
verifyOptimizerVersion(connection, "1");
try (ResultSet rs = connection.createStatement().executeQuery("SELECT 1")) {
assertThat(rs.next()).isTrue();
Expand All @@ -167,7 +176,9 @@ public void setOptimizerVersion() throws SQLException {
public void setLatestOptimizerVersion() throws SQLException {
try (Connection connection = createConnection(env, database)) {
verifyOptimizerVersion(connection, "");
connection.createStatement().execute("SET OPTIMIZER_VERSION='LATEST'");
connection
.createStatement()
.execute(String.format("SET %sOPTIMIZER_VERSION='LATEST'", getNamespace()));
verifyOptimizerVersion(connection, "LATEST");
try (ResultSet rs = connection.createStatement().executeQuery("SELECT 1")) {
assertThat(rs.next()).isTrue();
Expand All @@ -182,7 +193,9 @@ public void setInvalidOptimizerVersion() throws SQLException {
assumeFalse(
"optimizer version is ignored on emulator", EmulatorSpannerHelper.isUsingEmulator());
try (Connection connection = createConnection(env, database)) {
connection.createStatement().execute("SET OPTIMIZER_VERSION='9999999'");
connection
.createStatement()
.execute(String.format("SET %sOPTIMIZER_VERSION='9999999'", getNamespace()));
try (ResultSet rs = connection.createStatement().executeQuery("SELECT 1")) {
fail("missing expected exception");
} catch (SQLException e) {
Expand Down
Expand Up @@ -101,7 +101,10 @@ public void test02_WriteMutation() throws Exception {
connection.write(
Mutation.newInsertBuilder("TEST").set("ID").to(9999L).set("NAME").to("FOO").build());
java.sql.Statement statement = connection.createStatement();
statement.execute("SHOW VARIABLE COMMIT_TIMESTAMP");
statement.execute(
String.format(
"SHOW VARIABLE %sCOMMIT_TIMESTAMP",
getDialect() == Dialect.POSTGRESQL ? "SPANNER." : ""));
try (java.sql.ResultSet rs = statement.getResultSet()) {
assertThat(rs.next(), is(true));
assertThat(rs.getTimestamp(1), is(notNullValue()));
Expand Down

0 comments on commit b7b8efa

Please sign in to comment.