Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opentable embedded postgresql not working

I am using otj-pg-embedded for the first time and would like to incorporate it into our test framework. Details are as follows

Following is the maven dependency :

 <dependency>
            <groupId>com.opentable.components</groupId>
            <artifactId>otj-pg-embedded</artifactId>
            <version>0.12.5</version>
            <scope>test</scope>
 </dependency>

And the code is :

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

But it fails with java.lang.IllegalStateException on line 1 of the code.

Stack trace is :

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)

Is there anything that I am missing to configure here? Any help would be appreciated.

like image 416
Vikas Gite Avatar asked Dec 14 '18 08:12

Vikas Gite


1 Answers

By looking at this line in the stack trace initdb: invalid locale settings; check LANG and LC_* environment variables,

It seems you need to set env variables for locale as described here: https://github.com/zonkyio/embedded-postgres/issues/11.

export LC_CTYPE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
like image 141
Anil Bharadia Avatar answered Oct 14 '22 17:10

Anil Bharadia