Skip to content
Closed
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 @@ -30,9 +30,6 @@ public static <T> T getOrNull(ApiFuture<T> future) throws SpannerException {
try {
return future == null ? null : future.get();
} catch (ExecutionException e) {
if (e.getCause() instanceof SpannerException) {
throw (SpannerException) e.getCause();
}
throw SpannerExceptionFactory.asSpannerException(e.getCause());
} catch (InterruptedException e) {
throw SpannerExceptionFactory.propagateInterrupt(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public void cancel() throws Exception {
assertThat(list).containsExactlyElementsIn(createExpectedRows());
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment thread
sakthivelmanii marked this conversation as resolved.
Resolved
Comment thread
sakthivelmanii marked this conversation as resolved.
Resolved
Comment on lines 446 to +447

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

For consistency and to avoid redundant assertions, we can remove assertThat(e.getCause()).isInstanceOf(SpannerException.class) since SpannerExceptionFactory.asSpannerException safely handles any exception type.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.CANCELLED);
assertThat(cancelledIndexes).contains(index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void toListAsyncPropagatesError() {
ExecutionException.class,
() -> rs.toListAsync(ignored -> new Object(), executor).get());
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 178 to +179

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

For consistency and to avoid redundant assertions, we can remove assertThat(e.getCause()).isInstanceOf(SpannerException.class) since SpannerExceptionFactory.asSpannerException safely handles any exception type.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
assertThat(se.getMessage()).contains("invalid query");
}
Expand Down Expand Up @@ -505,7 +505,7 @@ public void callbackReturnsError() throws InterruptedException {
});
ExecutionException e = assertThrows(ExecutionException.class, () -> rs.getResult().get());
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 507 to +508

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

For consistency and to avoid redundant assertions, we can remove assertThat(e.getCause()).isInstanceOf(SpannerException.class) since SpannerExceptionFactory.asSpannerException safely handles any exception type.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.UNKNOWN);
assertThat(se.getMessage()).contains("async test");
assertThat(callbackCounter.get()).isEqualTo(1);
Expand Down Expand Up @@ -535,7 +535,7 @@ public void callbackReturnsErrorWhileBufferIsFull_shouldStopProducer() throws Ex
ExecutionException e =
assertThrows(ExecutionException.class, () -> result.get(30L, TimeUnit.SECONDS));
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 537 to +538

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

For consistency and to avoid redundant assertions, we can remove assertThat(e.getCause()).isInstanceOf(SpannerException.class) since SpannerExceptionFactory.asSpannerException safely handles any exception type.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.UNKNOWN);
assertThat(se.getMessage()).contains("async test");
// The producer should stop and release the underlying result set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void asyncRunnerInvalidUpdate() throws Exception {
runner.runAsync(txn -> txn.executeUpdateAsync(INVALID_UPDATE_STATEMENT), executor);
ExecutionException e = assertThrows(ExecutionException.class, () -> updateCount.get());
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 141 to +142

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

For consistency and to avoid redundant assertions, we can remove assertThat(e.getCause()).isInstanceOf(SpannerException.class) since SpannerExceptionFactory.asSpannerException safely handles any exception type.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
assertThat(se.getMessage()).contains("invalid statement");
}
Expand Down Expand Up @@ -288,7 +288,7 @@ public void asyncRunnerCommitFails() throws Exception {
executor);
ExecutionException e = assertThrows(ExecutionException.class, () -> updateCount.get());
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 290 to +291

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

For consistency and to avoid redundant assertions, we can remove assertThat(e.getCause()).isInstanceOf(SpannerException.class) since SpannerExceptionFactory.asSpannerException safely handles any exception type.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
assertThat(se.getMessage()).contains("mutation limit exceeded");
}
Expand Down Expand Up @@ -358,7 +358,7 @@ public void asyncRunnerInvalidBatchUpdate() throws Exception {
executor);
ExecutionException e = assertThrows(ExecutionException.class, () -> updateCount.get());
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 360 to +361

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

For consistency and to avoid redundant assertions, we can remove assertThat(e.getCause()).isInstanceOf(SpannerException.class) since SpannerExceptionFactory.asSpannerException safely handles any exception type.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
assertThat(se.getMessage()).contains("invalid statement");
}
Expand Down Expand Up @@ -505,7 +505,7 @@ public void asyncRunnerWithBatchUpdateCommitFails() throws Exception {
executor);
ExecutionException e = assertThrows(ExecutionException.class, () -> updateCount.get());
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 507 to +508

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

