我正在使用 Liquibase 进行单元测试的迁移。我使用一个名为 ${projectName}Liquibase.java 的类来存储两个静态函数
public class ${projectName}Liquibase {
...
public static void runMigrations(Connection conn, DB_TYPE dbType) {
Liquibase liquibase;
Database database = null;
try {
database = DatabaseFactory.getInstance()
.findCorrectDatabaseImplementation(new JdbcConnection(conn));
liquibase = new Liquibase(dbType.filePath, new FileSystemResourceAccessor(), database);
liquibase.validate();
liquibase.update(null);
} catch (LiquibaseException e) {
throw new RuntimeException("File at " + dbType.filePath + " Error: " + e.getMessage());
}
}
public static void dropTables() {
...
}
}
我通过使用 System.getProperty("user.dir") 和路径的其余部分来获取文件 dbType.filePath 参数。
该文件可以正常读取,但是,更新仅通过第一个变更集,然后在测试期间挂起。因此,测试不会运行。
测试从我的 Intellij 项目中的其他文件和子模块成功运行。特别是,我们的集成测试套件使用来自不同子模块的相同接口成功运行。所有的测试都将通过,直到这个:
Running *.*.*.*.*.*DAOTest
2013-11-03 14:59:53,144 DEBUG [main] c.j.bonecp.BoneCPDataSource : JDBC URL = jdbc:hsqldb:mem:*, Username = SA, partitions = 2, max (per partition) = 5, min (per partition) = 5, helper threads = 3, idle max age = 60 min, idle test period = 240 min
INFO 11/3/13 2:59 PM:liquibase: Reading from PUBLIC.DATABASECHANGELOG
INFO 11/3/13 2:59 PM:liquibase: Successfully acquired change log lock
INFO 11/3/13 2:59 PM:liquibase: Reading from PUBLIC.DATABASECHANGELOG
INFO 11/3/13 2:59 PM:liquibase: /Users/davidgroff/repo/services/${projectName}/server/../core/src/main/java/com/*/*/liquibase/hsqldb.sql: 1::davidgroff: Custom SQL executed
INFO 11/3/13 2:59 PM:liquibase: /Users/davidgroff/repo/services/${projectName}/server/../core/src/main/java/com/*/*/liquibase/hsqldb.sql: 1::davidgroff: ChangeSet /Users/davidgroff/repo/services/*/*/../core/src/main/java/com/*/*/liquibase/hsqldb.sql::1::davidgroff ran successfully in 3ms
INFO 11/3/13 2:59 PM:liquibase: Successfully released change log lock
在此之后,测试反复挂起,就像在某个无限循环中一样。
我有当前的设置:
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.0.6</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.6</version>
</dependency>
我在 Maven 3.1.0 上使用 Java 7。