Search in sources :

Example 6 with DeleteSessionRequest

use of com.google.spanner.v1.DeleteSessionRequest in project java-spanner by googleapis.

the class SpannerClient method deleteSession.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Ends a session, releasing server resources associated with it. This will asynchronously trigger
 * cancellation of any operations that are running with this session.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (SpannerClient spannerClient = SpannerClient.create()) {
 *   String name = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString();
 *   spannerClient.deleteSession(name);
 * }
 * }</pre>
 *
 * @param name Required. The name of the session to delete.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteSession(String name) {
    DeleteSessionRequest request = DeleteSessionRequest.newBuilder().setName(name).build();
    deleteSession(request);
}
Also used : DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest)

Example 7 with DeleteSessionRequest

use of com.google.spanner.v1.DeleteSessionRequest in project java-spanner by googleapis.

the class SpannerClient method deleteSession.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Ends a session, releasing server resources associated with it. This will asynchronously trigger
 * cancellation of any operations that are running with this session.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (SpannerClient spannerClient = SpannerClient.create()) {
 *   SessionName name = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
 *   spannerClient.deleteSession(name);
 * }
 * }</pre>
 *
 * @param name Required. The name of the session to delete.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteSession(SessionName name) {
    DeleteSessionRequest request = DeleteSessionRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteSession(request);
}
Also used : DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest)

Example 8 with DeleteSessionRequest

use of com.google.spanner.v1.DeleteSessionRequest in project java-spanner by googleapis.

the class SpannerClientTest method deleteSessionTest2.

@Test
public void deleteSessionTest2() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockSpanner.addResponse(expectedResponse);
    String name = "name3373707";
    client.deleteSession(name);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteSessionRequest actualRequest = ((DeleteSessionRequest) actualRequests.get(0));
    Assert.assertEquals(name, 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) ByteString(com.google.protobuf.ByteString) 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