Skip to content

chore: loosen restrictions setRetryAbortsInternally #2924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-spanner'
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-spanner:6.60.0'
implementation 'com.google.cloud:google-cloud-spanner:6.60.1'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.60.0"
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.60.1"
```
<!-- {x-version-update-end} -->

Expand Down Expand Up @@ -643,7 +643,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.60.0
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.60.1
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,6 @@ public void setStatementTag(String tag) {
*/
private void checkSetRetryAbortsInternallyAvailable() {
ConnectionPreconditions.checkState(!isClosed(), CLOSED_ERROR_MSG);
ConnectionPreconditions.checkState(isInTransaction(), "This connection has no transaction");
ConnectionPreconditions.checkState(
getTransactionMode() == TransactionMode.READ_WRITE_TRANSACTION,
"RetryAbortsInternally is only available for read-write transactions");
ConnectionPreconditions.checkState(
!isTransactionStarted(),
"RetryAbortsInternally cannot be set after the transaction has started");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,50 @@ public void testCheckResultTypeAllowed() {
checkResultTypeAllowed(parser.parse(Statement.of(start)), allowedResultTypes);
}

@Test
public void testSetRetryAbortsInternally() {
try (ConnectionImpl connection =
createConnection(
ConnectionOptions.newBuilder()
.setCredentials(NoCredentials.getInstance())
.setUri(URI)
.build())) {
assertFalse("Read-only should be disabled by default", connection.isReadOnly());
assertTrue("Autocommit should be enabled by default", connection.isAutocommit());
assertFalse(
"Retry aborts internally should be disabled by default on test connections",
connection.isRetryAbortsInternally());

// It should be possible to change this value also when in auto-commit mode.
connection.setRetryAbortsInternally(true);
assertTrue(connection.isRetryAbortsInternally());

// It should be possible to change this value also when in transactional mode, as long as
// there is no active transaction.
connection.setAutocommit(false);
connection.setRetryAbortsInternally(false);
assertFalse(connection.isRetryAbortsInternally());

// It should be possible to change the value when in read-only mode.
connection.setReadOnly(true);
connection.setRetryAbortsInternally(true);
assertTrue(connection.isRetryAbortsInternally());

// It should not be possible to change the value when there is an active transaction.
connection.setReadOnly(false);
connection.setAutocommit(false);
connection.execute(Statement.of(SELECT));
assertThrows(SpannerException.class, () -> connection.setRetryAbortsInternally(false));
// Verify that the value did not change.
assertTrue(connection.isRetryAbortsInternally());

// Rolling back the connection should allow us to set the property again.
connection.rollback();
connection.setRetryAbortsInternally(false);
assertFalse(connection.isRetryAbortsInternally());
}
}

private void assertThrowResultNotAllowed(
AbstractStatementParser parser, String sql, ImmutableSet<ResultType> allowedResultTypes) {
SpannerException exception =
Expand Down