Quarkus,Flyway 无法连接到 TestContainer postgresql
Quarkus, Flyway can't connect to TestContainer postgresql
我正在我的 quarkus 应用程序中设置 Flyway,该应用程序已经具有适当的数据库设置,工作正常,但使用手动完成的数据库设置 (initdb()
) 方法来设置其数据库。
我目前使用 postgresql testcontainer 实例进行测试,并按以下方式进行设置:
@Override
public Map<String, String> start() {
log.info("STARTING test lifecycle resources.");
Map<String, String> configOverride = new HashMap<>();
if(MYSQL_CONTAINER == null || !MYSQL_CONTAINER.isRunning()){
PostgreSQLContainerProvider provider = new PostgreSQLContainerProvider();
MYSQL_CONTAINER = provider.newInstance();
MYSQL_CONTAINER.withDatabaseName("client-demo");
MYSQL_CONTAINER.start();
}
configOverride.put("quarkus.datasource.db-kind", "postgresql");
configOverride.put("quarkus.datasource.username", MYSQL_CONTAINER.getUsername());
configOverride.put("quarkus.datasource.password", MYSQL_CONTAINER.getPassword());
// replaceFirst required to connect; invalidUri exception thrown otherwise
configOverride.put("quarkus.datasource.reactive.url", MYSQL_CONTAINER.getJdbcUrl().replaceFirst("jdbc:", ""));
log.info("Config overrides: {}", configOverride);
return configOverride;
}
目前为止一切正常,测试代码可以按预期与数据库适当交互。
但是,当我尝试将 Flyway 添加到方程式时,Flyway 似乎无法连接到数据库:
2022-01-25 14:23:03,005 INFO [org.acm.cus.dem.uti.TestResourceLifecycleManager] (pool-4-thread-1) Config overrides: {quarkus.datasource.password=test, quarkus.datasource.db-kind=postgresql, quarkus.datasource.reactive.url=postgresql://localhost:49352/client-demo?loggerLevel=OFF, quarkus.datasource.username=test}
2022-01-25 14:23:03,695 WARN [io.agr.pool] (agroal-11) Datasource '<default>': FATAL: password authentication failed for user "test"
2022-01-25 14:23:03,721 INFO [org.acm.cus.dem.uti.TestResourceLifecycleManager] (main) STOPPING test lifecycle resources.
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 15.251 s <<< FAILURE! - in org.acme.cust.demo.CucumberTest
[ERROR] org.acme.cust.demo.CucumberTest.getTests Time elapsed: 15.238 s <<< ERROR!
java.lang.RuntimeException: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.lang.RuntimeException: Failed to start quarkus
Caused by: org.flywaydb.core.internal.exception.FlywaySqlException:
Unable to obtain connection from database: FATAL: password authentication failed for user "test"
有什么想法吗?
在您的配置中,您提到了反应式数据库连接。但是 Flyway 仍然需要“旧的”jdbc 连接。因此,如果您仍想以反应方式使用数据库,则可能必须同时配置两者。
我正在我的 quarkus 应用程序中设置 Flyway,该应用程序已经具有适当的数据库设置,工作正常,但使用手动完成的数据库设置 (initdb()
) 方法来设置其数据库。
我目前使用 postgresql testcontainer 实例进行测试,并按以下方式进行设置:
@Override
public Map<String, String> start() {
log.info("STARTING test lifecycle resources.");
Map<String, String> configOverride = new HashMap<>();
if(MYSQL_CONTAINER == null || !MYSQL_CONTAINER.isRunning()){
PostgreSQLContainerProvider provider = new PostgreSQLContainerProvider();
MYSQL_CONTAINER = provider.newInstance();
MYSQL_CONTAINER.withDatabaseName("client-demo");
MYSQL_CONTAINER.start();
}
configOverride.put("quarkus.datasource.db-kind", "postgresql");
configOverride.put("quarkus.datasource.username", MYSQL_CONTAINER.getUsername());
configOverride.put("quarkus.datasource.password", MYSQL_CONTAINER.getPassword());
// replaceFirst required to connect; invalidUri exception thrown otherwise
configOverride.put("quarkus.datasource.reactive.url", MYSQL_CONTAINER.getJdbcUrl().replaceFirst("jdbc:", ""));
log.info("Config overrides: {}", configOverride);
return configOverride;
}
目前为止一切正常,测试代码可以按预期与数据库适当交互。
但是,当我尝试将 Flyway 添加到方程式时,Flyway 似乎无法连接到数据库:
2022-01-25 14:23:03,005 INFO [org.acm.cus.dem.uti.TestResourceLifecycleManager] (pool-4-thread-1) Config overrides: {quarkus.datasource.password=test, quarkus.datasource.db-kind=postgresql, quarkus.datasource.reactive.url=postgresql://localhost:49352/client-demo?loggerLevel=OFF, quarkus.datasource.username=test}
2022-01-25 14:23:03,695 WARN [io.agr.pool] (agroal-11) Datasource '<default>': FATAL: password authentication failed for user "test"
2022-01-25 14:23:03,721 INFO [org.acm.cus.dem.uti.TestResourceLifecycleManager] (main) STOPPING test lifecycle resources.
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 15.251 s <<< FAILURE! - in org.acme.cust.demo.CucumberTest
[ERROR] org.acme.cust.demo.CucumberTest.getTests Time elapsed: 15.238 s <<< ERROR!
java.lang.RuntimeException: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.lang.RuntimeException: Failed to start quarkus
Caused by: org.flywaydb.core.internal.exception.FlywaySqlException:
Unable to obtain connection from database: FATAL: password authentication failed for user "test"
有什么想法吗?
在您的配置中,您提到了反应式数据库连接。但是 Flyway 仍然需要“旧的”jdbc 连接。因此,如果您仍想以反应方式使用数据库,则可能必须同时配置两者。