Beispiel #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();
  }
Beispiel #2
0
  /**
   * Test that requesting connections from a partition that is empty will fetch it from other
   * partitions that still have connections.
   */
  @Test
  public void testPartitionDrain() throws InterruptedException, SQLException {
    CommonTestUtils.logTestInfo("Test connections obtained from alternate partition");

    config.setAcquireIncrement(1);
    config.setMinConnectionsPerPartition(10);
    config.setMaxConnectionsPerPartition(10);
    config.setPartitionCount(2);
    BoneCP dsb = new BoneCP(config);
    for (int i = 0; i < 20; i++) {
      dsb.getConnection();
    }
    assertEquals(20, dsb.getTotalLeased());
    assertEquals(0, dsb.getTotalFree());
    dsb.close();
    CommonTestUtils.logPass();
  }
Beispiel #3
0
  @Test
  public void testGetReleaseSingleThread() throws InterruptedException, SQLException {
    CommonTestUtils.logTestInfo("Test simple get/release connection from 1 partition");

    config.setMinConnectionsPerPartition(30);
    config.setMaxConnectionsPerPartition(100);
    config.setAcquireIncrement(5);
    config.setPartitionCount(1);
    BoneCP dsb = new BoneCP(config);

    for (int i = 0; i < 60; i++) {
      Connection conn = dsb.getConnection();
      conn.close();
    }
    assertEquals(0, dsb.getTotalLeased());
    assertEquals(30, dsb.getTotalFree());

    dsb.shutdown();
    CommonTestUtils.logPass();
  }
Beispiel #4
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();
  }