Skip to content

Commit aa4c0f5

Browse files
authored
chore: only reset dialect result when it has changed (#1471)
Only change the dialect result that is returned by the mock server when the dialect has actually changed. This makes the test a bit quicker, as we also don't have to close the SpannerPool after each test.
1 parent e3f58d1 commit aa4c0f5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/test/java/com/google/cloud/spanner/jdbc/SavepointMockServerTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.sql.SQLException;
4444
import java.sql.Savepoint;
4545
import java.util.List;
46+
import java.util.Objects;
4647
import java.util.stream.Collectors;
4748
import org.junit.After;
4849
import org.junit.Before;
@@ -54,6 +55,8 @@
5455

5556
@RunWith(Parameterized.class)
5657
public class SavepointMockServerTest extends AbstractMockServerTest {
58+
private static Dialect currentDialect;
59+
5760
@Parameter public Dialect dialect;
5861

5962
@Parameters(name = "dialect = {0}")
@@ -63,13 +66,18 @@ public static Object[] data() {
6366

6467
@Before
6568
public void setupDialect() {
66-
mockSpanner.putStatementResult(StatementResult.detectDialectResult(this.dialect));
69+
// Only reset the dialect result when it has actually changed. This prevents the SpannerPool
70+
// from being closed after each test, which again makes the test slower.
71+
if (!Objects.equals(this.dialect, currentDialect)) {
72+
currentDialect = this.dialect;
73+
mockSpanner.putStatementResult(StatementResult.detectDialectResult(this.dialect));
74+
SpannerPool.closeSpannerPool();
75+
}
6776
}
6877

6978
@After
7079
public void clearRequests() {
7180
mockSpanner.clearRequests();
72-
SpannerPool.closeSpannerPool();
7381
}
7482

7583
private String createUrl() {

0 commit comments

Comments
 (0)