Beispiel #1
0
        public void ActivateOnObjectOnBorrow()
        {
            A.CallTo(() => factory.ValidateObject(null)).WithAnyArguments().Returns(true);

            Assert.AreEqual(0, pool.NumActive, "active wrong");
            Assert.AreEqual(1, pool.NumIdle, "idle wrong");
            pool.BorrowObject();
            Assert.AreEqual(1, pool.NumActive, "active wrong");
            Assert.AreEqual(0, pool.NumIdle, "idle wrong");

            A.CallTo(() => factory.ActivateObject(null)).WithAnyArguments().MustHaveHappened();
        }
        public void WaitOnBorrowWhenExausted()
        {
            int n = 100;

            object[] objects = new object[n];
            pool = new SimplePool(new MyFactory(), n);
            for (int i = 0; i < n; i++)
            {
                objects[i] = pool.BorrowObject();
            }
            Latch  latch  = new Latch();
            ISync  sync   = new Latch();
            Helper helper = new Helper(latch, sync, pool);
            Thread thread = new Thread(new ThreadStart(helper.UsePool));

            thread.Start();
            Assert.AreEqual(n, pool.NumActive);
            Assert.AreEqual(0, pool.NumIdle);
            object released = objects[n - 1];

            pool.ReturnObject(released);
            latch.Acquire();
            Assert.AreEqual(n, pool.NumActive);
            Assert.AreEqual(0, pool.NumIdle);
            Assert.IsNotNull(helper.gotFromPool, "helper did not get from pool");
            Assert.AreSame(released, helper.gotFromPool, "got unexpected object");
        }
Beispiel #3
0
        public void ThrowsExceptionWhenOutOfItemsBecauseFailedValidation()
        {
            object o = new object();

            A.CallTo(() => factory.MakeObject()).Returns(o);
            A.CallTo(() => factory.ValidateObject(o)).Returns(false);

            pool = new SimplePool(factory, 1);
            Assert.Throws <PoolException>(() => pool.BorrowObject());
        }
        public void ThrowsExceptionWhenOutOfItemsBecauseFailedValidation()
        {
            object o = new object();

            Expect.Call(factory.MakeObject()).Return(o);
            Expect.Call(factory.ValidateObject(o)).Return(false);
            mocks.ReplayAll();

            pool = new SimplePool(factory, 1);
            pool.BorrowObject();
            mocks.VerifyAll();
        }
 public void Run()
 {
     lock (this.GetType())
     {
         //Console.Out.WriteLine("#{0} running (created/run: {1}/{2})...", id, created, nRun);
         nRun++;
     }
     for (int i = 0; i < repeat; i++)
     {
         QueryPerformance.IQueried queried = pool.BorrowObject() as QueryPerformance.IQueried;
         queried.Run();
         pool.ReturnObject(queried);
         runned = true;
     }
     run.Release();
 }
        public void ActivateOnObjectOnBorrow()
        {
            Expect.Call(factory.ValidateObject(null)).IgnoreArguments().Return(true).Repeat.Any();
            factory.ActivateObject(null);
            LastCall.IgnoreArguments();
            mocks.ReplayAll();

            Assert.AreEqual(0, pool.NumActive, "active wrong");
            Assert.AreEqual(1, pool.NumIdle, "idle wrong");
            pool.BorrowObject();
            Assert.AreEqual(1, pool.NumActive, "active wrong");
            Assert.AreEqual(0, pool.NumIdle, "idle wrong");
            mocks.VerifyAll();
        }