// Path: src/test/java/io/vertx/ThreadLeakCheckerRule.java
// public class ThreadLeakCheckerRule implements TestRule {
// 
//   private final Predicate<Thread> predicate;
// 
//   public ThreadLeakCheckerRule() {
//     this(t ->
//       t.getName().equals("vertx-jdbc-service-get-connection-thread") ||
//       t.getName().startsWith("C3P0PooledConnectionPoolManager")
//     );
//   }
// 
//   public ThreadLeakCheckerRule(Predicate<Thread> predicate) {
//     this.predicate = predicate;
//   }
// 
//   @Override
//   public Statement apply(Statement statement, Description description) {
//     return new Statement() {
//       @Override
//       public void evaluate() throws Throwable {
//         check("before");
//         statement.evaluate();
//         check("after");
//       }
//     };
//   }
// 
//   private void check(String when) {
//     long start = System.nanoTime(), stop;
//     List<Thread> threads;
//     for (; ; ) {
//       // Make a check
//       threads = findThreads(predicate);
//       if (threads.isEmpty()) {
//         return;
//       }
//       stop = System.nanoTime();
//       if (SECONDS.convert(stop - start, NANOSECONDS) >= 5) {
//         break;
//       } else {
//         try {
//           MILLISECONDS.sleep(10);
//         } catch (InterruptedException e) {
//           Thread.currentThread().interrupt();
//           break;
//         }
//       }
//     }
//     StringBuilder msg = new StringBuilder(threads.stream()
//       .map(t -> t.getName() + ": state=" + t.getState().name() + "/alive=" + t.isAlive())
//       .collect(Collectors.joining(", ", "Unexpected threads " + when + " test:", ".")));
//     ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
//     for (ThreadInfo ti : threadMxBean.dumpAllThreads(true, true)) {
//       msg.append(System.getProperty("line.separator")).append(ti.toString());
//     }
//     fail(msg.toString());
//   }
// 
//   public static List<Thread> findThreads(Predicate<Thread> predicate) {
//     return Thread.getAllStackTraces()
//       .keySet()
//       .stream()
//       .filter(predicate)
//       .collect(Collectors.toList());
//   }
// }


import io.vertx.ThreadLeakCheckerRule;
import io.vertx.core.json.JsonObject;
import org.junit.Rule;
import org.junit.Test;
import javax.sql.DataSource;
import java.sql.SQLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
package io.vertx.ext.jdbc.spi.impl;




/**
 * Checks the behavior of {@link HikariCPDataSourceProvider}.
 *
 * @author <a href="http://escoffier.me">Clement Escoffier</a>
 */
public class HikariCPDataSourceProviderTest {

  @Rule
  public ThreadLeakCheckerRule rule = new ThreadLeakCheckerRule();

  @Test
  public void testCreationOfTheHikariCPDataSource() throws SQLException {
    HikariCPDataSourceProvider provider = new HikariCPDataSourceProvider();

    JsonObject configuration = new JsonObject();
    configuration
        .put("foo", "bar")
        .put("jdbcUrl", "jdbc:hsqldb:mem:test?shutdown=true")
        .put("maxLifetime", 200L)
        .put("maximumPoolSize", 30);

    DataSource dataSource = provider.getDataSource(configuration);
    assertNotNull(dataSource);
    assertNotNull(dataSource.getConnection());

    assertEquals(30, provider.maximumPoolSize(dataSource, configuration));

    provider.close(dataSource);
  }

  @Test
// Path: src/test/java/io/vertx/ThreadLeakCheckerRule.java
// public class ThreadLeakCheckerRule implements TestRule {
// 
//   private final Predicate<Thread> predicate;
// 
//   public ThreadLeakCheckerRule() {
//     this(t ->
//       t.getName().equals("vertx-jdbc-service-get-connection-thread") ||
//       t.getName().startsWith("C3P0PooledConnectionPoolManager")
//     );
//   }
// 
//   public ThreadLeakCheckerRule(Predicate<Thread> predicate) {
//     this.predicate = predicate;
//   }
// 
//   @Override
//   public Statement apply(Statement statement, Description description) {
//     return new Statement() {
//       @Override
//       public void evaluate() throws Throwable {
//         check("before");
//         statement.evaluate();
//         check("after");
//       }
//     };
//   }
// 
//   private void check(String when) {
//     long start = System.nanoTime(), stop;
//     List<Thread> threads;
//     for (; ; ) {
//       // Make a check
//       threads = findThreads(predicate);
//       if (threads.isEmpty()) {
//         return;
//       }
//       stop = System.nanoTime();
//       if (SECONDS.convert(stop - start, NANOSECONDS) >= 5) {
//         break;
//       } else {
//         try {
//           MILLISECONDS.sleep(10);
//         } catch (InterruptedException e) {
//           Thread.currentThread().interrupt();
//           break;
//         }
//       }
//     }
//     StringBuilder msg = new StringBuilder(threads.stream()
//       .map(t -> t.getName() + ": state=" + t.getState().name() + "/alive=" + t.isAlive())
//       .collect(Collectors.joining(", ", "Unexpected threads " + when + " test:", ".")));
//     ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
//     for (ThreadInfo ti : threadMxBean.dumpAllThreads(true, true)) {
//       msg.append(System.getProperty("line.separator")).append(ti.toString());
//     }
//     fail(msg.toString());
//   }
// 
//   public static List<Thread> findThreads(Predicate<Thread> predicate) {
//     return Thread.getAllStackTraces()
//       .keySet()
//       .stream()
//       .filter(predicate)
//       .collect(Collectors.toList());
//   }
// }


// Path: src/test/java/io/vertx/ext/jdbc/spi/impl/HikariCPDataSourceProviderTest.java
import io.vertx.ThreadLeakCheckerRule;
import io.vertx.core.json.JsonObject;
import org.junit.Rule;
import org.junit.Test;
import javax.sql.DataSource;
import java.sql.SQLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

package io.vertx.ext.jdbc.spi.impl;




/**
 * Checks the behavior of {@link HikariCPDataSourceProvider}.
 *
 * @author <a href="http://escoffier.me">Clement Escoffier</a>
 */
public class HikariCPDataSourceProviderTest {

  @Rule
  public ThreadLeakCheckerRule rule = new ThreadLeakCheckerRule();

  @Test
  public void testCreationOfTheHikariCPDataSource() throws SQLException {
    HikariCPDataSourceProvider provider = new HikariCPDataSourceProvider();

    JsonObject configuration = new JsonObject();
    configuration
        .put("foo", "bar")
        .put("jdbcUrl", "jdbc:hsqldb:mem:test?shutdown=true")
        .put("maxLifetime", 200L)
        .put("maximumPoolSize", 30);

    DataSource dataSource = provider.getDataSource(configuration);
    assertNotNull(dataSource);
    assertNotNull(dataSource.getConnection());

    assertEquals(30, provider.maximumPoolSize(dataSource, configuration));

    provider.close(dataSource);
  }

  @Test
  public void testCreationOfTheHikariCPDataSourceWithInteger() throws SQLException {