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 #2
0
        public void PassivateObjectOnReturn()
        {
            A.CallTo(() => factory.ValidateObject(null)).WithAnyArguments().Returns(true);

            pool.ReturnObject(pool.BorrowObject());
            A.CallTo(() => factory.PassivateObject(null)).WithAnyArguments().MustHaveHappened();
        }
        public void PassivateObjectOnReturn()
        {
            Expect.Call(factory.ValidateObject(null)).IgnoreArguments().Return(true).Repeat.Any();
            factory.PassivateObject(null);
            LastCall.IgnoreArguments();
            mocks.ReplayAll();

            pool.ReturnObject(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();
 }