Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.cloud.spanner.SpannerImpl.PageFetcher;
import com.google.cloud.spanner.spi.v1.SpannerRpc;
import com.google.cloud.spanner.spi.v1.SpannerRpc.Paginated;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.protobuf.Empty;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
Expand Down Expand Up @@ -155,7 +156,18 @@ public Page<Database> listDatabases(String instanceId, ListOption... options) {
@Override
public Paginated<com.google.spanner.admin.database.v1.Database> getNextPage(
String nextPageToken) {
return rpc.listDatabases(instanceName, pageSize, nextPageToken);
try {
return rpc.listDatabases(instanceName, pageSize, nextPageToken);
} catch (SpannerException e) {
throw SpannerExceptionFactory.newSpannerException(
e.getErrorCode(),
String.format(
"Failed to list the databases of %s with pageToken %s: %s",
instanceName,
MoreObjects.firstNonNull(nextPageToken, "<null>"),
e.getMessage()),
e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -170,6 +171,39 @@ public void listDatabases() {
assertThat(dbs.size()).isEqualTo(2);
}

@Test
public void listDatabasesError() {
when(rpc.listDatabases(INSTANCE_NAME, 1, null))
.thenThrow(
SpannerExceptionFactory.newSpannerException(ErrorCode.INVALID_ARGUMENT, "Test error"));
try {
client.listDatabases(INSTANCE_ID, Options.pageSize(1));
Assert.fail("Missing expected exception");
} catch (SpannerException e) {
assertThat(e.getMessage()).contains(INSTANCE_NAME);
// Assert that the call was done without a page token.
assertThat(e.getMessage()).contains("with pageToken <null>");
}
}

@Test
public void listDatabaseErrorWithToken() {
String pageToken = "token";
when(rpc.listDatabases(INSTANCE_NAME, 1, null))
.thenReturn(new Paginated<>(ImmutableList.<Database>of(getDatabaseProto()), pageToken));
when(rpc.listDatabases(INSTANCE_NAME, 1, pageToken))
.thenThrow(
SpannerExceptionFactory.newSpannerException(ErrorCode.INVALID_ARGUMENT, "Test error"));
try {
Lists.newArrayList(client.listDatabases(INSTANCE_ID, Options.pageSize(1)).iterateAll());
Assert.fail("Missing expected exception");
} catch (SpannerException e) {
assertThat(e.getMessage()).contains(INSTANCE_NAME);
// Assert that the call was done without a page token.
assertThat(e.getMessage()).contains(String.format("with pageToken %s", pageToken));
}
}

@Test
public void getDatabaseIAMPolicy() {
when(rpc.getDatabaseAdminIAMPolicy(DB_NAME))
Expand Down