Search in sources :

Example 1 with DeleteSessionRequest

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)));
}
Also used : DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest)

Example 2 with DeleteSessionRequest

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);
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) Session(com.google.spanner.v1.Session)

Example 3 with DeleteSessionRequest

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()));
}
Also used : Empty(com.google.protobuf.Empty) DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest) AbstractMessage(com.google.protobuf.AbstractMessage) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 4 with DeleteSessionRequest

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);
}
Also used : DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext)

Example 5 with DeleteSessionRequest

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");
    }
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ExecuteSqlRequest(com.google.spanner.v1.ExecuteSqlRequest) Test(org.junit.Test)

Aggregations

DeleteSessionRequest (com.google.spanner.v1.DeleteSessionRequest)6 AbstractMessage (com.google.protobuf.AbstractMessage)3 Test (org.junit.Test)3 Empty (com.google.protobuf.Empty)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 ByteString (com.google.protobuf.ByteString)1 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)1 Session (com.google.spanner.v1.Session)1 SessionName (com.google.spanner.v1.SessionName)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1