Skip to content

Commit ccda785

Browse files
authored
Merge branch 'main' into x-goog-request-id-bases
2 parents 8bd366d + 20a3d0d commit ccda785

File tree

7 files changed

+70
-13
lines changed

7 files changed

+70
-13
lines changed

.github/workflows/hermetic_library_generation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
with:
3838
fetch-depth: 0
3939
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
40-
- uses: googleapis/sdk-platform-java/.github/scripts@v2.52.0
40+
- uses: googleapis/sdk-platform-java/.github/scripts@v2.53.0
4141
if: env.SHOULD_RUN == 'true'
4242
with:
4343
base_ref: ${{ github.base_ref }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ If you are using Maven without the BOM, add this to your dependencies:
4949
If you are using Gradle 5.x or later, add this to your dependencies:
5050

5151
```Groovy
52-
implementation platform('com.google.cloud:libraries-bom:26.53.0')
52+
implementation platform('com.google.cloud:libraries-bom:26.54.0')
5353
5454
implementation 'com.google.cloud:google-cloud-spanner'
5555
```

generation_config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
gapic_generator_version: 2.52.0
2-
googleapis_commitish: 3cf61b2df20eace09e6336c23f9e08859c0d87ae
3-
libraries_bom_version: 26.53.0
1+
gapic_generator_version: 2.53.0
2+
googleapis_commitish: 9605bff3d36fbdb1227b26bce68258c5f00815e4
3+
libraries_bom_version: 26.54.0
44
libraries:
55
- api_shortname: spanner
66
name_pretty: Cloud Spanner

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ public void commit() {
8080
} catch (SpannerException e2) {
8181
txnState = TransactionState.COMMIT_FAILED;
8282
throw e2;
83+
} finally {
84+
// At this point, if the TransactionState is not ABORTED, then the transaction has reached an
85+
// end state.
86+
// We can safely call close() to release resources.
87+
if (getState() != TransactionState.ABORTED) {
88+
close();
89+
}
8390
}
8491
}
8592

