in cloudprober/src/main/java/com/google/grpc/cloudprober/SpannerProbes.java [65:102]
public static void sessionManagementProber(
SpannerGrpc.SpannerBlockingStub stub) throws ProberException {
Session session = null;
try {
session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(DATABASE).build());
// Get session.
Session responseGet =
stub.getSession(GetSessionRequest.newBuilder().setName(session.getName()).build());
if (!session.getName().equals(responseGet.getName())) {
throw new ProberException(
String.format(
"Incorrect session name %s, should be %s.",
responseGet.getName(), session.getName()));
}
// List sessions.
ListSessionsResponse responseList =
stub.listSessions(ListSessionsRequest.newBuilder().setDatabase(DATABASE).build());
int inList = 0;
for (Session s : responseList.getSessionsList()) {
if (s.getName().equals(session.getName())) {
inList = 1;
break;
}
}
if (inList == 0) {
throw new ProberException(
String.format("The session list doesn't contain %s.", session.getName()));
}
} finally {
deleteSession(stub, session);
}
}