上周,我的集成测试运行良好。今天,在我的测试运行之前,这个异常一直被抛出:
org.postgresql.util.PSQLException: FATAL: could not open file "base/12669/2601": No such file or directory
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)
at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2566)
at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:131)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:210)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
at org.postgresql.Driver.makeConnection(Driver.java:452)
at org.postgresql.Driver.connect(Driver.java:254)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at com.onzo.analytics.dal.PostgresForTesting.openConnection(PostgresForTesting.scala:111)
PostgresForTesting.scala:111 是我代码中这个函数的主体:
private def openConnection(): Unit = {
_connection = DriverManager.getConnection(_dbUrl)
}
DriverManager
是java.sql.DriverManager
。
_dbUrl
在这里设置:
private def startPostgres(): Unit = {
val port = 5431 // standard port is 5432; use a non-standard port to avoid accidentally using a real Postgres
_postgres = new EmbeddedPostgres(Version.V9_6_8, "imadatadir") // I changed this
val config = sys.env.get("HOME") match {
case None => EmbeddedPostgres.defaultRuntimeConfig()
case Some(ndHome) =>
val cache = Paths.get(ndHome, ".cache", "embedded-postgres")
Files.createDirectories(cache)
EmbeddedPostgres.cachedRuntimeConfig(cache)
}
// downloads Postgres, caches it locally (101MB)
_dbUrl = _postgres.start(config, "localhost", port, _dbName, "username", "password", new util.ArrayList[String])
val executor = AsyncExecutor(
name = "pg-for-testing",
minThreads = this.postgresConfig.numThreads,
maxThreads = this.postgresConfig.numThreads,
maxConnections = this.postgresConfig.maxConnections,
queueSize = this.postgresConfig.queueSize
)
_db = Database.forURL(_dbUrl, driver = "org.postgresql.Driver", executor = executor)
}
EmbeddedPostgres
是ru.yandex.qatools.embed.postgresql.EmbeddedPostgres
,来自postgresql-embedded。
在这个问题今天早上提出丑陋的头之前,我使用的是临时目录,而不是对imadatadir
目录进行硬编码。(请参阅标记为 的行I changed this
。)我对imadatadir
目录进行了硬编码以尝试调试此问题。(所以这不是导致问题的原因。)
有趣的事实:base/12669/2601
它抱怨无法打开的文件确实存在:
$ ls -l imadatadir/base/12669/2601*
-rw------- 1 dave.hinton staff 8192 17 Dec 12:57 imadatadir/base/12669/2601
-rw------- 1 dave.hinton staff 24576 17 Dec 12:57 imadatadir/base/12669/2601_fsm
-rw------- 1 dave.hinton staff 8192 17 Dec 12:57 imadatadir/base/12669/2601_vm
进一步的事实,可能相关也可能不相关:
- 我的同事都无法重现该问题;他们在 Linux 上,我在 macOS 上
- 我周末没有升级 macOS
版本:
- 斯卡拉 2.12.4
- JVM:甲骨文 Java 8 更新 191
- SBT 1.2.1
- postgresql-embedded 2.9(我看到版本 2.10 现在已经发布了......但是当我升级使用它时没有变化)
- macOS 莫哈韦 10.14.1
关于如何让它再次工作的任何想法?或者至少进一步调查出了什么问题?