Example usage for org.apache.commons.pool KeyedObjectPool getNumIdle

List of usage examples for org.apache.commons.pool KeyedObjectPool getNumIdle

Introduction

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

Prototype

int getNumIdle() throws UnsupportedOperationException;

Source Link

Document

Returns the total number of instances currently idle in this pool (optional operation).

Usage

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

public void testUnsupportedOperations() throws Exception {
    if (!getClass().equals(TestBaseKeyedObjectPool.class)) {
        return; // skip redundant tests
    }//from  ww w.j  a  v  a  2  s.c o m
    KeyedObjectPool pool = new BaseKeyedObjectPool() {
        public Object borrowObject(Object key) {
            return null;
        }

        public void returnObject(Object key, Object obj) {
        }

        public void invalidateObject(Object key, Object obj) {
        }
    };

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

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

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

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

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

    pool.close(); // a no-op, probably should be remove

}