// @Test
  public void testConnectionCloseBlocking() throws SQLException {
    HikariConfig config = new HikariConfig();
    config.setMinimumIdle(0);
    config.setMaximumPoolSize(1);
    config.setConnectionTimeout(1500);
    config.setDataSource(new CustomMockDataSource());

    long start = ClockSource.INSTANCE.currentTime();
    try (HikariDataSource ds = new HikariDataSource(config)) {
      Connection connection = ds.getConnection();
      connection.close();

      // Hikari only checks for validity for connections with lastAccess > 1000 ms so we sleep for
      // 1001 ms to force
      // Hikari to do a connection validation which will fail and will trigger the connection to be
      // closed
      UtilityElf.quietlySleep(1100L);

      shouldFail = true;

      // on physical connection close we sleep 2 seconds
      connection = ds.getConnection();

      Assert.assertTrue(
          "Waited longer than timeout",
          (ClockSource.INSTANCE.elapsedMillis(start) < config.getConnectionTimeout()));
    } catch (SQLException e) {
      Assert.assertTrue(
          "getConnection failed because close connection took longer than timeout",
          (ClockSource.INSTANCE.elapsedMillis(start) < config.getConnectionTimeout()));
    }
  }
 public static JdbcFs getFileSystemProvider(String url, String user, String pass, String dialect) {
   HikariConfig config = new HikariConfig();
   config.setDataSource(new DriverManagerDataSource(url, user, pass));
   config.setMinimumIdle(1);
   config.setMaximumPoolSize(2);
   return new JdbcFs(
       new AlarmEnabledDataSource(
           url, ChimeraFsHelper.class.getSimpleName(), new HikariDataSource(config)),
       dialect);
 }
  public MySQLDatabase(
      Logger log, String ip, String port, String database, String username, String password) {
    super(log, "MySQL");
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl("jdbc:mysql://" + ip + ":" + port + "/" + database);
    hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
    hikariConfig.setUsername(username);
    hikariConfig.setPassword(password);
    hikariConfig.setMinimumIdle(1);
    hikariConfig.setMaximumPoolSize(10);
    hikariConfig.setConnectionTimeout(10000);

    _source = new HikariDataSource(hikariConfig);
  }
Beispiel #4
0
  /**
   * get HikariCP Common Configuration
   *
   * @return
   */
  private HikariConfig getHikariConfig() {
    HikariConfig config = new HikariConfig();

    config.setMinimumIdle(minimumIdle);
    config.setMaximumPoolSize(maximumPoolSize);
    config.setConnectionTestQuery(validationQuery);
    config.setConnectionTimeout(connectionTimeout);
    config.setAutoCommit(isAutoCommit);

    config.addDataSourceProperty("cachePrepStmts", cachePrepStmts);
    config.addDataSourceProperty("prepStmtCacheSize", prepStmtCacheSize);
    config.addDataSourceProperty("useServerPrepStmts", useServerPrepStmts);

    return config;
  }