Example #1
0
        public void CreateListDeleteSession()
        {
            Session session;
            {
                CreateSessionRequest request = new CreateSessionRequest
                {
                    Database = DatabaseUrl
                };
                session = client.CreateSession(request);
                Assert.IsNotNull(session);
                AssertAffinityCount(1);
            }

            {
                ListSessionsRequest request = new ListSessionsRequest
                {
                    Database = DatabaseUrl
                };
                ListSessionsResponse response = client.ListSessions(request);
                Assert.IsNotNull(response);
                Assert.IsNotNull(response.Sessions);
                Assert.IsTrue(response.Sessions.Any(item => item.Name == session.Name));
                AssertAffinityCount(1);
            }

            {
                DeleteSessionRequest request = new DeleteSessionRequest
                {
                    Name = session.Name
                };
                client.DeleteSession(request);
                AssertAffinityCount(0);
            }

            {
                ListSessionsRequest request = new ListSessionsRequest
                {
                    Database = DatabaseUrl
                };
                ListSessionsResponse response = client.ListSessions(request);
                Assert.IsNotNull(response);
                Assert.IsNotNull(response.Sessions);
                Assert.IsFalse(response.Sessions.Any(item => item.Name == session.Name));
                AssertAffinityCount(0);
            }
        }
        /*
         * Probes to test session related grpc call from Spanner stub.
         *
         * Includes tests against CreateSession, GetSession, ListSessions, and
         * DeleteSession of Spanner stub.
         *
         * Args:
         *  stub: An object of SpannerStub.
         *  metrics: A list of metrics.
         *
         */

        public static void sessionManagement(Spanner.SpannerClient client, ref Dictionary <string, long> metrics)
        {
            long latency;
            CreateSessionRequest createSessionRequest = new CreateSessionRequest();

            createSessionRequest.Database = _DATABASE;
            //Create Session test
            //Create
            stopwatch.Start();
            Session session = client.CreateSession(createSessionRequest);

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

            //Get Session
            GetSessionRequest getSessionRequest = new GetSessionRequest();

            getSessionRequest.Name = session.Name;
            stopwatch.Start();
            client.GetSession(getSessionRequest);
            stopwatch.Stop();
            latency = stopwatch.ElapsedMilliseconds;
            metrics.Add("get_session_latency_ms", latency);

            //List Session
            ListSessionsRequest listSessionsRequest = new ListSessionsRequest();

            listSessionsRequest.Database = _DATABASE;
            stopwatch.Start();
            client.ListSessions(listSessionsRequest);
            stopwatch.Stop();
            latency = stopwatch.ElapsedMilliseconds;
            metrics.Add("list_sessions_latency_ms", latency);

            //Delete Session
            DeleteSessionRequest deleteSessionRequest = new DeleteSessionRequest();

            deleteSessionRequest.Name = session.Name;
            stopwatch.Start();
            client.DeleteSession(deleteSessionRequest);
            stopwatch.Stop();
            latency = stopwatch.ElapsedMilliseconds;
            metrics.Add("delete_session_latency_ms", latency);
        }