/*
         * Probes to test ExecuteSql and ExecuteStreamingSql call from Spanner stub.
         *
         * Args:
         *  stub: An object of SpannerStub.
         *  metrics: A list of metrics.
         *
         */

        public static void executeSql(Spanner.SpannerClient client, ref Dictionary <string, long> metrics)
        {
            long latency;

            //Create Session
            Session session = StartSession(client);

            //Probing ExecuteSql Call
            stopwatch.Start();
            ExecuteSqlRequest executeSqlRequest = new ExecuteSqlRequest();

            executeSqlRequest.Session = session.Name;
            executeSqlRequest.Sql     = "select * FROM users";
            client.ExecuteSql(executeSqlRequest);
            stopwatch.Stop();
            latency = stopwatch.ElapsedMilliseconds;
            metrics.Add("execute_sql_latency_ms", latency);

            //Probing ExecuteStreamingSql Call
            AsyncServerStreamingCall <PartialResultSet> partial_result_set = client.ExecuteStreamingSql(executeSqlRequest);

            stopwatch.Start();
            var header = partial_result_set.ResponseHeadersAsync;

            stopwatch.Stop();
            latency = stopwatch.ElapsedMilliseconds;
            metrics.Add("execute_streaming_sql_latency_ms", latency);

            //Delete Session
            EndSession(client, session);
        }
 public void ExecuteSql()
 {
     Session session;
     {
         CreateSessionRequest request = new CreateSessionRequest
         {
             Database = DatabaseUrl
         };
         session = client.CreateSession(request);
         Assert.IsNotNull(session);
         AssertAffinityCount(1);
     }
     {
         ExecuteSqlRequest request = new ExecuteSqlRequest
         {
             Session = session.Name,
             Sql     = string.Format("select id, data from {0}", TableName)
         };
         ResultSet resultSet = client.ExecuteSql(request);
         AssertAffinityCount(1);
         Assert.IsNotNull(resultSet);
         Assert.AreEqual(1, resultSet.Rows.Count);
         Assert.AreEqual(ColumnId, resultSet.Rows[0].Values[0].StringValue);
     }
     {
         DeleteSessionRequest request = new DeleteSessionRequest
         {
             Name = session.Name
         };
         client.DeleteSession(request);
         AssertAffinityCount(0);
     }
 }