Skip to content
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 @@ -1457,4 +1457,30 @@ public void testClientIdReusedOnDatabaseNotFound() {
}
}
}

@Test
public void testBatchCreateSessionsPermissionDenied() {
mockSpanner.setBatchCreateSessionsExecutionTime(
SimulatedExecutionTime.ofStickyException(
Status.PERMISSION_DENIED.withDescription("Not permitted").asRuntimeException()));
try (Spanner spanner =
SpannerOptions.newBuilder()
.setProjectId("my-project")
.setChannelProvider(channelProvider)
.setCredentials(NoCredentials.getInstance())
.build()
.getService()) {
DatabaseId databaseId = DatabaseId.of("my-project", "my-instance", "my-database");
DatabaseClient client = spanner.getDatabaseClient(databaseId);
// The following call is non-blocking and will not generate an exception.
ResultSet rs = client.singleUse().executeQuery(SELECT1);
try {
// Actually trying to get any results will cause an exception.
rs.next();
fail("missing PERMISSION_DENIED exception");
} catch (SpannerException e) {
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.PERMISSION_DENIED);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.google.cloud.spanner.IntegrationTest;
import com.google.cloud.spanner.KeySet;
import com.google.cloud.spanner.Options;
import com.google.cloud.spanner.ResultSet;
import com.google.cloud.spanner.SessionPoolOptions;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerException;
Expand Down Expand Up @@ -184,11 +185,15 @@ public void deniedGetDatabase() {

@Test
public void deniedRead() {
// Getting a session and starting a read is non-blocking and will not cause an exception. Trying
// to get results from the result set will.
ResultSet rs =
databaseClient
.singleUse()
.read("nonexistent-table", KeySet.all(), Arrays.asList("nonexistent-col"));
try {
// Tests that the initial create session request returns a permission denied.
databaseClient
.singleUse()
.read("nonexistent-table", KeySet.all(), Arrays.asList("nonexistent-col"));
rs.next();
fail("Expected PERMISSION_DENIED SpannerException");
} catch (SpannerException e) {
checkExceptionForVPCError(e);
Expand Down