Search in sources :

Example 1 with GetSessionRequest

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

the class MockSpannerServiceImpl method getSession.

@Override
public void getSession(GetSessionRequest request, StreamObserver<Session> responseObserver) {
    requests.add(request);
    Preconditions.checkNotNull(request.getName());
    try {
        getSessionExecutionTime.simulateExecutionTime(exceptions, stickyGlobalExceptions, freezeLock);
        Session session = sessions.get(request.getName());
        if (session == null) {
            setSessionNotFound(request.getName(), responseObserver);
        } else {
            session = session.toBuilder().setApproximateLastUseTime(getCurrentGoogleTimestamp()).build();
            responseObserver.onNext(session);
            responseObserver.onCompleted();
        }
    } catch (StatusRuntimeException e) {
        responseObserver.onError(e);
    } catch (Throwable t) {
        responseObserver.onError(Status.INTERNAL.asRuntimeException());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) Session(com.google.spanner.v1.Session)

Example 2 with GetSessionRequest

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

the class SpannerClientTest method getSessionTest2.

@Test
public void getSessionTest2() throws Exception {
    Session expectedResponse = Session.newBuilder().setName(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).setApproximateLastUseTime(Timestamp.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    String name = "name3373707";
    Session actualResponse = client.getSession(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetSessionRequest actualRequest = ((GetSessionRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : GetSessionRequest(com.google.spanner.v1.GetSessionRequest) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 3 with GetSessionRequest

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

the class SpannerClientTest method getSessionTest.

@Test
public void getSessionTest() throws Exception {
    Session expectedResponse = Session.newBuilder().setName(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).setApproximateLastUseTime(Timestamp.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    SessionName name = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
    Session actualResponse = client.getSession(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetSessionRequest actualRequest = ((GetSessionRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : GetSessionRequest(com.google.spanner.v1.GetSessionRequest) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) SessionName(com.google.spanner.v1.SessionName) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Aggregations

Session (com.google.spanner.v1.Session)3 AbstractMessage (com.google.protobuf.AbstractMessage)2 GetSessionRequest (com.google.spanner.v1.GetSessionRequest)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ByteString (com.google.protobuf.ByteString)1 SessionName (com.google.spanner.v1.SessionName)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1