为什么我的Postgres集成测试突然抛出异常?

时间:2018-12-17 15:26:50

标签: postgresql scala embedded-postgres

上周,我的集成测试运行良好。今天,在我的测试开始运行之前,始终会抛出该异常:

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)
  }

DriverManagerjava.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)
  }

EmbeddedPostgresru.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

版本:

  • Scala 2.12.4
  • JVM:Oracle Java 8 Update 191
  • SBT 1.2.1
  • postgresql嵌入式2.9(我看到2.10版本已经发布了……但是升级到使用它时没有变化)
  • macOS Mojave 10.14.1

关于如何使它重新工作的任何想法?或者至少进一步调查出了什么问题?

0 个答案:

没有答案