当前位置: 首页>>代码示例>>Java>>正文


Java ObjectPool.addObject方法代码示例

本文整理汇总了Java中org.apache.commons.pool.ObjectPool.addObject方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectPool.addObject方法的具体用法?Java ObjectPool.addObject怎么用?Java ObjectPool.addObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.pool.ObjectPool的用法示例。


在下文中一共展示了ObjectPool.addObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testExceptionOnActivate

import org.apache.commons.pool.ObjectPool; //导入方法依赖的package包/类
/**
 * Verifies that exceptions thrown by factory activate method are not propagated to
 * the caller.  Objects that throw on activate are destroyed and if none succeed,
 * the caller gets NoSuchElementException.
 */
public void testExceptionOnActivate() throws Exception {
    SelectiveFactory factory = new SelectiveFactory();
    ObjectPool pool = new StackObjectPool(factory);
    pool.addObject();
    pool.addObject();
    factory.setThrowOnActivate(true);
    try {
        pool.borrowObject();
        fail("Expecting NoSuchElementException");
    } catch (NoSuchElementException ex) {
        // expected
    }
    assertEquals(0, pool.getNumIdle());
    assertEquals(0, pool.getNumActive());
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:21,代码来源:TestStackObjectPool.java

示例2: testExceptionOnDestroy

import org.apache.commons.pool.ObjectPool; //导入方法依赖的package包/类
/**
 * Verifies that exceptions thrown by factory destroy are swallowed
 * by both addObject and returnObject.
 */
public void testExceptionOnDestroy() throws Exception {
    SelectiveFactory factory = new SelectiveFactory();
    ObjectPool pool = new StackObjectPool(factory, 2);
    factory.setThrowOnDestroy(true);
    for (int i = 0; i < 3; i++) {
        pool.addObject(); // Third one will destroy, exception should be swallowed
    }
    assertEquals(2, pool.getNumIdle());
    
    Object[] objects = new Object[3];
    for (int i = 0; i < 3; i++) {
        objects[i] = pool.borrowObject();
    }
    for (int i = 0; i < 3; i++) {
        pool.returnObject(objects[i]); // Third triggers destroy
    } 
    assertEquals(2, pool.getNumIdle());
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:23,代码来源:TestStackObjectPool.java

示例3: testExceptionOnPassivate

import org.apache.commons.pool.ObjectPool; //导入方法依赖的package包/类
/**
 * Verifies that addObject propagates exceptions thrown by
 * factory passivate, but returnObject swallows these.
 */
public void testExceptionOnPassivate() throws Exception {
    SelectiveFactory factory = new SelectiveFactory();
    ObjectPool pool = new StackObjectPool(factory, 2);
    factory.setThrowOnPassivate(true);
    
    // addObject propagates
    try {
        pool.addObject();
        fail("Expecting IntegerFactoryException");
    } catch (IntegerFactoryException ex) {
        assertEquals("passivateObject", ex.getType());
        assertEquals(0, ex.getValue());
    }
    assertEquals(0, pool.getNumIdle());
    
    // returnObject swallows 
    Object obj = pool.borrowObject();
    pool.returnObject(obj);
    assertEquals(0, pool.getNumIdle());
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:25,代码来源:TestStackObjectPool.java

示例4: testAddObject

import org.apache.commons.pool.ObjectPool; //导入方法依赖的package包/类
public void testAddObject() throws Exception {
    assertEquals("should be zero idle", 0, pool.getNumIdle());
    pool.addObject();
    assertEquals("should be one idle", 1, pool.getNumIdle());
    assertEquals("should be zero active", 0, pool.getNumActive());
    Object obj = pool.borrowObject();
    assertEquals("should be zero idle", 0, pool.getNumIdle());
    assertEquals("should be one active", 1, pool.getNumActive());
    pool.returnObject(obj);
    assertEquals("should be one idle", 1, pool.getNumIdle());
    assertEquals("should be zero active", 0, pool.getNumActive());

    ObjectPool op = new GenericObjectPool();
    try {
        op.addObject();
        fail("Expected IllegalStateException when there is no factory.");
    } catch (IllegalStateException ise) {
        //expected
    }
    op.close();
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:22,代码来源:TestGenericObjectPool.java

示例5: testInitIdleCapacityExceeded

import org.apache.commons.pool.ObjectPool; //导入方法依赖的package包/类
/**
 * Verifies that initIdleCapacity is not a hard limit, but maxIdle is.
 */
public void testInitIdleCapacityExceeded() throws Exception {
    PoolableObjectFactory factory = new SimpleFactory();
    ObjectPool pool = new StackObjectPool(factory, 2, 1);
    pool.addObject();
    pool.addObject();
    assertEquals(2, pool.getNumIdle());
    pool.close();
    pool = new StackObjectPool(factory, 1, 2);
    pool.addObject();
    pool.addObject();
    assertEquals(1, pool.getNumIdle());
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:16,代码来源:TestStackObjectPool.java


注:本文中的org.apache.commons.pool.ObjectPool.addObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。