Skip to content

Commit 77539dc

Browse files
committed
test: added getSnapshotTimestamp() method
The snapshot timestamp is the timestamp at which all the reads in a transaction ran when using repeatable read isolation. The method is only intended to be used for internal testing purposes, so the snapshot timestamp will be `null` if attempted to be used externally.
1 parent 675e90b commit 77539dc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.cloud.Timestamp;
2020
import com.google.common.base.Preconditions;
2121
import java.util.Objects;
22+
import javax.annotation.Nullable;
2223

2324
/** Represents a response from a commit operation. */
2425
public class CommitResponse {
@@ -41,6 +42,18 @@ public Timestamp getCommitTimestamp() {
4142
return Timestamp.fromProto(proto.getCommitTimestamp());
4243
}
4344

45+
/**
46+
* Returns a {@link Timestamp} representing the timestamp at which all reads in the transaction
47+
* ran at, if the transaction ran at repeatable read isolation in internal test environments, and
48+
* otherwise returns null.
49+
*/
50+
public @Nullable Timestamp getSnapshotTimestamp() {
51+
if (proto.getSnapshotTimestamp() == com.google.protobuf.Timestamp.getDefaultInstance()) {
52+
return null;
53+
}
54+
return Timestamp.fromProto(proto.getSnapshotTimestamp());
55+
}
56+
4457
/**
4558
* @return true if the {@link CommitResponse} includes {@link CommitStats}
4659
*/

0 commit comments

Comments
 (0)