Exemplo n.º 1
0
 @Test
 public void testBaseBorrow() throws Exception {
   try {
     _pool = makeEmptyPool(3);
   } catch (UnsupportedOperationException e) {
     return; // skip this test if unsupported
   }
   assertEquals(getNthObject(0), _pool.borrowObject());
   assertEquals(getNthObject(1), _pool.borrowObject());
   assertEquals(getNthObject(2), _pool.borrowObject());
   _pool.close();
 }
Exemplo n.º 2
0
 @Test
 public void testBaseAddObject() throws Exception {
   try {
     _pool = makeEmptyPool(3);
   } catch (UnsupportedOperationException e) {
     return; // skip this test if unsupported
   }
   try {
     assertEquals(0, _pool.getNumIdle());
     assertEquals(0, _pool.getNumActive());
     _pool.addObject();
     assertEquals(1, _pool.getNumIdle());
     assertEquals(0, _pool.getNumActive());
     String obj = _pool.borrowObject();
     assertEquals(getNthObject(0), obj);
     assertEquals(0, _pool.getNumIdle());
     assertEquals(1, _pool.getNumActive());
     _pool.returnObject(obj);
     assertEquals(1, _pool.getNumIdle());
     assertEquals(0, _pool.getNumActive());
   } catch (UnsupportedOperationException e) {
     return; // skip this test if one of those calls is unsupported
   } finally {
     _pool.close();
   }
 }
Exemplo n.º 3
0
  @Test
  public void testBaseClosePool() throws Exception {
    try {
      _pool = makeEmptyPool(3);
    } catch (UnsupportedOperationException e) {
      return; // skip this test if unsupported
    }
    String obj = _pool.borrowObject();
    _pool.returnObject(obj);

    _pool.close();
    try {
      _pool.borrowObject();
      fail("Expected IllegalStateException");
    } catch (IllegalStateException e) {
      // expected
    }
  }
Exemplo n.º 4
0
 @Test
 public void testBaseNumActiveNumIdle() throws Exception {
   try {
     _pool = makeEmptyPool(3);
   } catch (UnsupportedOperationException e) {
     return; // skip this test if unsupported
   }
   assertEquals(0, _pool.getNumActive());
   assertEquals(0, _pool.getNumIdle());
   String obj0 = _pool.borrowObject();
   assertEquals(1, _pool.getNumActive());
   assertEquals(0, _pool.getNumIdle());
   String obj1 = _pool.borrowObject();
   assertEquals(2, _pool.getNumActive());
   assertEquals(0, _pool.getNumIdle());
   _pool.returnObject(obj1);
   assertEquals(1, _pool.getNumActive());
   assertEquals(1, _pool.getNumIdle());
   _pool.returnObject(obj0);
   assertEquals(0, _pool.getNumActive());
   assertEquals(2, _pool.getNumIdle());
   _pool.close();
 }
Exemplo n.º 5
0
  @Test
  public void testBaseBorrowReturn() throws Exception {
    try {
      _pool = makeEmptyPool(3);
    } catch (UnsupportedOperationException e) {
      return; // skip this test if unsupported
    }
    String obj0 = _pool.borrowObject();
    assertEquals(getNthObject(0), obj0);
    String obj1 = _pool.borrowObject();
    assertEquals(getNthObject(1), obj1);
    String obj2 = _pool.borrowObject();
    assertEquals(getNthObject(2), obj2);
    _pool.returnObject(obj2);
    obj2 = _pool.borrowObject();
    assertEquals(getNthObject(2), obj2);
    _pool.returnObject(obj1);
    obj1 = _pool.borrowObject();
    assertEquals(getNthObject(1), obj1);
    _pool.returnObject(obj0);
    _pool.returnObject(obj2);
    obj2 = _pool.borrowObject();
    if (isLifo()) {
      assertEquals(getNthObject(2), obj2);
    }
    if (isFifo()) {
      assertEquals(getNthObject(0), obj2);
    }

    obj0 = _pool.borrowObject();
    if (isLifo()) {
      assertEquals(getNthObject(0), obj0);
    }
    if (isFifo()) {
      assertEquals(getNthObject(2), obj0);
    }
    _pool.close();
  }
Exemplo n.º 6
0
 public static final IndexedRingBuffer getInstance() {
   return POOL.borrowObject();
 }