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());
}
}
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()));
}
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()));
}
Aggregations