예제 #1
0
  @Test
  public void noConnectionLeak() {
    OpenConnectionCountDriverDataSource dataSource = new OpenConnectionCountDriverDataSource();

    assertEquals(0, dataSource.getOpenConnectionCount());
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("migration/sql");
    flyway.clean();
    assertEquals(0, dataSource.getOpenConnectionCount());
    assertEquals(4, flyway.migrate());
    assertEquals(0, dataSource.getOpenConnectionCount());
  }
예제 #2
0
  @Test
  public void noConnectionLeakWithException() {
    OpenConnectionCountDriverDataSource dataSource = new OpenConnectionCountDriverDataSource();

    assertEquals(0, dataSource.getOpenConnectionCount());
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("migration/failed");
    try {
      flyway.clean();
      assertEquals(0, dataSource.getOpenConnectionCount());
      flyway.migrate();
      fail();
    } catch (FlywayException e) {
      // Expected -> Ignore
    }
    assertEquals(0, dataSource.getOpenConnectionCount());
  }
예제 #3
0
  /** Tests the functionality of the OpenConnectionCountDriverDataSource. */
  @Test
  public void connectionCount() throws Exception {
    OpenConnectionCountDriverDataSource dataSource = new OpenConnectionCountDriverDataSource();

    assertEquals(0, dataSource.getOpenConnectionCount());
    Connection connection = dataSource.getConnection();
    assertEquals(1, dataSource.getOpenConnectionCount());
    connection.close();
    assertEquals(0, dataSource.getOpenConnectionCount());

    Connection connection2 = dataSource.getConnection();
    assertEquals(1, dataSource.getOpenConnectionCount());
    Connection connection3 = dataSource.getConnection();
    assertEquals(2, dataSource.getOpenConnectionCount());
    connection2.close();
    assertEquals(1, dataSource.getOpenConnectionCount());
    connection3.close();
    assertEquals(0, dataSource.getOpenConnectionCount());
  }