예제 #1
0
 internal FakeSessionPool()
 {
     Mock    = SpannerClientHelpers.CreateMockClient(Logger);
     Options = new SessionPoolOptions
     {
         SessionEvictionJitter = RetrySettings.NoJitter,
         SessionRefreshJitter  = RetrySettings.NoJitter
     };
 }
            public void ReleaseDetachedSession_NoDelete()
            {
                var logger  = new InMemoryLogger();
                var mock    = SpannerClientHelpers.CreateMockClient(logger);
                var pool    = new SessionPool(mock.Object, new SessionPoolOptions());
                var session = pool.CreateDetachedSession(s_sampleSessionName, s_sampleTransactionId, ModeOneofCase.ReadOnly);

                // No calls to DeleteSession
                session.ReleaseToPool(false);
                logger.AssertNoWarningsOrErrors();
            }
예제 #3
0
        public void CreateDetachedSession()
        {
            var logger = new InMemoryLogger();
            var mock   = SpannerClientHelpers.CreateMockClient(logger);
            var pool   = new SessionPool(mock.Object, new SessionPoolOptions());

            var mode    = ModeOneofCase.ReadOnly;
            var session = pool.CreateDetachedSession(s_sampleSessionName, s_sampleTransactionId, mode);

            Assert.Equal(s_sampleSessionName, session.SessionName);
            Assert.Equal(s_sampleTransactionId, session.TransactionId);
            Assert.Equal(mode, session.TransactionMode);
            logger.AssertNoWarningsOrErrors();
        }
            public void ReleaseDetachedSession_Delete()
            {
                var logger = new InMemoryLogger();
                var mock   = SpannerClientHelpers.CreateMockClient(logger);

                // We will force the session to be deleted, so check it happens in the mock.
                mock.Setup(client => client.DeleteSessionAsync(new DeleteSessionRequest {
                    SessionName = s_sampleSessionName
                }, null))
                .Returns(Task.FromResult(0))
                .Verifiable();

                var pool    = new SessionPool(mock.Object, new SessionPoolOptions());
                var session = pool.CreateDetachedSession(s_sampleSessionName, s_sampleTransactionId, ModeOneofCase.ReadOnly);

                // Logically, the deletion happens asynchronously. However, everything completes synchronously so we don't need
                // to sleep or anything to wait for the call to come through.
                session.ReleaseToPool(true);
                logger.AssertNoWarningsOrErrors();
                mock.Verify();
            }