Ejemplo n.º 1
0
            public void ShouldCloseTheConnectionIfSessionIsHealthyButThePoolIsFull()
            {
                var mock = new Mock <IPooledSession>();

                mock.Setup(x => x.IsHealthy).Returns(true);
                var id = new Guid();

                var inUseSessions = new Dictionary <Guid, IPooledSession>();

                inUseSessions.Add(id, mock.Object);

                var availableSessions = new Queue <IPooledSession>();
                var pooledSessionMock = new Mock <IPooledSession>();

                for (int i = 0; i < Config.DefaultConfig.MaxIdleSessionPoolSize; i++)
                {
                    availableSessions.Enqueue(pooledSessionMock.Object);
                }

                var pool = new SessionPool(availableSessions, inUseSessions);

                pool.NumberOfAvailableSessions.Should().Be(10);
                pool.NumberOfInUseSessions.Should().Be(1);

                pool.Release(id);

                pool.NumberOfAvailableSessions.Should().Be(10);
                pool.NumberOfInUseSessions.Should().Be(0);
                mock.Verify(x => x.Close(), Times.Once);
            }
Ejemplo n.º 2
0
            public void ShouldReturnToPoolWhenSessionIsHealthyAndPoolIsNotFull()
            {
                var mock = new Mock <IPooledSession>();

                mock.Setup(x => x.IsHealthy).Returns(true);
                var id = new Guid();

                var inUseSessions = new Dictionary <Guid, IPooledSession>();

                inUseSessions.Add(id, mock.Object);
                var pool = new SessionPool(null, inUseSessions);

                pool.NumberOfAvailableSessions.Should().Be(0);
                pool.NumberOfInUseSessions.Should().Be(1);

                pool.Release(id);

                pool.NumberOfAvailableSessions.Should().Be(1);
                pool.NumberOfInUseSessions.Should().Be(0);
            }
Ejemplo n.º 3
0
            public void ShouldCloseSessionWhenSessionIsUnhealthy()
            {
                var mock = new Mock <IPooledSession>();

                mock.Setup(x => x.IsHealthy).Returns(false);
                var id = new Guid();

                var inUseSessions = new Dictionary <Guid, IPooledSession>();

                inUseSessions.Add(id, mock.Object);
                var pool = new SessionPool(null, inUseSessions);

                pool.NumberOfAvailableSessions.Should().Be(0);
                pool.NumberOfInUseSessions.Should().Be(1);

                pool.Release(id);

                pool.NumberOfAvailableSessions.Should().Be(0);
                pool.NumberOfInUseSessions.Should().Be(0);
                mock.Verify(x => x.Close(), Times.Once);
            }