slavaz / embedded-postgresql-maven-plugin

Embedded PostgreSQL Maven Plugin
13 stars 11 forks source link

A started database cannot be connected to #5

Closed JanecekPetr closed 7 years ago

JanecekPetr commented 7 years ago

I believe I created the simplest possible setup:

<plugin>
    <groupId>com.github.slavaz</groupId>
    <artifactId>embedded-postgresql-maven-plugin</artifactId>
    <version>1.1.0</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <pgServerVersion>9.5</pgServerVersion>
        <dbName>somename</dbName>
    </configuration>
</plugin>

<plugin>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>4.2.0</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>migrate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <driver>org.postgresql.Driver</driver>
        <url>jdbc:postgresql://localhost/somename</url>
        <user>postgres</user>
        <password>postgres</password>
    </configuration>
</plugin>

but what I am seeing is a failing build, Flyway cannot connect to the DB:

[INFO] --- embedded-postgresql-maven-plugin:1.1.0:start (default) @ myproject ---
[INFO] Using system properties proxy configuration: null:null. no proxy: null
[INFO] Starting PostgreSQL...
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Extract C:\Users\xxxxxx\.embedpostgresql\postgresql-9.5.5-1-windows-x64-binaries.zip START
.............................................................................................................................................................................................................................................Extract C:\Users\xxxxxx\.embedpostgresql\postgresql-9.5.5-1-windows-x64-binaries.zip DONE
[INFO]
[INFO] --- flyway-maven-plugin:4.2.0:migrate (default) @ myproject ---
[INFO] Flyway 4.2.0 by Boxfuse
Jul 21, 2017 5:29:49 PM org.postgresql.Driver connect
SEVERE: Connection error:
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

What am I missing here? No matter what configuration I try, the result seems to always be the same. Note that after the "Extract DONE", the plugin still works in the background for ~10 seconds with no output, only then does Flyway start.

Oh, and also after Maven tells me that the build failed, this appears in the console:

Exception in thread "Thread-16" java.lang.IllegalStateException: Shutdown in progress
        at java.lang.ApplicationShutdownHooks.add(ApplicationShutdownHooks.java:66)
        at java.lang.Runtime.addShutdownHook(Runtime.java:211)
        at de.flapdoodle.embed.process.io.file.FileCleaner.forceDeleteOnExit(FileCleaner.java:52)
        at de.flapdoodle.embed.process.io.file.Files.forceDelete(Files.java:125)
        at de.flapdoodle.embed.process.runtime.AbstractProcess.stop(AbstractProcess.java:173)
        at de.flapdoodle.embed.process.runtime.AbstractProcess$JobKiller.run(AbstractProcess.java:243)
        at java.lang.Thread.run(Thread.java:745)
slavaz commented 7 years ago

I guess, you tried to run maven under privileged user. For getting more details see https://github.com/yandex-qatools/postgresql-embedded/issues/86 or https://github.com/yandex-qatools/postgresql-embedded/blob/master/README.md ('Known issues' section)

Would you please verify it? For example, try to create unprivileged user and to run Maven under the user...

JanecekPetr commented 7 years ago

Oh. I'm sorry, you're completely right. I skimmed over that section as I read it as "doesn't run under UNprivileged user...". Not sure how I got that.

I will apparently need to try to write my own wrapper for https://github.com/opentable/otj-pg-embedded which has been working both on Linux and Windows very well for me.

JanecekPetr commented 7 years ago

(Early working prototype to be seen at https://gitlab.com/janecekpetr/embedded-postgresql-maven-plugin, I basically forked your awesome plugin and switched the underlying lib.)