Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.google.cloud.Timestamp;
import com.google.common.base.Preconditions;
import com.google.spanner.v1.TransactionOptions.IsolationLevel;
import com.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
Comment on lines +21 to +22
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Add the imports for InternalApi and Nullable to support marking the new methods as internal and nullable, as they are intended for internal test environments.

Suggested change
import com.google.spanner.v1.TransactionOptions.IsolationLevel;
import com.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
import com.google.api.core.InternalApi;
import com.google.spanner.v1.TransactionOptions.IsolationLevel;
import com.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
import javax.annotation.Nullable;

import java.util.Objects;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -54,6 +56,30 @@ public Timestamp getCommitTimestamp() {
return Timestamp.fromProto(proto.getSnapshotTimestamp());
}

/**
* Returns the {@link IsolationLevel} used for the read-write transaction if the transaction ran
* in internal test environments, and otherwise returns null.
*/
public @Nullable IsolationLevel getIsolationLevel() {
if (proto.getIsolationLevel() == IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED
Comment thread
shobhitsg marked this conversation as resolved.
|| proto.getIsolationLevel() == IsolationLevel.UNRECOGNIZED) {
return null;
}
return proto.getIsolationLevel();
}
Comment on lines +59 to +69
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since this method is intended for internal test environments, it should be annotated with @internalapi to indicate it is not part of the stable public API. Additionally, using a local variable for the isolation level avoids multiple calls to the underlying proto getter.

  /**
   * Returns the {@link IsolationLevel} used for the read-write transaction if the transaction ran
   * in internal test environments, and otherwise returns null.
   */
  @InternalApi
  public @Nullable IsolationLevel getIsolationLevel() {
    IsolationLevel isolationLevel = proto.getIsolationLevel();
    if (isolationLevel == IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED
        || isolationLevel == IsolationLevel.UNRECOGNIZED) {
      return null;
    }
    return isolationLevel;
  }
References
  1. Update stale Javadoc comments to reflect new method behavior for improved clarity, rather than removing them.
  2. Breaking changes to public APIs are permissible if the API has not yet been released.


/**
* Returns the {@link ReadLockMode} used for the read-write transaction if the transaction ran in
* internal test environments, and otherwise returns null.
*/
public @Nullable ReadLockMode getReadLockMode() {
if (proto.getReadLockMode() == ReadLockMode.READ_LOCK_MODE_UNSPECIFIED
|| proto.getReadLockMode() == ReadLockMode.UNRECOGNIZED) {
return null;
}
return proto.getReadLockMode();
}
Comment on lines +71 to +81
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to getIsolationLevel, this method should be annotated with @internalapi and can be optimized by using a local variable for the read lock mode.

  /**
   * Returns the {@link ReadLockMode} used for the read-write transaction if the transaction ran in
   * internal test environments, and otherwise returns null.
   */
  @InternalApi
  public @Nullable ReadLockMode getReadLockMode() {
    ReadLockMode readLockMode = proto.getReadLockMode();
    if (readLockMode == ReadLockMode.READ_LOCK_MODE_UNSPECIFIED
        || readLockMode == ReadLockMode.UNRECOGNIZED) {
      return null;
    }
    return readLockMode;
  }
References
  1. Update stale Javadoc comments to reflect new method behavior for improved clarity, rather than removing them.
  2. Breaking changes to public APIs are permissible if the API has not yet been released.


/**
* @return true if the {@link CommitResponse} includes {@link CommitStats}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import com.google.cloud.Timestamp;
import com.google.spanner.v1.CommitResponse.CommitStats;
import com.google.spanner.v1.TransactionOptions.IsolationLevel;
import com.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -119,4 +121,50 @@ public void testGetSnapshotTimestamp() {
Timestamp.ofTimeSecondsAndNanos(123L, 456),
responseWithSnapshotTimestamp.getSnapshotTimestamp());
}

@Test
public void testGetIsolationLevel() {
com.google.spanner.v1.CommitResponse protoWithoutIsolationLevel =
com.google.spanner.v1.CommitResponse.getDefaultInstance();
CommitResponse responseWithoutIsolationLevel = new CommitResponse(protoWithoutIsolationLevel);
assertEquals(null, responseWithoutIsolationLevel.getIsolationLevel());

com.google.spanner.v1.CommitResponse protoWithUnspecifiedIsolationLevel =
com.google.spanner.v1.CommitResponse.newBuilder()
.setIsolationLevel(IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED)
.build();
CommitResponse responseWithUnspecifiedIsolationLevel =
new CommitResponse(protoWithUnspecifiedIsolationLevel);
assertEquals(null, responseWithUnspecifiedIsolationLevel.getIsolationLevel());

com.google.spanner.v1.CommitResponse protoWithIsolationLevel =
com.google.spanner.v1.CommitResponse.newBuilder()
.setIsolationLevel(IsolationLevel.REPEATABLE_READ)
.build();
CommitResponse responseWithIsolationLevel = new CommitResponse(protoWithIsolationLevel);
assertEquals(IsolationLevel.REPEATABLE_READ, responseWithIsolationLevel.getIsolationLevel());
}

@Test
public void testGetReadLockMode() {
com.google.spanner.v1.CommitResponse protoWithoutReadLockMode =
com.google.spanner.v1.CommitResponse.getDefaultInstance();
CommitResponse responseWithoutReadLockMode = new CommitResponse(protoWithoutReadLockMode);
assertEquals(null, responseWithoutReadLockMode.getReadLockMode());

com.google.spanner.v1.CommitResponse protoWithUnspecifiedReadLockMode =
com.google.spanner.v1.CommitResponse.newBuilder()
.setReadLockMode(ReadLockMode.READ_LOCK_MODE_UNSPECIFIED)
.build();
CommitResponse responseWithUnspecifiedReadLockMode =
new CommitResponse(protoWithUnspecifiedReadLockMode);
assertEquals(null, responseWithUnspecifiedReadLockMode.getReadLockMode());

com.google.spanner.v1.CommitResponse protoWithReadLockMode =
com.google.spanner.v1.CommitResponse.newBuilder()
.setReadLockMode(ReadLockMode.PESSIMISTIC)
.build();
CommitResponse responseWithReadLockMode = new CommitResponse(protoWithReadLockMode);
assertEquals(ReadLockMode.PESSIMISTIC, responseWithReadLockMode.getReadLockMode());
}
}
Loading