Skip to content

Commit 890a294

Browse files
committed
chore(spanner): fix code and tests
1 parent c8d1e63 commit 890a294

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void setSpan(ISpan span) {
5555

5656
@Override
5757
public void close() {
58-
closeAsync();
58+
SpannerApiFutures.get(closeAsync());
5959
}
6060

6161
@Override
@@ -183,6 +183,10 @@ public ApiFuture<Void> rollbackAsync() {
183183

184184
@Override
185185
public TransactionContextFuture resetForRetryAsync() {
186+
if (txn == null || !txn.isAborted() && txnState != TransactionState.ABORTED) {
187+
throw new IllegalStateException(
188+
"resetForRetry can only be called if the previous attempt aborted");
189+
}
186190
return new TransactionContextFutureImpl(this, internalBeginAsync(false));
187191
}
188192

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITAsyncExamplesTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ public void runAsync() throws Exception {
253253
},
254254
executor);
255255
assertThat(insertCount.get()).isEqualTo(1L);
256+
if (env.getTestHelper().getOptions().getSessionPoolOptions().getUseMultiplexedSessionForRW()) {
257+
// The runAsync() method should only be called once on the runner.
258+
// However, due to a bug in regular sessions, it can be executed multiple times on the same
259+
// runner.
260+
runner = client.runAsync();
261+
}
256262
ApiFuture<Long> deleteCount =
257263
runner.runAsync(
258264
txn ->

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBatchDmlTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.spanner.it;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20+
import static org.junit.Assume.assumeFalse;
2021

2122
import com.google.api.gax.longrunning.OperationFuture;
2223
import com.google.cloud.spanner.Database;
@@ -84,6 +85,10 @@ public void dropTable() throws Exception {
8485

8586
@Test
8687
public void noStatementsInRequest() {
88+
// TODO(sriharshach): Remove this skip once backend support empty transactions to commit.
89+
assumeFalse(
90+
"Skipping for multiplexed sessions since it does not allow empty transactions to commit",
91+
isUsingMultiplexedSessionsForRW());
8792
final TransactionCallable<long[]> callable =
8893
transaction -> {
8994
List<Statement> stmts = new ArrayList<>();
@@ -252,4 +257,8 @@ public void largeBatchDml_withNonParameterisedStatements() {
252257
assertThat(actualRowCounts.length).isEqualTo(80);
253258
assertThat(expectedRowCounts).isEqualTo(actualRowCounts);
254259
}
260+
261+
boolean isUsingMultiplexedSessionsForRW() {
262+
return env.getTestHelper().getOptions().getSessionPoolOptions().getUseMultiplexedSessionForRW();
263+
}
255264
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBatchReadTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ public static void setUpDatabase() throws Exception {
181181
totalSize = 0;
182182
}
183183
}
184-
dbClient.write(mutations);
184+
if (mutations.size() > 0) {
185+
dbClient.write(mutations);
186+
}
185187
}
186188
// Our read/queries are executed with some staleness.
187189
Thread.sleep(2 * STALENESS_MILLISEC);

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITTransactionTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,10 @@ public void nestedSingleUseReadTxnThrows() {
464464
@Test
465465
public void nestedTxnSucceedsWhenAllowed() {
466466
assumeFalse("Emulator does not support multiple parallel transactions", isUsingEmulator());
467-
467+
// TODO(sriharshach): Remove this skip once backend support empty transactions to commit.
468+
assumeFalse(
469+
"Skipping for multiplexed sessions since it does not allow empty transactions to commit",
470+
isUsingMultiplexedSessionsForRW());
468471
client
469472
.readWriteTransaction()
470473
.allowNestedTransaction()
@@ -588,4 +591,8 @@ public void testTransactionRunnerReturnsCommitStats() {
588591
// MutationCount = 2 (2 columns).
589592
assertEquals(2L, runner.getCommitResponse().getCommitStats().getMutationCount());
590593
}
594+
595+
boolean isUsingMultiplexedSessionsForRW() {
596+
return env.getTestHelper().getOptions().getSessionPoolOptions().getUseMultiplexedSessionForRW();
597+
}
591598
}

0 commit comments

Comments
 (0)