Example #1
0
 public void TestAcquireNew()
 {
     using (var pool = new Pool <Item>(x => new Item(), new SilentLog()))
     {
         var item1 = pool.AcquireNew();
         pool.Release(item1);
         var item2 = pool.AcquireNew();
         Assert.That(item2, Is.Not.EqualTo(item1));
     }
 }
        public void TestAcquireNew()
        {
            var metricsMock = new Mock <IConnectionPoolMetrics>(MockBehavior.Strict);

            metricsMock.Setup(x => x.AcquireNewConnectionContext())
            .Returns(NoOpContext.Instance)
            .Verifiable();
            using (var pool = new Pool <Item>(x => new Item(), metricsMock.Object, new SilentLog()))
            {
                var item1 = pool.AcquireNew();
                pool.Release(item1);
                var item2 = pool.AcquireNew();
                Assert.That(item2, Is.Not.EqualTo(item1));
                metricsMock.Verify(x => x.AcquireNewConnectionContext(), Times.Exactly(2));
            }
        }
Example #3
0
 public void TestAcquireExists()
 {
     using (var pool = new Pool <Item>(x => new Item(), new SilentLog()))
     {
         var item1 = pool.AcquireNew();
         pool.Release(item1);
         Assert.That(pool.TryAcquireExists(out var item2));
         Assert.That(item2, Is.EqualTo(item1));
         Assert.That(!pool.TryAcquireExists(out var item3));
     }
 }