opentable嵌入式PostgreSQL无法正常工作

Vik*_*ite 6 java postgresql in-memory-database

我第一次使用otj-pg-embedded,并希望将其合并到我们的测试框架中。详细如下

以下是Maven依赖项:

 <dependency>
            <groupId>com.opentable.components</groupId>
            <artifactId>otj-pg-embedded</artifactId>
            <version>0.12.5</version>
            <scope>test</scope>
 </dependency>
Run Code Online (Sandbox Code Playgroud)

代码是:

EmbeddedPostgres pg = EmbeddedPostgres.start();
 Connection connection = pg.getPostgresDatabase().getConnection();
 Statement s = connection.createStatement();
 ResultSet rs = s.executeQuery("SELECT 1");
 assertEquals(1, rs.getInt(1));
Run Code Online (Sandbox Code Playgroud)

但是它失败,并在代码的第1行出现java.lang.IllegalStateException。

堆栈跟踪为:

initdb: invalid locale settings; check LANG and LC_* environment variables

java.lang.IllegalStateException: Process [/var/folders/rj/3jd5_2n16g37lv1v550g9cqw0000gp/T/embedded-pg/PG-b210101549c90a94dbbada389b65c5d2/bin/initdb, -A, trust, -U, postgres, -D, /var/folders/rj/3jd5_2n16g37lv1v550g9cqw0000gp/T/epg2729813194709143982, -E, UTF-8] failed


        at com.opentable.db.postgres.embedded.EmbeddedPostgres.system(EmbeddedPostgres.java:593)
        at com.opentable.db.postgres.embedded.EmbeddedPostgres.initdb(EmbeddedPostgres.java:230)
        at com.opentable.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:148)
        at com.opentable.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:580)
        at com.opentable.db.postgres.embedded.EmbeddedPostgres.start(EmbeddedPostgres.java:480)
Run Code Online (Sandbox Code Playgroud)

我在这里配置缺少什么吗?任何帮助,将不胜感激。

Ani*_*dia 1

通过查看堆栈跟踪中的这一行 initdb: invalid locale settings; check LANG and LC_* environment variables

看来您需要为语言环境设置环境变量,如下所述: https: //github.com/zonkyio/embedded-postgres/issues/11

export LC_CTYPE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
Run Code Online (Sandbox Code Playgroud)