use of com.google.spanner.v1.DeleteSessionRequest in project google-cloud-java by GoogleCloudPlatform.
the class GrpcSpannerRpc method deleteSession.
@Override
public void deleteSession(String sessionName, @Nullable Map<Option, ?> options) {
DeleteSessionRequest request = DeleteSessionRequest.newBuilder().setName(sessionName).build();
get(doUnaryCall(SpannerGrpc.METHOD_DELETE_SESSION, request, sessionName, Option.CHANNEL_HINT.getLong(options)));
}
use of com.google.spanner.v1.DeleteSessionRequest in project java-spanner by googleapis.
the class MockSpannerServiceImpl method deleteSession.
@Override
public void deleteSession(DeleteSessionRequest request, StreamObserver<Empty> responseObserver) {
requests.add(request);
Preconditions.checkNotNull(request.getName());
try {
deleteSessionExecutionTime.simulateExecutionTime(exceptions, stickyGlobalExceptions, freezeLock);
Session session = sessions.get(request.getName());
if (session != null) {
try {
doDeleteSession(session);
} catch (Throwable e) {
responseObserver.onError(Status.INTERNAL.asRuntimeException());
return;
}
}
responseObserver.onNext(Empty.getDefaultInstance());
responseObserver.onCompleted();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
}
}
use of com.google.spanner.v1.DeleteSessionRequest in project java-spanner by googleapis.
the class SpannerClientTest method deleteSessionTest.
@Test
public void deleteSessionTest() throws Exception {
Empty expectedResponse = Empty.newBuilder().build();
mockSpanner.addResponse(expectedResponse);
SessionName name = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
client.deleteSession(name);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteSessionRequest actualRequest = ((DeleteSessionRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.v1.DeleteSessionRequest in project java-spanner by googleapis.
the class GapicSpannerRpc method asyncDeleteSession.
@Override
public ApiFuture<Empty> asyncDeleteSession(String sessionName, @Nullable Map<Option, ?> options) {
DeleteSessionRequest request = DeleteSessionRequest.newBuilder().setName(sessionName).build();
GrpcCallContext context = newCallContext(options, sessionName, request, SpannerGrpc.getDeleteSessionMethod());
return spannerStub.deleteSessionCallable().futureCall(request, context);
}
use of com.google.spanner.v1.DeleteSessionRequest in project java-spanner by googleapis.
the class DatabaseClientImplTest method testBackendPartitionQueryOptions.
@Test
public void testBackendPartitionQueryOptions() {
// from the session pool interfering with the test case.
try (Spanner spanner = SpannerOptions.newBuilder().setProjectId("[PROJECT]").setChannelProvider(channelProvider).setCredentials(NoCredentials.getInstance()).setSessionPoolOption(SessionPoolOptions.newBuilder().setMinSessions(0).build()).build().getService()) {
BatchClient client = spanner.getBatchClient(DatabaseId.of("[PROJECT]", "[INSTANCE]", "[DATABASE"));
BatchReadOnlyTransaction transaction = client.batchReadOnlyTransaction(TimestampBound.strong());
List<Partition> partitions = transaction.partitionQuery(PartitionOptions.newBuilder().setMaxPartitions(10L).build(), Statement.newBuilder(SELECT1.getSql()).withQueryOptions(QueryOptions.newBuilder().setOptimizerVersion("1").setOptimizerStatisticsPackage("custom-package").build()).build());
try (ResultSet rs = transaction.execute(partitions.get(0))) {
// Just iterate over the results to execute the query.
while (rs.next()) {
}
} finally {
transaction.cleanup();
}
// Check if the last query executed is a DeleteSessionRequest and the second last query
// executed is a ExecuteSqlRequest and was executed using a custom optimizer version and
// statistics package.
List<AbstractMessage> requests = mockSpanner.getRequests();
assert requests.size() >= 2 : "required to have at least 2 requests";
assertThat(requests.get(requests.size() - 1)).isInstanceOf(DeleteSessionRequest.class);
assertThat(requests.get(requests.size() - 2)).isInstanceOf(ExecuteSqlRequest.class);
ExecuteSqlRequest executeSqlRequest = (ExecuteSqlRequest) requests.get(requests.size() - 2);
assertThat(executeSqlRequest.getQueryOptions()).isNotNull();
assertThat(executeSqlRequest.getQueryOptions().getOptimizerVersion()).isEqualTo("1");
assertThat(executeSqlRequest.getQueryOptions().getOptimizerStatisticsPackage()).isEqualTo("custom-package");
}
}
Aggregations