function sessionManagement()

in cloudprober/grpc_gpc_prober/spanner_probes.php [42:83]


function sessionManagement($client, &$metrics){
	global $_DATABASE;

	$createSessionRequest = new Google\Cloud\Spanner\V1\CreateSessionRequest();
	$createSessionRequest->setDatabase($_DATABASE);
	#Create Session test
	#Create
	$time_start = microtime_float();
	list($session, $status) = $client->CreateSession($createSessionRequest)->wait();

	hardAssertIfStatusOk($status);
	hardAssert($session !== null, 'Call completed with a null response');

	$lantency =  (microtime_float()- $time_start) * 1000;
	$metrics['create_session_latency_ms'] = $lantency;

	#Get Session
	$getSessionRequest = new Google\Cloud\Spanner\V1\GetSessionRequest();
	$getSessionRequest->setName($session->getName());
	$time_start = microtime_float();
	$response = $client->GetSession($getSessionRequest);
	$response->wait();
	$lantency =  (microtime_float() - $time_start) * 1000;
	$metrics['get_session_latency_ms'] = $lantency;

	#List session
	$listSessionsRequest = new Google\Cloud\Spanner\V1\ListSessionsRequest();
	$listSessionsRequest->setDatabase($_DATABASE);
	$time_start = microtime_float();
	$response = $client->ListSessions($listSessionsRequest);
	$lantency =  (microtime_float() - $time_start) * 1000;
	$metrics['list_sessions_latency_ms'] = $lantency;

	#Delete session
	$deleteSessionRequest = new Google\Cloud\Spanner\V1\DeleteSessionRequest();
	$deleteSessionRequest->setName($session->getName());
	$time_start = microtime_float();
	$client->deleteSession($deleteSessionRequest);
	$lantency =  (microtime_float() - $time_start) * 1000;
	$metrics['delete_session_latency_ms'] = $lantency;

}