Skip to content

Commit

Permalink
chore: use gson Java version util (googleapis#3085)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olavloite committed May 3, 2024
1 parent c64c8f8 commit 86481b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@

package com.google.cloud.spanner;

import com.google.gson.internal.JavaVersion;

/** Util class for getting the Java version the tests are executed on. */
public class JavaVersionUtil {

/** Returns the major Java version (e.g. 8, 11, 17) */
public static int getJavaMajorVersion() {
String version = System.getProperty("java.version");
if (version.startsWith("1.")) {
version = version.substring(2, 3);
} else {
int dot = version.indexOf(".");
if (dot != -1) {
version = version.substring(0, dot);
}
}
return Integer.parseInt(version);
return JavaVersion.getMajorJavaVersion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void testMaintainer() {

@Test
public void testForceDisableEnvVar() throws Exception {
assumeTrue(isJava8());
assumeTrue(isJava8() && !isWindows());
assumeFalse(
System.getenv().containsKey("GOOGLE_CLOUD_SPANNER_FORCE_DISABLE_MULTIPLEXED_SESSIONS"));

Expand Down Expand Up @@ -146,4 +146,8 @@ public void testForceDisableEnvVar() throws Exception {
private boolean isJava8() {
return JavaVersionUtil.getJavaMajorVersion() == 8;
}

private boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("windows");
}
}

0 comments on commit 86481b5

Please sign in to comment.