Ejemplo n.º 1
0
	    public PooledQueuedExecutor(int size)
	    {
            //// <example name="create-pool">
            pool = new SimplePool(new QueuedExecutorPoolableFactory(), size);
            //// </example>	        
            syncs = ArrayList.Synchronized(new ArrayList());
	    }
Ejemplo n.º 2
0
            public void Run()
            {
                SimplePool pool = new SimplePool(new Pooled(creationTime, executionTime), poolSize);
                for (int i = 0; i < clientSize; i++)
                {
                    Client client = new Client(i, run, pool, repeat);
                    Thread thread = new Thread(new ThreadStart(client.Run));
                    thread.Start();
                    clients.Add(client);
                }
                run.Acquire();

                foreach (Client client in clients)
                    Assert.IsTrue(client.runned, "\nclient " + clients.IndexOf(client) + " not runned");
            }
Ejemplo n.º 3
0
 public Client(int id, ISync run, SimplePool pool, int repeat)
 {
     this.run = run;
     this.pool = pool;
     this.id = id;
     lock (this.GetType())
     {
         created++;
         //Console.Out.WriteLine("#{0} created (created/run: {1}/{2})...", id, created, nRun);
     }
     this.repeat = repeat;
 }
Ejemplo n.º 4
0
 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");
 }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        public void SetUp()
        {
            mocks = new MockRepository();
            factory = (IPoolableObjectFactory) mocks.DynamicMock(typeof(IPoolableObjectFactory));
            Expect.Call(factory.MakeObject()).Return(new object()).Repeat.Any();

            mocks.ReplayAll();
            pool = new SimplePool(factory, 1);

            mocks.BackToRecordAll();
        }