Example usage for org.apache.commons.pool BaseObjectPool BaseObjectPool

List of usage examples for org.apache.commons.pool BaseObjectPool BaseObjectPool

Introduction

In this page you can find the example usage for org.apache.commons.pool BaseObjectPool BaseObjectPool.

Prototype

public BaseObjectPool() 

Source Link

Usage

From source file:edu.illinois.enforcemop.examples.apache.pool.TestBaseObjectPool.java

public void testUnsupportedOperations() throws Exception {
    if (!getClass().equals(TestBaseObjectPool.class)) {
        return; // skip redundant tests
    }//  w  w w .  j  a va 2  s.c o  m
    ObjectPool pool = new BaseObjectPool() {
        public Object borrowObject() {
            return null;
        }

        public void returnObject(Object obj) {
        }

        public void invalidateObject(Object obj) {
        }
    };

    assertTrue("Negative expected.", pool.getNumIdle() < 0);
    assertTrue("Negative expected.", pool.getNumActive() < 0);

    try {
        pool.clear();
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        pool.addObject();
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        pool.setFactory(null);
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
        // expected
    }
}

From source file:edu.illinois.enforcemop.examples.apache.pool.TestBaseObjectPool.java

public void testClose() throws Exception {
    ObjectPool pool = new BaseObjectPool() {
        public Object borrowObject() {
            return null;
        }// ww  w  . j  a  va  2  s  . c  om

        public void returnObject(Object obj) {
        }

        public void invalidateObject(Object obj) {
        }
    };

    pool.close();
    pool.close(); // should not error as of Pool 2.0.
}