/// <summary>Snippet for BatchCreateSessions</summary>
 public void BatchCreateSessions()
 {
     // Snippet: BatchCreateSessions(DatabaseName,CallSettings)
     // Create client
     SpannerClient spannerClient = SpannerClient.Create();
     // Initialize request argument(s)
     DatabaseName database = new DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]");
     // Make the request
     BatchCreateSessionsResponse response = spannerClient.BatchCreateSessions(database);
     // End snippet
 }
 /// <summary>Snippet for BatchCreateSessions</summary>
 public void BatchCreateSessions_RequestObject()
 {
     // Snippet: BatchCreateSessions(BatchCreateSessionsRequest,CallSettings)
     // Create client
     SpannerClient spannerClient = SpannerClient.Create();
     // Initialize request argument(s)
     BatchCreateSessionsRequest request = new BatchCreateSessionsRequest
     {
         DatabaseAsDatabaseName = new DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"),
     };
     // Make the request
     BatchCreateSessionsResponse response = spannerClient.BatchCreateSessions(request);
     // End snippet
 }
        /// <summary>Snippet for BatchCreateSessionsAsync</summary>
        public async Task BatchCreateSessionsAsync()
        {
            // Snippet: BatchCreateSessionsAsync(DatabaseName,CallSettings)
            // Additional: BatchCreateSessionsAsync(DatabaseName,CancellationToken)
            // Create client
            SpannerClient spannerClient = await SpannerClient.CreateAsync();

            // Initialize request argument(s)
            DatabaseName database = new DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]");
            // Make the request
            BatchCreateSessionsResponse response = await spannerClient.BatchCreateSessionsAsync(database);

            // End snippet
        }
예제 #4
0
        public async Task BatchCreateSessionsAsync2()
        {
            Mock <Spanner.SpannerClient> mockGrpcClient = new Mock <Spanner.SpannerClient>(MockBehavior.Strict);
            BatchCreateSessionsRequest   request        = new BatchCreateSessionsRequest
            {
                DatabaseAsDatabaseName = new DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"),
            };
            BatchCreateSessionsResponse expectedResponse = new BatchCreateSessionsResponse();

            mockGrpcClient.Setup(x => x.BatchCreateSessionsAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <BatchCreateSessionsResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            SpannerClient client = new SpannerClientImpl(mockGrpcClient.Object, null);
            BatchCreateSessionsResponse response = await client.BatchCreateSessionsAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #5
0
        public void BatchCreateSessions2()
        {
            Mock <Spanner.SpannerClient> mockGrpcClient = new Mock <Spanner.SpannerClient>(MockBehavior.Strict);
            BatchCreateSessionsRequest   request        = new BatchCreateSessionsRequest
            {
                DatabaseAsDatabaseName = new DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"),
            };
            BatchCreateSessionsResponse expectedResponse = new BatchCreateSessionsResponse();

            mockGrpcClient.Setup(x => x.BatchCreateSessions(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            SpannerClient client = new SpannerClientImpl(mockGrpcClient.Object, null);
            BatchCreateSessionsResponse response = client.BatchCreateSessions(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #6
0
        /// <summary>Snippet for BatchCreateSessionsAsync</summary>
        public async Task BatchCreateSessionsAsync_RequestObject()
        {
            // Snippet: BatchCreateSessionsAsync(BatchCreateSessionsRequest,CallSettings)
            // Additional: BatchCreateSessionsAsync(BatchCreateSessionsRequest,CancellationToken)
            // Create client
            SpannerClient spannerClient = await SpannerClient.CreateAsync();

            // Initialize request argument(s)
            BatchCreateSessionsRequest request = new BatchCreateSessionsRequest
            {
                DatabaseAsDatabaseName = new DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"),
                SessionCount           = 0,
            };
            // Make the request
            BatchCreateSessionsResponse response = await spannerClient.BatchCreateSessionsAsync(request);

            // End snippet
        }
        public void BatchCreateSessions()
        {
            SpannerClientBuilder builder = new SpannerClientBuilder
            {
                Endpoint           = _fixture.Endpoint,
                ChannelCredentials = ChannelCredentials.Insecure
            };
            SpannerClient client = builder.Build();
            BatchCreateSessionsRequest request = new BatchCreateSessionsRequest
            {
                Database        = "projects/p1/instances/i1/databases/d1",
                SessionCount    = 25,
                SessionTemplate = new Session()
            };
            BatchCreateSessionsResponse response = client.BatchCreateSessions(request);

            Assert.Equal(25, response.Session.Count);
        }
예제 #8
0
            public override async Task <BatchCreateSessionsResponse> BatchCreateSessionsAsync(BatchCreateSessionsRequest request, CallSettings callSettings = null)
            {
                await CheckFailAllRpcs();

                await Scheduler.Delay(CreateSessionDelay);

                var database = request.DatabaseAsDatabaseName;
                BatchCreateSessionsResponse response = new BatchCreateSessionsResponse();
                int count;

                for (int i = 0; i < request.SessionCount; i++)
                {
                    count = Interlocked.Increment(ref _sessionCounter);
                    response.Session.Add(new Session {
                        SessionName = new SessionName(database.ProjectId, database.InstanceId, database.DatabaseId, $"session-{count}")
                    });
                }

                return(response);
            }
예제 #9
0
        internal static Mock <SpannerClient> SetupBatchCreateSessionsAsync(this Mock <SpannerClient> spannerClientMock)
        {
            spannerClientMock
            .Setup(client => client.BatchCreateSessionsAsync(It.IsNotNull <BatchCreateSessionsRequest>(), It.IsAny <CallSettings>()))
            .Returns <BatchCreateSessionsRequest, CallSettings>((request, _) =>
            {
                BatchCreateSessionsResponse response = new BatchCreateSessionsResponse();

                for (int i = 0; i < request.SessionCount; i++)
                {
                    var session         = request.SessionTemplate.Clone();
                    session.CreateTime  = session.ApproximateLastUseTime = spannerClientMock.GetNowTimestamp();
                    session.Expired     = false;
                    session.Name        = Guid.NewGuid().ToString();
                    session.SessionName = new SessionName(ProjectId, Instance, Database, session.Name);

                    response.Session.Add(session);
                }

                return(Task.FromResult(response));
            });
            return(spannerClientMock);
        }