Пример #1
0
    public void IsAliveFalseIfLifetimeIsExceed()
    {
        var now     = 1_000_000;
        var timeAgo = now - (30 * 1000);
        var isAlive = ConnectionPoolLifetimeHelper.IsAlive(20, timeAgo, now);

        Assert.IsFalse(isAlive);
    }
Пример #2
0
    public void IsAliveTrueIfLifetimeNotExceed()
    {
        var now     = 1_000_000;
        var timeAgo = now - (10 * 1000);
        var isAlive = ConnectionPoolLifetimeHelper.IsAlive(20, timeAgo, now);

        Assert.IsTrue(isAlive);
    }
        public void IsAliveTrueIfLifetimeNotExceed()
        {
            var timeAgo = Environment.TickCount - (10 * 1000);             //10 seconds
            var now     = Environment.TickCount;
            var isAlive = ConnectionPoolLifetimeHelper.IsAlive(20, timeAgo, now);

            Assert.IsTrue(isAlive);
        }
        public void IsAliveFalseIfLifetimeIsExceed()
        {
            var timeAgo = Environment.TickCount - (30 * 1000);              //30 seconds
            var now     = Environment.TickCount;
            var isAlive = ConnectionPoolLifetimeHelper.IsAlive(20, timeAgo, now);

            Assert.IsFalse(isAlive);
        }
        public void PrunePool()
        {
            lock (_syncRoot)
            {
                CheckDisposedImpl();

                var now       = GetTicks();
                var available = _available.ToList();
                if (available.Count <= _connectionString.MinPoolSize)
                {
                    return;
                }
                var keep      = available.Where(x => ConnectionPoolLifetimeHelper.IsAlive(_connectionString.ConnectionLifetime, x.Created, now)).ToList();
                var keepCount = keep.Count;
                if (keepCount < _connectionString.MinPoolSize)
                {
                    keep = keep.Concat(available.Except(keep).OrderByDescending(x => x.Created).Take(_connectionString.MinPoolSize - keepCount)).ToList();
                }
                var release = available.Except(keep).ToList();
                Parallel.ForEach(release, x => x.Release());
                _available = new Stack <Item>(keep);
            }
        }