Skip to content

Commit

Permalink
tests: fixes jdbc query options test (#468)
Browse files Browse the repository at this point in the history
* tests: fixes jdbc query options test

This test was failing, because we were no longer recreating the jdbc
connection from scratch. One of the tests, set an environment variable
specifying the optimizer version, which was permanently applied, since
the connection was not re-created.

Here we make sure to start / stop the static server before each test.

* chore: fixes linting errors
  • Loading branch information
thiagotnunes committed May 18, 2021
1 parent 2fc4679 commit def3aaa
Showing 1 changed file with 8 additions and 7 deletions.
Expand Up @@ -26,12 +26,19 @@
import com.google.spanner.v1.ExecuteSqlRequest;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class JdbcQueryOptionsTest extends AbstractMockServerTest {
@Before
public void setup() throws Exception {
stopServer();
startStaticServer();
}

@Test
public void testDefaultOptimizerVersion() throws SQLException {
try (java.sql.Connection connection = createJdbcConnection()) {
Expand Down Expand Up @@ -151,13 +158,7 @@ public void testUseOptimizerVersionFromConnectionUrl() throws SQLException {
@Test
public void testUseOptimizerVersionFromEnvironment() throws SQLException {
try {
SpannerOptions.useEnvironment(
new SpannerOptions.SpannerEnvironment() {
@Override
public String getOptimizerVersion() {
return "20";
}
});
SpannerOptions.useEnvironment(() -> "20");
try (java.sql.Connection connection =
DriverManager.getConnection(String.format("jdbc:%s", getBaseUrl()))) {
// Do a query and verify that the version from the environment is used.
Expand Down

0 comments on commit def3aaa

Please sign in to comment.