Esempio n. 1
0
 public void TestFillUpToWork()
 {
     using (TestDynamicPool testInst = new TestDynamicPool(0, 10))
     {
         Assert.AreEqual(0, testInst.ElementCount);
         testInst.FillPoolUpTo(5);
         Assert.AreEqual(5, testInst.ElementCount);
         testInst.FillPoolUpTo(10);
         Assert.AreEqual(10, testInst.ElementCount);
         testInst.FillPoolUpTo(100);
         Assert.AreEqual(10, testInst.ElementCount);
     }
 }
        public void TestIsBetterCreateNew()
        {
            using (TestDynamicPool testInst = new TestDynamicPool(0, 10))
            {
                testInst.FillPoolUpTo(1);

                Assert.AreEqual(1, testInst.ElementCount);

                testInst.AlwaysCreateNew = true;

                for (int i = 1; i < 10; i++)
                {
                    using (var item = testInst.Rent())
                    {
                        Assert.IsTrue(item.IsValid);
                    }
                    Assert.AreEqual(i + 1, testInst.ElementCount);
                }

                for (int i = 0; i < 10; i++)
                {
                    using (var item = testInst.Rent())
                    {
                        Assert.IsTrue(item.IsValid);
                    }
                    Assert.AreEqual(10, testInst.ElementCount);
                }
            }
        }
        public void TestRentInOrder()
        {
            using (TestDynamicPool testInst = new TestDynamicPool(0, 1000))
            {
                testInst.FillPoolUpTo(1000);

                List <RentedElementMonitor <TestPoolElem> > rented = new List <RentedElementMonitor <TestPoolElem> >();

                for (int i = 0; i < 1000; i++)
                {
                    rented.Add(testInst.Rent());
                }

                for (int i = 0; i < rented.Count - 1; i++)
                {
                    Assert.IsTrue(rented[i].Element.Value > rented[i + 1].Element.Value);
                }

                for (int i = 0; i < rented.Count; i++)
                {
                    rented[i].Dispose();
                    Assert.AreEqual(i + 1, testInst.FreeElementCount);
                }
            }
        }
Esempio n. 4
0
        public void TestTrimWork()
        {
            using (TestDynamicPool testInst = new TestDynamicPool(0, 10, 1000))
            {
                testInst.FillPoolUpTo(10);
                Assert.AreEqual(10, testInst.ElementCount);

                Stopwatch sw = Stopwatch.StartNew();

                while (sw.ElapsedMilliseconds < 1500)
                {
                    using (var item = testInst.Rent())
                    {
                        Assert.IsTrue(item.IsValid);
                    }
                }

                Assert.AreEqual(1, testInst.ElementCount);
            }
        }