Example #1
0
 @Test(expected = SQLException.class)
 public void testDBConnectionInvalidUsername() throws SQLException {
   CommonTestUtils.logTestInfo("Test trying to start up with an invalid username/pass combo.");
   config.setUsername("non existent");
   new BoneCP(config);
   CommonTestUtils.logPass();
 }
Example #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);

    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();
  }
Example #3
0
 @Test(expected = SQLException.class)
 public void testDBConnectionInvalidJDBCurl() throws SQLException {
   CommonTestUtils.logTestInfo("Test trying to start up with an invalid URL.");
   config.setJdbcUrl("invalid JDBC URL");
   new BoneCP(config);
   CommonTestUtils.logPass();
 }
Example #4
0
 @Test
 public void testMultithreadMultiPartition() throws InterruptedException, SQLException {
   CommonTestUtils.logTestInfo("Test multiple threads hitting a multiple partitions concurrently");
   config.setAcquireIncrement(5);
   config.setMinConnectionsPerPartition(10);
   config.setMaxConnectionsPerPartition(25);
   config.setPartitionCount(5);
   config.setReleaseHelperThreads(0);
   BoneCPDataSource dsb = new BoneCPDataSource(config);
   dsb.setDriverClass("org.hsqldb.jdbcDriver");
   CommonTestUtils.startThreadTest(100, 1000, dsb, 0, false);
   assertEquals(0, dsb.getTotalLeased());
   dsb.close();
   CommonTestUtils.logPass();
 }
  /**
   * Test bounce of inner connection.
   *
   * @throws IllegalArgumentException
   * @throws SecurityException
   * @throws IllegalAccessException
   * @throws InvocationTargetException
   */
  @Test
  public void testStandardMethods()
      throws IllegalArgumentException, SecurityException, IllegalAccessException,
          InvocationTargetException {
    Set<String> skipTests = new HashSet<String>();
    skipTests.add("close");
    skipTests.add("getConnection");
    skipTests.add("markPossiblyBroken");
    skipTests.add("trackStatement");
    skipTests.add("checkClosed");
    skipTests.add("isClosed");
    skipTests.add("internalClose");
    skipTests.add("prepareCall");
    skipTests.add("prepareStatement");
    skipTests.add("setClientInfo");
    skipTests.add("getConnectionLastUsed");
    skipTests.add("setConnectionLastUsed");
    skipTests.add("getConnectionLastReset");
    skipTests.add("setConnectionLastReset");
    skipTests.add("isPossiblyBroken");
    skipTests.add("getOriginatingPartition");
    skipTests.add("setOriginatingPartition");
    skipTests.add("renewConnection");
    skipTests.add("clearStatementCaches");
    skipTests.add("obtainInternalConnection");
    skipTests.add("sendInitSQL");
    skipTests.add("$VRi"); // this only comes into play when code coverage is started. Eclemma bug?

    CommonTestUtils.testStatementBounceMethod(mockConnection, testClass, skipTests, mockConnection);
  }
Example #6
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();
  }
Example #7
0
  @Test
  public void testMultithreadMultiPartitionWithRandomWorkDelay()
      throws InterruptedException, SQLException {
    CommonTestUtils.logTestInfo(
        "Test multiple threads hitting a partition and doing some work of random duration on each connection");
    config.setAcquireIncrement(5);
    config.setMinConnectionsPerPartition(10);
    config.setMaxConnectionsPerPartition(25);
    config.setPartitionCount(5);

    BoneCPDataSource dsb = new BoneCPDataSource(config);
    dsb.setDriverClass("org.hsqldb.jdbcDriver");

    CommonTestUtils.startThreadTest(100, 10, dsb, -50, false);
    assertEquals(0, dsb.getTotalLeased());
    dsb.close();
    CommonTestUtils.logPass();
  }
Example #8
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();
  }
Example #9
0
 @Test
 public void testClosedConnection() throws InterruptedException, SQLException {
   BoneCP dsb = null;
   CommonTestUtils.logTestInfo(
       "Tests that closed connections trigger exceptions if use is attempted.");
   config.setMinConnectionsPerPartition(10);
   config.setMaxConnectionsPerPartition(20);
   config.setAcquireIncrement(5);
   config.setPartitionCount(1);
   try {
     dsb = new BoneCP(config);
     Connection conn = dsb.getConnection();
     conn.prepareCall(CommonTestUtils.TEST_QUERY);
     conn.close();
     try {
       conn.prepareCall(CommonTestUtils.TEST_QUERY);
       fail("Should have thrown an exception");
     } catch (SQLException e) {
       CommonTestUtils.logPass();
     }
   } finally {
     dsb.shutdown();
   }
 }
  /**
   * Mock setup.
   *
   * @throws Exception
   */
  @BeforeClass
  public static void setUp() throws Exception {
    config = CommonTestUtils.getConfigClone();
    mockConnection = createNiceMock(ConnectionHandle.class);
    mockPreparedStatementCache = createNiceMock(IStatementCache.class);
    mockCallableStatementCache = createNiceMock(IStatementCache.class);

    mockLogger = createNiceMock(Logger.class);
    makeThreadSafe(mockLogger, true);
    mockPool = createNiceMock(BoneCP.class);
    mockPool.closeConnectionWatch = true;
    expect(mockPool.getConfig()).andReturn(config).anyTimes();
    config.setTransactionRecoveryEnabled(false);
    config.setStatementsCacheSize(1);
    replay(mockPool);
    testClass =
        new ConnectionHandle(
            mockConnection, mockPreparedStatementCache, mockCallableStatementCache, mockPool);
    testStatementCache = new StatementCache(100);
    Field field = testClass.getClass().getDeclaredField("logger");
    field.setAccessible(true);
    field.set(null, mockLogger);
    config.setReleaseHelperThreads(0);
  }
Example #11
0
 @BeforeClass
 public static void setup() throws ClassNotFoundException {
   Class.forName("org.hsqldb.jdbcDriver");
   config = CommonTestUtils.getConfigClone();
 }