/*
         * Delete Current Session
         */

        public static void EndSession(Spanner.SpannerClient client, Session session)
        {
            DeleteSessionRequest deleteSessionRequest = new DeleteSessionRequest();

            deleteSessionRequest.Name = session.Name;
            client.DeleteSession(deleteSessionRequest);
            return;
        }
        /*
         * 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);
        }
예제 #3
0
        public void CreateSessionWithNewChannel()
        {
            IList <AsyncUnaryCall <Session> > calls = new List <AsyncUnaryCall <Session> >();

            for (int i = 0; i < DefaultMaxChannelsPerTarget; i++)
            {
                var call = client.CreateSessionAsync(
                    new CreateSessionRequest {
                    Database = DatabaseUrl
                });
                calls.Add(call);
                Assert.AreEqual(i + 1, invoker.GetChannelRefsForTest().Count);
            }
            for (int i = 0; i < calls.Count; i++)
            {
                client.DeleteSession(
                    new DeleteSessionRequest {
                    Name = calls[i].ResponseAsync.Result.Name
                });
            }

            calls.Clear();

            for (int i = 0; i < DefaultMaxChannelsPerTarget; i++)
            {
                var call = client.CreateSessionAsync(
                    new CreateSessionRequest {
                    Database = DatabaseUrl
                });
                calls.Add(call);
                Assert.AreEqual(DefaultMaxChannelsPerTarget, invoker.GetChannelRefsForTest().Count);
            }
            for (int i = 0; i < calls.Count; i++)
            {
                client.DeleteSession(
                    new DeleteSessionRequest {
                    Name = calls[i].ResponseAsync.Result.Name
                });
            }
        }