package org.jfox.pool;

import junit.framework.TestCase;

/**
 * @author <a href="mailto:yangyong@ufsoft.com.cn">Young Yang</a>
 */

public class SimpleObjectPoolTest extends TestCase {
    SimpleObjectPool pool;

    public void setUp() throws Exception {
        super.setUp();
    }

    public void tearDown() throws Exception {

    }

    public void testSimpleObjectPool() throws Exception {
        pool = new SimpleObjectPool(SimpleObjectFactory.class, TestPoolableObject.class);

        pool.init();

        System.out.println("Working: " + pool.getWorking() + ", Rest: " + pool.getRest());

        TestPoolableObject tpobj = (TestPoolableObject) pool.retrieveObject();

        System.out.println("Working: " + pool.getWorking() + ", Rest: " + pool.getRest());

        System.out.println("word from pool: " + tpobj.say());

        pool.restoreObject(tpobj);

        System.out.println("Working: " + pool.getWorking() + ", Rest: " + pool.getRest());

    }

    public void testTimeout() throws Exception {
        pool = new SimpleObjectPool(SimpleObjectFactory.class, TestPoolableObject.class, 5, 10, 10 * 1000);

        pool.init();

        TestPoolableObject tpobj = (TestPoolableObject) pool.retrieveObject();

        System.out.println("Working: " + pool.getWorking() + ", Rest: " + pool.getRest());
        System.out.println("sleeptime: " + tpobj.getSleepTime());
        pool.restoreObject(tpobj);

        System.out.println("Working: " + pool.getWorking() + ", Rest: " + pool.getRest());

    }

}