예제 #1
0
  /** Tests that new connections are created on the fly. */
  @Test
  public void testConnectionCreate() throws InterruptedException, SQLException {
    CommonTestUtils.logTestInfo("Tests that new connections are created on the fly");
    config.setMinConnectionsPerPartition(10);
    config.setMaxConnectionsPerPartition(20);
    config.setAcquireIncrement(5);
    config.setPartitionCount(1);
    config.setReleaseHelperThreads(0);

    BoneCP dsb = new BoneCP(config);

    assertEquals(10, dsb.getTotalCreatedConnections());
    assertEquals(0, dsb.getTotalLeased());

    for (int i = 0; i < 10; i++) {
      dsb.getConnection();
    }
    assertEquals(10, dsb.getTotalLeased());

    for (int i = 0; i < 60; i++) {
      Thread.yield();
      Thread.sleep(2000); // give time for pool watch thread to fire up
      if (dsb.getTotalCreatedConnections() == 15) {
        break;
      }
    }
    assertEquals(15, dsb.getTotalCreatedConnections());
    assertEquals(10, dsb.getTotalLeased());
    assertEquals(5, dsb.getTotalFree());

    dsb.shutdown();
    CommonTestUtils.logPass();
  }
예제 #2
0
  /** Tests that new connections are created on the fly. */
  @Test
  public void testConnectionCreate() throws InterruptedException, SQLException {
    CommonTestUtils.logTestInfo("Tests that new connections are created on the fly");
    config.setMinConnectionsPerPartition(10);
    config.setMaxConnectionsPerPartition(20);
    config.setAcquireIncrement(5);
    config.setPartitionCount(1);
    config.setReleaseHelperThreads(0);
    config.setPoolAvailabilityThreshold(0);

    BoneCP dsb = new BoneCP(config);

    assertEquals(10, dsb.getTotalCreatedConnections());
    assertEquals(0, dsb.getTotalLeased());

    Connection[] con = new Connection[10];
    for (int i = 0; i < 10; i++) {
      con[i] = dsb.getConnection(); // keep track of it to avoid finalizer
    }
    assertEquals(10, dsb.getTotalLeased());

    for (int i = 0; i < 10; i++) {
      Thread.yield();
      Thread.sleep(500); // give time for pool watch thread to fire up
      if (dsb.getTotalCreatedConnections() == 15) {
        break;
      }
    }
    assertEquals(15, dsb.getTotalCreatedConnections());
    assertEquals(10, dsb.getTotalLeased());
    assertEquals(5, dsb.getTotalFree());

    for (Connection c : con) {
      c.close();
    }

    dsb.shutdown();
    CommonTestUtils.logPass();
  }