For consistency and to avoid redundant assertions, we can remove assertThat(e.getCause()).isInstanceOf(SpannerException.class) since SpannerExceptionFactory.asSpannerException safely handles any exception type.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
assertThat(se.getMessage()).contains("mutation limit exceeded");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ public void runAsyncWithException() throws Exception {

ExecutionException e = assertThrows(ExecutionException.class, fut::get);
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 1630 to +1631

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

For consistency and to avoid redundant assertions, we can remove assertThat(e.getCause()).isInstanceOf(SpannerException.class) since SpannerExceptionFactory.asSpannerException safely handles any exception type.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);

executor.shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected boolean shouldCacheError(Exception e) {
successCount++;
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
assertThat(((SpannerException) e.getCause()).getErrorCode())
assertThat(SpannerExceptionFactory.asSpannerException(e.getCause()).getErrorCode())
Comment on lines 182 to +183

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

For consistency and to avoid redundant assertions, we can remove assertThat(e.getCause()).isInstanceOf(SpannerException.class) since SpannerExceptionFactory.asSpannerException safely handles any exception type.

        assertThat(SpannerExceptionFactory.asSpannerException(e.getCause()).getErrorCode())

.isEqualTo(ErrorCode.UNAVAILABLE);
failureCount++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.cloud.spanner.SpannerExceptionFactory;

/** Integration tests for asynchronous APIs. */
@Category(ParallelIntegrationTest.class)
Expand Down Expand Up @@ -269,7 +270,7 @@ public void tableNotFound() throws Exception {
row.get();
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 272 to +273

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.

high

Since e.getCause() can be a GAX exception (which is the primary reason for using SpannerExceptionFactory.asSpannerException), asserting that the cause is directly an instance of SpannerException will cause the test to fail. We should remove this assertion.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.NOT_FOUND);
assertThat(se.getMessage()).contains("BadTableName");
}
Expand All @@ -285,7 +286,7 @@ public void columnNotFound() throws Exception {
row.get();
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 288 to +289

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.

high

Since e.getCause() can be a GAX exception, asserting that the cause is directly an instance of SpannerException will cause the test to fail. We should remove this assertion.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.NOT_FOUND);
assertThat(se.getMessage()).contains("BadColumnName");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.cloud.spanner.SpannerExceptionFactory;

