예제 #1
0
  @Test
  public void outOfOrder() {
    DriverDataSource dataSource =
        new DriverDataSource(null, "jdbc:h2:mem:flyway_out_of_order;DB_CLOSE_DELAY=-1", "sa", "");

    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("migration/sql");
    flyway.setTarget(new MigrationVersion("1.2"));
    assertEquals(4, flyway.info().all().length);
    assertEquals(3, flyway.info().pending().length);

    flyway.clean();
    assertEquals(3, flyway.migrate());
    assertEquals(0, flyway.info().pending().length);

    flyway.setLocations("migration/sql", "migration/outoforder");
    assertEquals(5, flyway.info().all().length);
    assertEquals(MigrationState.IGNORED, flyway.info().all()[2].getState());
    assertEquals(0, flyway.migrate());

    flyway.setTarget(MigrationVersion.LATEST);
    flyway.setOutOfOrder(true);
    assertEquals(MigrationState.PENDING, flyway.info().all()[2].getState());
    assertEquals(2, flyway.migrate());

    assertEquals(MigrationState.OUT_OF_ORDER, flyway.info().all()[2].getState());
    assertEquals(MigrationState.SUCCESS, flyway.info().all()[4].getState());
  }
예제 #2
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());
  }
예제 #3
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());
  }