Package com.jolbox.bonecp

Examples of com.jolbox.bonecp.BoneCPDataSource


   * @throws InterruptedException
   * @throws SQLException
   */
  private BoneCPDataSource multiThreadedBoneCP(boolean doPreparedStatement, int partitions) throws PropertyVetoException, InterruptedException, SQLException {

    BoneCPDataSource dsb = new BoneCPDataSource();
    dsb.setDriverClass("com.jolbox.bonecp.MockJDBCDriver");
    dsb.setJdbcUrl(url);
    dsb.setUsername(username);
    dsb.setPassword(password);
//    dsb.setPoolStrategy("CACHED");
    dsb.setDisableConnectionTracking(true);
    if (doPreparedStatement){
      dsb.setStatementsCacheSize(max_statement);
    } else {
      dsb.setStatementsCacheSize(0);
    }
    dsb.setMinConnectionsPerPartition(pool_size / partitions);
    dsb.setMaxConnectionsPerPartition(pool_size / partitions);
    dsb.setPartitionCount(partitions);
    dsb.setAcquireIncrement(5);
    return dsb;

  }
View Full Code Here


                return mock(Connection.class);
            }
        });
        DriverManager.registerDriver(dummyDriver);

        testDataSource = new BoneCPDataSource();
        testDataSource.setJdbcUrl("jdbc://dummy:url");
        testDataSource.setPartitionCount(1);
        testDataSource.setMinConnectionsPerPartition(1);
        testDataSource.setMaxConnectionsPerPartition(6);
        testDataSource.setConnectionTimeoutInMs(5000);
View Full Code Here

    {
//      System.setProperty("oracle.jdbc.ReadTimeout", "5000");

      Class.forName("org.postgresql.Driver");

      BoneCPDataSource ds = new BoneCPDataSource();
      ds.setJdbcUrl("jdbc:postgresql://localhost/postgres");
      ds.setUsername("postgres");
      ds.setPassword("postgres");
      ds.setDefaultAutoCommit(false);
      ds.sanitize();

      System.out.println("Initial connection test");
      testConnection(ds);

      System.out.println("Unplug your network cable ");
View Full Code Here

    if (!(oldDS instanceof BoneCPDataSource)){
      throw new SQLException("Unknown datasource type! Was expecting BoneCPDataSource but received "+oldDS.getClass()+". Not switching datasource!");
    }
   
    BoneCPDataSource newDS = new BoneCPDataSource(newConfig);
    newDS.getConnection().close(); // initialize a connection (+ throw it away) to force the datasource to initialize the pool
   
    // force application to start using the new one
    setTargetDataSource(newDS);
   
    logger.info("Shutting down old datasource slowly. Old Config: "+oldDS);
View Full Code Here

   * @throws ClassNotFoundException
   */
  @Test
  public void testSwitchDataSource() throws SQLException, ClassNotFoundException {

    BoneCPDataSource mockDataSource = createNiceMock(BoneCPDataSource.class);
    DynamicDataSourceProxy ddsp = new DynamicDataSourceProxy();
    // Test #1: Check for correct instance.
    ddsp.setTargetDataSource(new DelegatingDataSource());
    try{
      ddsp.switchDataSource(null);
      fail("Should throw an exception");
    } catch(SQLException e){
      // do nothing
    }
   
    // Test #2: Given a good config, should initialize pool and switch datasource to it
    BoneCPConfig config = new BoneCPConfig();
    config.setJdbcUrl("jdbc:mock");
    config.setUsername("sa");
    config.setPassword("");
    config.setMinConnectionsPerPartition(2);
    config.setMaxConnectionsPerPartition(2);
    config.setPartitionCount(1);
   

    ddsp = new DynamicDataSourceProxy(mockDataSource);

    // Old datasource should be closed.
    mockDataSource.close();
    expectLastCall().once();
    replay(mockDataSource);
    ddsp.switchDataSource(config);
    // and a new datasource should be in place
    assertNotSame(mockDataSource, ddsp.getTargetDataSource());
View Full Code Here

TOP

Related Classes of com.jolbox.bonecp.BoneCPDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.