Skip to content

Commit ebf0582

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 ebf0582

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 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,17 @@ public Timestamp getCommitTimestamp() {
4142
return Timestamp.fromProto(proto.getCommitTimestamp());
4243
}
4344

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

0 commit comments

Comments
 (0)