/** Integration tests for asynchronous APIs. */
@Category(ParallelIntegrationTest.class)
Expand Down Expand Up @@ -503,7 +504,7 @@ public void cancel() throws Exception {
fail("missing expected exception");
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 506 to +507

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.

high

Since e.getCause() can be a GAX exception, the assertion assertThat(e.getCause()).isInstanceOf(SpannerException.class) will fail. We should remove it and rely on SpannerExceptionFactory.asSpannerException to handle the conversion.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

assertThat(se.getErrorCode()).isEqualTo(ErrorCode.CANCELLED);
assertThat(values).containsExactly("v0");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.cloud.spanner.SpannerExceptionFactory;

/** Integration test for commit timestamp of Cloud Spanner. */
@Category(ParallelIntegrationTest.class)
Expand Down Expand Up @@ -172,8 +173,7 @@ public void schemaChangeTimestampInFuture() throws Exception {
.get();
fail("missing expected exception");
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
assertThat(se.getErrorCode()).isEqualTo(ErrorCode.FAILED_PRECONDITION);
}
}
Expand Down Expand Up @@ -205,8 +205,7 @@ public void invalidColumnOption() throws Exception {
.get();
fail("missing expected exception");
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
assertThat(se.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
}
}
Expand All @@ -221,8 +220,7 @@ public void invalidColumnOptionValue() throws Exception {
.get();
fail("missing expected exception");
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
assertThat(se.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
}
}
Expand All @@ -240,8 +238,7 @@ public void invalidColumnType() throws Exception {
.get();
fail("missing expected exception");
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
assertThat(se.getErrorCode()).isEqualTo(ErrorCode.FAILED_PRECONDITION);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.cloud.spanner.SpannerExceptionFactory;

/** Integration tests for {@link com.google.cloud.spanner.DatabaseAdminClient}. */
@Category(ParallelIntegrationTest.class)
Expand Down Expand Up @@ -264,14 +265,10 @@ public void updateDatabaseInvalidFieldsToUpdate() {
OperationFuture<Database, UpdateDatabaseMetadata> op =
dbAdminClient.updateDatabase(databaseToUpdate);

try {
op.get(5, TimeUnit.MINUTES);
Assert.fail("No exception thrown");
} catch (ExecutionException | InterruptedException | TimeoutException e) {
Assert.assertTrue(e.getCause() instanceof SpannerException);
SpannerException exception = ((SpannerException) e.getCause());
assertEquals(ErrorCode.INVALID_ARGUMENT, exception.getErrorCode());
}
ExecutionException e = Assert.assertThrows(
ExecutionException.class, () -> op.get(5, TimeUnit.MINUTES));
SpannerException exception = SpannerExceptionFactory.asSpannerException(e.getCause());
assertEquals(ErrorCode.INVALID_ARGUMENT, exception.getErrorCode());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.cloud.spanner.SpannerExceptionFactory;
import java.util.concurrent.ExecutionException;

@Category(ParallelIntegrationTest.class)
@RunWith(JUnit4.class)
Expand Down Expand Up @@ -112,7 +114,7 @@ public void returnsTheVersionRetentionPeriodSetThroughGetDatabase() throws Excep
}

@Test(expected = DatabaseNotFoundException.class)
public void returnsAnErrorWhenAnInvalidVersionRetentionPeriodIsGiven() {
public void returnsAnErrorWhenAnInvalidVersionRetentionPeriodIsGiven() throws Exception {
Comment on lines 116 to +117

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.

high

The @Test(expected = DatabaseNotFoundException.class) annotation is incorrect here because the ExecutionException is caught and handled inside the try-catch block, meaning no exception will propagate out of the method. Keeping this annotation will cause the test to fail with an AssertionError because the expected exception is not thrown.

Suggested change
@Test(expected = DatabaseNotFoundException.class)
public void returnsAnErrorWhenAnInvalidVersionRetentionPeriodIsGiven() {
public void returnsAnErrorWhenAnInvalidVersionRetentionPeriodIsGiven() throws Exception {
@Test
public void returnsAnErrorWhenAnInvalidVersionRetentionPeriodIsGiven() throws Exception {

final String instanceId = testHelper.getInstanceId().getInstance();
final String databaseId = testHelper.getUniqueDatabaseId();
final String extraStatement =
Expand All @@ -121,8 +123,8 @@ public void returnsAnErrorWhenAnInvalidVersionRetentionPeriodIsGiven() {
try {
createDatabase(instanceId, databaseId, extraStatement);
fail("Expected invalid argument error when setting invalid version retention period");
} catch (Exception e) {
SpannerException spannerException = (SpannerException) e.getCause();
} catch (ExecutionException e) {
SpannerException spannerException = SpannerExceptionFactory.asSpannerException(e.getCause());
assertThat(spannerException.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.cloud.spanner.SpannerExceptionFactory;
import java.util.concurrent.ExecutionException;

@Category(ParallelIntegrationTest.class)
@RunWith(JUnit4.class)
Expand Down Expand Up @@ -149,7 +151,7 @@ public void returnsTheVersionRetentionPeriodSetThroughInformationSchema() {
}

@Test
public void returnsAnErrorWhenAnInvalidRetentionPeriodIsGiven() {
public void returnsAnErrorWhenAnInvalidRetentionPeriodIsGiven() throws Exception {
try {
dbAdminClient
.updateDatabaseDdl(
Expand All @@ -162,8 +164,8 @@ public void returnsAnErrorWhenAnInvalidRetentionPeriodIsGiven() {
"op_invalid_retention_period_" + databaseId)
.get(OPERATION_TIMEOUT.toNanos(), TimeUnit.NANOSECONDS);
fail("Expected invalid argument error when setting invalid version retention period");
} catch (Exception e) {
SpannerException spannerException = (SpannerException) e.getCause();
} catch (ExecutionException e) {
SpannerException spannerException = SpannerExceptionFactory.asSpannerException(e.getCause());
assertThat(spannerException.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import com.google.cloud.spanner.SpannerExceptionFactory;

@RunWith(Parameterized.class)
@Category(ParallelIntegrationTest.class)
Expand Down Expand Up @@ -160,7 +161,7 @@ public void testInvalidInsert() throws InterruptedException {
txn = manager.resetForRetryAsync();
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
Comment on lines 163 to +164

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.

high

The assertion assertThat(e.getCause()).isInstanceOf(SpannerException.class) should be removed because the cause can be a GAX exception, which would cause this assertion to fail.

Suggested change
assertThat(e.getCause()).isInstanceOf(SpannerException.class);
SpannerException se = (SpannerException) e.getCause();
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());
SpannerException se = SpannerExceptionFactory.asSpannerException(e.getCause());

if (env.getTestHelper()
.getOptions()
.getSessionPoolOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.runners.MethodSorters;
import com.google.cloud.spanner.SpannerExceptionFactory;

/**
* Integration tests creating, reading, updating and deleting backups. This test class combines
Expand Down Expand Up @@ -569,11 +570,7 @@ private <T> void getOrThrow(OperationFuture<T, ?> operation)
try {
operation.get();
} catch (ExecutionException e) {
if (e.getCause() instanceof SpannerException) {
throw (SpannerException) e.getCause();
} else {
throw e;
}
throw SpannerExceptionFactory.asSpannerException(e.getCause());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void copyBackup(
BackupName.of(projectId, instanceId, sourceBackupId), expireTime.toProto()).get();
System.out.println("Copied backup [" + destinationBackup.getName() + "]");
} catch (ExecutionException e) {
throw (SpannerException) e.getCause();
throw SpannerExceptionFactory.asSpannerException(e.getCause());
Comment thread
sakthivelmanii marked this conversation as resolved.
Resolved
} catch (InterruptedException e) {
throw SpannerExceptionFactory.propagateInterrupt(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void copyBackupWithMultiRegionEncryptionKey(
destinationBackup = databaseAdminClient.copyBackupAsync(request).get();
System.out.println("Copied backup [" + destinationBackup.getName() + "]");
} catch (ExecutionException e) {
throw (SpannerException) e.getCause();
throw SpannerExceptionFactory.asSpannerException(e.getCause());
Comment thread
sakthivelmanii marked this conversation as resolved.
Resolved
} catch (InterruptedException e) {
throw SpannerExceptionFactory.propagateInterrupt(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void createDatabaseWithDefaultLeader(String instanceName, String database
System.out.println("\tDefault leader: " + createdDatabase.getDefaultLeader());
} catch (ExecutionException e) {
// If the operation failed during execution, expose the cause.
throw (SpannerException) e.getCause();
throw SpannerExceptionFactory.asSpannerException(e.getCause());
Comment thread
sakthivelmanii marked this conversation as resolved.
Resolved
} catch (InterruptedException e) {
// Throw when a thread is waiting, sleeping, or otherwise occupied,
// and the thread is interrupted, either before or during the activity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void createDatabaseWithVersionRetentionPeriod(String projectId,
System.out.println("\tEarliest version time: " + database.getEarliestVersionTime());
} catch (ExecutionException e) {
// If the operation failed during execution, expose the cause.
throw (SpannerException) e.getCause();
throw SpannerExceptionFactory.asSpannerException(e.getCause());
Comment thread
sakthivelmanii marked this conversation as resolved.
Resolved
} catch (InterruptedException e) {
// Throw when a thread is waiting, sleeping, or otherwise occupied,
// and the thread is interrupted, either before or during the activity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.cloud.spanner.SpannerExceptionFactory;
Comment thread
sakthivelmanii marked this conversation as resolved.
Resolved
import java.util.concurrent.ExecutionException;

public class DatabaseAddSplitPointsSample {

Expand Down Expand Up @@ -110,11 +112,13 @@ static void addSplitPoints(String projectId, String instanceId, String databaseI
splitPoints.add(splitPointForIndex);
splitPoints.add(splitPointForIndexWitTableKey);
databaseAdminClient.addSplitPoints(
DatabaseName.of(projectId, instanceId, databaseId), splitPoints);
DatabaseName.of(projectId, instanceId, databaseId), splitPoints).get();

} catch (Exception e) {
} catch (ExecutionException e) {
// If the operation failed during execution, expose the cause.
throw (SpannerException) e.getCause();
throw SpannerExceptionFactory.asSpannerException(e.getCause());
} catch (InterruptedException e) {
throw SpannerExceptionFactory.propagateInterrupt(e);
}
}
}
Expand Down
Loading
Loading