FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: add missing span.end calls for AsyncTransactionManager by olavloite · Pull Request #4012 · googleapis/java-spanner · GitHub

This repository was archived by the owner on Apr 7, 2026. It is now read-only.
/ java-spanner Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,19 @@ public void onFailure(Throwable t) {
txnState = TransactionState.ABORTED;
} else {
txnState = TransactionState.COMMIT_FAILED;
if (span != null) {
span.setStatus(t);
span.end();
}
commitResponse.setException(t);
}
}

@Override
public void onSuccess(CommitResponse result) {
if (span != null) {
span.end();
}
commitResponse.set(result);
}
},
Expand All @@ -190,6 +197,10 @@ public ApiFuture<Void> rollbackAsync() {
ignored -> ApiFutures.immediateFuture(null),
MoreExecutors.directExecutor());
} finally {
if (span != null) {
span.addAnnotation("Transaction rolled back");
span.end();
}
txnState = TransactionState.ROLLED_BACK;
}
}
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
import com.google.api.gax.retrying.RetrySettings;
import com.google.cloud.NoCredentials;
import com.google.cloud.spanner.AsyncTransactionManager.CommitTimestampFuture;
import com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture;
import com.google.cloud.spanner.MockSpannerServiceImpl.SimulatedExecutionTime;
import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult;
import com.google.cloud.spanner.SpannerOptions.SpannerEnvironment;
import com.google.cloud.spanner.connection.RandomResultSetGenerator;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import io.grpc.Status;
import io.opentelemetry.api.GlobalOpenTelemetry;
Expand Down Expand Up @@ -451,6 +454,58 @@ public boolean isEnableApiTracing() {
"CloudSpannerOperation.ExecuteStreamingQuery", "Spanner.ExecuteStreamingSql", spans);
}

@Test
public void testAsyncTransactionManagerCommit() throws Exception {
try (AsyncTransactionManager manager = client.transactionManagerAsync()) {
TransactionContextFuture transactionFuture = manager.beginAsync();
CommitTimestampFuture commitTimestamp =
transactionFuture
.then(
(transaction, __) -> transaction.executeUpdateAsync(UPDATE_RANDOM),
MoreExecutors.directExecutor())
.commitAsync();
commitTimestamp.get();
}

assertEquals(CompletableResultCode.ofSuccess(), spanExporter.flush());
List<SpanData> spans = spanExporter.getFinishedSpanItems();
assertContains("CloudSpanner.ReadWriteTransaction", spans);
assertContains("CloudSpannerOperation.ExecuteUpdate", spans);
assertContains("CloudSpannerOperation.Commit", spans);
assertContains("Spanner.ExecuteSql", spans);
assertContains("Spanner.Commit", spans);

assertParent("CloudSpanner.ReadWriteTransaction", "CloudSpannerOperation.ExecuteUpdate", spans);
assertParent("CloudSpanner.ReadWriteTransaction", "CloudSpannerOperation.Commit", spans);
assertParent("CloudSpannerOperation.ExecuteUpdate", "Spanner.ExecuteSql", spans);
}

@Test
public void testAsyncTransactionManagerRollback() throws Exception {
try (AsyncTransactionManager manager = client.transactionManagerAsync()) {
TransactionContextFuture transactionFuture = manager.beginAsync();
transactionFuture
.then(
(transaction, __) -> transaction.executeUpdateAsync(UPDATE_RANDOM),
MoreExecutors.directExecutor())
.get();
manager.rollbackAsync().get();
}

assertEquals(CompletableResultCode.ofSuccess(), spanExporter.flush());
List<SpanData> spans = spanExporter.getFinishedSpanItems();
assertContains("CloudSpanner.ReadWriteTransaction", spans);
assertContains("CloudSpannerOperation.ExecuteUpdate", spans);
assertContains("Spanner.ExecuteSql", spans);
assertContains("Spanner.Rollback", spans);

assertParent("CloudSpanner.ReadWriteTransaction", "CloudSpannerOperation.ExecuteUpdate", spans);
assertParent("CloudSpannerOperation.ExecuteUpdate", "Spanner.ExecuteSql", spans);
SpanData transactionSpan = getSpan("CloudSpanner.ReadWriteTransaction", spans);
assertNotNull(transactionSpan);
assertContainsEvent("Transaction rolled back", transactionSpan.getEvents());
}

void assertContains(String expected, List<SpanData> spans) {
assertTrue(
"Expected " + spansToString(spans) + " to contain " + expected,
Expand Down
Loading

Back | FazBrowse Home | New Git URL