Skip to content

Commit 37fdc27

Browse files
feat: Use multiplexed sessions for read-only transactions (#3917)
* feat: Enable Multiplex session by default * enable new github actions * enable regular session pipeline with emulator * rename job names * skip running multiplex session tests in regular session * chore: generate libraries at Wed Jun 18 07:14:15 UTC 2025 * Skip multiplex session tests in regular session * Fix tests * Fix tests * Introduce a new Kokoro job for regular sessions --------- Co-authored-by: cloud-java-bot <[email protected]>
1 parent db0ed07 commit 37fdc27

File tree

9 files changed

+110
-3
lines changed

9 files changed

+110
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,25 @@ jobs:
5252
- run: .kokoro/build.sh
5353
env:
5454
JOB_TYPE: test
55-
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: true
5655
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS: true
5756
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW: true
57+
units-with-regular-session:
58+
runs-on: ubuntu-latest
59+
strategy:
60+
fail-fast: false
61+
matrix:
62+
java: [ 11, 17, 21 ]
63+
steps:
64+
- uses: actions/checkout@v4
65+
- uses: actions/setup-java@v3
66+
with:
67+
distribution: temurin
68+
java-version: ${{matrix.java}}
69+
- run: java -version
70+
- run: .kokoro/build.sh
71+
env:
72+
JOB_TYPE: test
73+
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: false
5874
units-java8:
5975
# Building using Java 17 and run the tests with Java 8 runtime
6076
name: "units (8)"
@@ -96,6 +112,26 @@ jobs:
96112
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: true
97113
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS: true
98114
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW: true
115+
units-with-regular-session8:
116+
# Building using Java 17 and run the tests with Java 8 runtime
117+
name: "units-with-regular-session (8)"
118+
runs-on: ubuntu-latest
119+
steps:
120+
- uses: actions/checkout@v4
121+
- uses: actions/setup-java@v3
122+
with:
123+
java-version: 8
124+
distribution: temurin
125+
- run: echo "SUREFIRE_JVM_OPT=-Djvm=${JAVA_HOME}/bin/java" >> $GITHUB_ENV
126+
shell: bash
127+
- uses: actions/setup-java@v3
128+
with:
129+
java-version: 17
130+
distribution: temurin
131+
- run: .kokoro/build.sh
132+
env:
133+
JOB_TYPE: test
134+
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: false
99135
windows:
100136
runs-on: windows-latest
101137
steps:

.github/workflows/integration-tests-against-emulator-with-multiplexed-session.yaml renamed to .github/workflows/integration-tests-against-emulator-with-regular-session.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ jobs:
3939
env:
4040
JOB_TYPE: test
4141
SPANNER_EMULATOR_HOST: localhost:9010
42-
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: true
42+
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: false
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
7+
}
8+
9+
env_vars: {
10+
key: "JOB_TYPE"
11+
value: "integration"
12+
}
13+
14+
# TODO: remove this after we've migrated all tests and scripts
15+
env_vars: {
16+
key: "GCLOUD_PROJECT"
17+
value: "gcloud-devel"
18+
}
19+
20+
env_vars: {
21+
key: "GOOGLE_CLOUD_PROJECT"
22+
value: "gcloud-devel"
23+
}
24+
25+
env_vars: {
26+
key: "GOOGLE_APPLICATION_CREDENTIALS"
27+
value: "secret_manager/java-it-service-account"
28+
}
29+
30+
env_vars: {
31+
key: "SECRET_MANAGER_KEYS"
32+
value: "java-it-service-account"
33+
}
34+
35+
env_vars: {
36+
key: "GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS"
37+
value: "false"
38+
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ public static class Builder {
613613

614614
// This field controls the default behavior of session management in Java client.
615615
// Set useMultiplexedSession to true to make multiplexed session the default.
616-
private boolean useMultiplexedSession = false;
616+
private boolean useMultiplexedSession = true;
617617

618618
// This field controls the default behavior of session management for RW operations in Java
619619
// client.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.junit.Assert.assertNotNull;
2828
import static org.junit.Assert.assertThrows;
2929
import static org.junit.Assert.assertTrue;
30+
import static org.junit.Assume.assumeFalse;
3031

3132
import com.google.api.core.ApiFuture;
3233
import com.google.api.core.ApiFutures;
@@ -69,6 +70,7 @@ public class MultiplexedSessionDatabaseClientMockServerTest extends AbstractMock
6970

7071
@BeforeClass
7172
public static void setupResults() {
73+
assumeFalse(TestHelper.isMultiplexSessionDisabled());
7274
mockSpanner.putStatementResults(
7375
StatementResult.query(STATEMENT, new RandomResultSetGenerator(1).generate()));
7476
mockSpanner.putStatementResult(StatementResult.update(UPDATE_STATEMENT, UPDATE_COUNT));

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.junit.Assert.assertThrows;
2525
import static org.junit.Assert.assertTrue;
2626
import static org.junit.Assert.fail;
27+
import static org.junit.Assume.assumeFalse;
2728

2829
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
2930
import com.google.api.gax.retrying.RetrySettings;
@@ -255,6 +256,7 @@ public void testMetricsWithGaxRetryUnaryRpc() {
255256

256257
@Test
257258
public void testNoNetworkConnection() {
259+
assumeFalse(TestHelper.isMultiplexSessionDisabled());
258260
// Create a Spanner instance that tries to connect to a server that does not exist.
259261
// This simulates a bad network connection.
260262
SpannerOptions.Builder builder = SpannerOptions.newBuilder();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ public void testDenyListedChannelIsCleared() {
284284

285285
@Test
286286
public void testSingleUseQuery_retriesOnNewChannel() {
287+
assumeFalse(TestHelper.isMultiplexSessionDisabled());
287288
SpannerOptions.Builder builder = createSpannerOptionsBuilder();
288289
builder.setSessionPoolOption(
289290
SessionPoolOptions.newBuilder().setUseMultiplexedSession(true).build());
@@ -312,6 +313,7 @@ public void testSingleUseQuery_retriesOnNewChannel() {
312313

313314
@Test
314315
public void testSingleUseQuery_stopsRetrying() {
316+
assumeFalse(TestHelper.isMultiplexSessionDisabled());
315317
SpannerOptions.Builder builder = createSpannerOptionsBuilder();
316318
builder.setSessionPoolOption(
317319
SessionPoolOptions.newBuilder().setUseMultiplexedSession(true).build());

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ public void testRandomizePositionQPSThreshold() {
283283

284284
@Test
285285
public void testUseMultiplexedSession() {
286+
assumeFalse(TestHelper.isMultiplexSessionDisabled());
286287
// skip these tests since this configuration can have dual behaviour in different test-runners
287288
assumeFalse(SessionPoolOptions.newBuilder().build().getUseMultiplexedSession());
288289
assertEquals(false, SessionPoolOptions.newBuilder().build().getUseMultiplexedSession());
@@ -304,6 +305,7 @@ public void testUseMultiplexedSession() {
304305
@Test
305306
public void testUseMultiplexedSessionForRW() {
306307
// skip these tests since this configuration can have dual behaviour in different test-runners
308+
assumeFalse(TestHelper.isMultiplexSessionDisabled());
307309
assumeFalse(
308310
Boolean.parseBoolean(System.getenv("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW")));
309311
assumeFalse(SessionPoolOptions.newBuilder().build().getUseMultiplexedSession());
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.spanner;
17+
18+
class TestHelper {
19+
20+
static boolean isMultiplexSessionDisabled() {
21+
return System.getenv()
22+
.getOrDefault("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS", "")
23+
.equalsIgnoreCase("false");
24+
}
25+
}

0 commit comments

Comments
 (0)