@@ -92,6 +99,9 @@ public void rollback() {
9299
txn.rollback();
93100
} finally {
94101
txnState = TransactionState.ROLLED_BACK;
102+
// At this point, the TransactionState is ROLLED_BACK which is an end state.
103+
// We can safely call close() to release resources.
104+
close();
95105
}
96106
}
97107

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

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,51 @@ public void clearRequests() {
6060
@Test
6161
public void testAsyncRunner_doesNotReturnCommitTimestampBeforeCommit() {
6262
AsyncRunner runner = client().runAsync();
63-
IllegalStateException e =
64-
assertThrows(IllegalStateException.class, () -> runner.getCommitTimestamp());
65-
assertTrue(e.getMessage().contains("runAsync() has not yet been called"));
63+
if (isMultiplexedSessionsEnabledForRW()) {
64+
Throwable e = assertThrows(Throwable.class, () -> runner.getCommitTimestamp().get());
65+
// If the error occurs within the future, it gets wrapped in an ExecutionException.
66+
// This happens when DelayedAsyncRunner is invoked while the multiplexed session is not yet
67+
// created.
68+
// If the error occurs before the future is created, it may throw an IllegalStateException
69+
// instead.
70+
assertTrue(e instanceof ExecutionException || e instanceof IllegalStateException);
71+
if (e instanceof ExecutionException) {
72+
Throwable cause = e.getCause();
73+
assertTrue(cause instanceof IllegalStateException);
74+
assertTrue(cause.getMessage().contains("runAsync() has not yet been called"));
75+
} else {
76+
assertTrue(e.getMessage().contains("runAsync() has not yet been called"));
77+
}
78+
} else {
79+
IllegalStateException e =
80+
assertThrows(IllegalStateException.class, () -> runner.getCommitTimestamp());
81+
assertTrue(e.getMessage().contains("runAsync() has not yet been called"));
82+
}
6683
}
6784

6885
@Test
6986
public void testAsyncRunner_doesNotReturnCommitResponseBeforeCommit() {
7087
AsyncRunner runner = client().runAsync();
71-
IllegalStateException e =
72-
assertThrows(IllegalStateException.class, () -> runner.getCommitResponse());
73-
assertTrue(e.getMessage().contains("runAsync() has not yet been called"));
88+
if (isMultiplexedSessionsEnabledForRW()) {
89+
Throwable e = assertThrows(Throwable.class, () -> runner.getCommitResponse().get());
90+
// If the error occurs within the future, it gets wrapped in an ExecutionException.
91+
// This happens when DelayedAsyncRunner is invoked while the multiplexed session is not yet
92+
// created.
93+
// If the error occurs before the future is created, it may throw an IllegalStateException
94+
// instead.
95+
assertTrue(e instanceof ExecutionException || e instanceof IllegalStateException);
96+
if (e instanceof ExecutionException) {
97+
Throwable cause = e.getCause();
98+
assertTrue(cause instanceof IllegalStateException);
99+
assertTrue(cause.getMessage().contains("runAsync() has not yet been called"));
100+
} else {
101+
assertTrue(e.getMessage().contains("runAsync() has not yet been called"));
102+
}
103+
} else {
104+
IllegalStateException e =
105+
assertThrows(IllegalStateException.class, () -> runner.getCommitResponse());
106+
assertTrue(e.getMessage().contains("runAsync() has not yet been called"));
107+
}
74108
}
75109

76110
@Test
@@ -558,7 +592,9 @@ public void closeTransactionBeforeEndOfAsyncQuery() throws Exception {
558592
// Wait until at least one row has been fetched. At that moment there should be one session
559593
// checked out.
560594
dataReceived.await();
561-
assertThat(clientImpl.pool.getNumberOfSessionsInUse()).isEqualTo(1);
595+
if (!isMultiplexedSessionsEnabledForRW()) {
596+
assertThat(clientImpl.pool.getNumberOfSessionsInUse()).isEqualTo(1);
597+
}
562598
assertThat(res.isDone()).isFalse();
563599
dataChecked.countDown();
564600
// Get the data from the transaction.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static org.junit.Assert.assertNotNull;
2929
import static org.junit.Assert.assertThrows;
3030
import static org.junit.Assert.assertTrue;
31+
import static org.junit.Assume.assumeFalse;
3132

3233
import com.google.api.core.ApiFuture;
3334
import com.google.api.core.ApiFutureCallback;
@@ -250,6 +251,11 @@ public void asyncTransactionManagerUpdate() throws Exception {
250251

251252
@Test
252253
public void asyncTransactionManagerIsNonBlocking() throws Exception {
254+
// TODO: Remove this condition once DelayedAsyncTransactionManager is made non-blocking with
255+
// multiplexed sessions.
256+
assumeFalse(
257+
"DelayedAsyncTransactionManager is currently blocking with multiplexed sessions.",
258+
spanner.getOptions().getSessionPoolOptions().getUseMultiplexedSessionForRW());
253259
mockSpanner.freeze();
254260
try (AsyncTransactionManager manager = clientWithEmptySessionPool().transactionManagerAsync()) {
255261
TransactionContextFuture transactionContextFuture = manager.beginAsync();
@@ -633,6 +639,11 @@ public void asyncTransactionManagerBatchUpdate() throws Exception {
633639

634640
@Test
635641
public void asyncTransactionManagerIsNonBlockingWithBatchUpdate() throws Exception {
642+
// TODO: Remove this condition once DelayedAsyncTransactionManager is made non-blocking with
643+
// multiplexed sessions.
644+
assumeFalse(
645+
"DelayedAsyncTransactionManager is currently blocking with multiplexed sessions.",
646+
spanner.getOptions().getSessionPoolOptions().getUseMultiplexedSessionForRW());
636647
mockSpanner.freeze();
637648
try (AsyncTransactionManager manager = clientWithEmptySessionPool().transactionManagerAsync()) {
638649
TransactionContextFuture transactionContextFuture = manager.beginAsync();

samples/snippets/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<dependency>
3535
<groupId>com.google.cloud</groupId>
3636
<artifactId>libraries-bom</artifactId>
37-
<version>26.53.0</version>
37+
<version>26.54.0</version>
3838
<type>pom</type>
3939
<scope>import</scope>
4040
</dependency>

0 commit comments

Comments
 (0)