Skip to content

Commit 86481b5

Browse files
authored
chore: use gson Java version util (#3085)
Uses the gson Java version checker, which is more production-hardened than the custom one in the Spanner client. It seems that the Spanner implementation does not get it right on all versions on Windows.
1 parent c64c8f8 commit 86481b5

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/JavaVersionUtil.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,13 @@
1616

1717
package com.google.cloud.spanner;
1818

19+
import com.google.gson.internal.JavaVersion;
20+
1921
/** Util class for getting the Java version the tests are executed on. */
2022
public class JavaVersionUtil {
2123

2224
/** Returns the major Java version (e.g. 8, 11, 17) */
2325
public static int getJavaMajorVersion() {
24-
String version = System.getProperty("java.version");
25-
if (version.startsWith("1.")) {
26-
version = version.substring(2, 3);
27-
} else {
28-
int dot = version.indexOf(".");
29-
if (dot != -1) {
30-
version = version.substring(0, dot);
31-
}
32-
}
33-
return Integer.parseInt(version);
26+
return JavaVersion.getMajorJavaVersion();
3427
}
3528
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void testMaintainer() {
111111

112112
@Test
113113
public void testForceDisableEnvVar() throws Exception {
114-
assumeTrue(isJava8());
114+
assumeTrue(isJava8() && !isWindows());
115115
assumeFalse(
116116
System.getenv().containsKey("GOOGLE_CLOUD_SPANNER_FORCE_DISABLE_MULTIPLEXED_SESSIONS"));
117117

@@ -146,4 +146,8 @@ public void testForceDisableEnvVar() throws Exception {
146146
private boolean isJava8() {
147147
return JavaVersionUtil.getJavaMajorVersion() == 8;
148148
}
149+
150+
private boolean isWindows() {
151+
return System.getProperty("os.name").toLowerCase().contains("windows");
152+
}
149153
}

0 commit comments

Comments
 (0)