Coder Social home page Coder Social logo

embedded-postgresql-maven-plugin's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

embedded-postgresql-maven-plugin's Issues

Database does not bind to pgServerPort on Windows

We started the plugin, see POM, via mvn verify.
We also added a proxy to settings.xml.
We are not able to connect to the port 5432 via telnet localhost 5432 on Windows.
On Linux Ubuntu 16 we are able to connect via telnet and PgAdmin too.
We think that the command line is not constructed so well on Windows.

After we found the ZIP in user home, we extracted and started the database on command line with our commands, the database was bound to the port 5432 and telnet connected to it on Windows.
We used these native commands:

set PGDATA=e:\tmp\zmaz\xx\x\target\data\
pg_ctl initdb
pg_ctl start -D e:\tmp\zmaz\xx\x\target\data\ -l logfile

now telnet:
telnet localhost 5432

Stop the database after successful connection
pg_ctl stop -D e:\tmp\zmaz\xx\x\target\data\ -l logfile

Here is our POM:

<plugin>
	<groupId>com.github.slavaz</groupId>
	<artifactId>embedded-postgresql-maven-plugin</artifactId>
	<version>1.2.2</version>
	<configuration>
		<pgServerVersion>9.6</pgServerVersion>
		<dbName>audit</dbName>
	</configuration>
	<executions>
		<execution>
			<id>start-pgsql</id>
			<phase>pre-integration-test</phase>
			<goals>
				<goal>start</goal>
			</goals>
		</execution>
		<execution>
			<id>stop-pgsql</id>
			<phase>post-integration-test</phase>
			<goals>
				<goal>stop</goal>
			</goals>
		</execution>
	</executions>
</plugin>

Here are Maven Debug logs of plugin configuration:

[DEBUG] Goal:          com.github.slavaz:embedded-postgresql-maven-plugin:1.1.0:start (start-pgsql)
[DEBUG] Style:         Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <dbName>audit</dbName>
  <password default-value="postgres"/>
  <pgCharset>${pgCharset}</pgCharset>
  <pgDatabaseDir>${pgDatabasedir}</pgDatabaseDir>
  <pgLocale>${pgLocale}</pgLocale>
  <pgServerPort default-value="5432">${pgPort}</pgServerPort>
  <pgServerVersion default-value="latest">9.6</pgServerVersion>
  <pluginDependencies default-value="${plugin.artifacts}"/>
  <projectBuildDir default-value="${project.build.directory}"/>
  <settings default-value="${settings}"/>
  <skipGoal default-value="false"/>
  <userName default-value="postgres">${username}</userName>
</configuration>

NoClassDefFoundError and "postgres" process not terminating

At the end of the build, there is always a NoClassDefFoundError for me:

java.lang.NoClassDefFoundError: org/apache/commons/io/FilenameUtils
	at org.apache.commons.io.FileUtils.isSymlink(FileUtils.java:2924)
	at org.apache.commons.io.FileUtils.deleteDirectory(FileUtils.java:1534)
	at org.apache.commons.io.FileUtils.forceDelete(FileUtils.java:2270)
	at de.flapdoodle.embed.process.io.file.Files.forceDelete(Files.java:119)
	at ru.yandex.qatools.embed.postgresql.PostgresProcess.sendStopToPostgresqlInstance(PostgresProcess.java:174)
	at ru.yandex.qatools.embed.postgresql.PostgresProcess.stopInternal(PostgresProcess.java:141)
	at de.flapdoodle.embed.process.runtime.AbstractProcess.stop(AbstractProcess.java:170)
	at de.flapdoodle.embed.process.runtime.AbstractProcess$JobKiller.run(AbstractProcess.java:243)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FilenameUtils
	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
	... 9 more

Also, when the build fails for whatever reason (some compilation error, failure in dependency resolution), the postgres process keeps running even after Maven has shut down (because the "stop" goal is never executed).

Not too long ago, I also created a similar Maven plugin and encountered the same issues. What I found was the problem is that Maven runs plugins using a separate class loader, while Embedded Postgres shuts down the process in a shutdown hook (using Runtime.addShutdownHook(..)). In the thread that the shutdown hook runs in, none of the classes are available, and so it fails to run at all, not stopping the postgres process, nor cleaning up temporary files.

My work-around then was to create a separate class loader, attach it to a thread, and run the Embedded Postgres code in that thread. This caused the classes to be available in the shutdown hook as well.

Unfortunately, I'm unable to share the exact code because I don't have access to it any more, but if you like I can try to replicate the work and create a pull request. It involved enumerating the plugin dependencies, and building a class loader instance from the appropriate JARs.

Fails to bootup on Mac OS X

Hitting a null pointer after the extraction is done:

Extract /Users/user/.embedpostgresql/postgresql-9.5.7-1-osx-binaries.zip START
..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Extract /Users/user/.embedpostgresql/postgresql-9.5.7-1-osx-binaries.zip DONE
Exception in thread "postgres-embedded" java.lang.RuntimeException: Invocation of method startPostgres threw exception
	at com.github.slavaz.maven.plugin.postgresql.embedded.psql.IsolatedPgInstanceManager.invokeStaticMethod(IsolatedPgInstanceManager.java:80)
	at com.github.slavaz.maven.plugin.postgresql.embedded.psql.IsolatedPgInstanceManager.lambda$start$0(IsolatedPgInstanceManager.java:28)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.github.slavaz.maven.plugin.postgresql.embedded.psql.IsolatedPgInstanceManager.invokeStaticMethod(IsolatedPgInstanceManager.java:76)
	... 2 more
Caused by: java.lang.NullPointerException
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1012)
	at de.flapdoodle.embed.process.runtime.ProcessControl.start(ProcessControl.java:205)
	at de.flapdoodle.embed.process.runtime.AbstractProcess.(AbstractProcess.java:98)
	at ru.yandex.qatools.embed.postgresql.AbstractPGProcess.(AbstractPGProcess.java:19)
	at ru.yandex.qatools.embed.postgresql.PostgresProcess.(PostgresProcess.java:68)
	at ru.yandex.qatools.embed.postgresql.PostgresExecutable.start(PostgresExecutable.java:25)
	at ru.yandex.qatools.embed.postgresql.PostgresExecutable.start(PostgresExecutable.java:13)
	at de.flapdoodle.embed.process.runtime.Executable.start(Executable.java:101)
	at com.github.slavaz.maven.plugin.postgresql.embedded.psql.PgInstanceManager.start(PgInstanceManager.java:30)
	at com.github.slavaz.maven.plugin.postgresql.embedded.psql.IsolatedPgInstanceManager.startPostgres(IsolatedPgInstanceManager.java:49)
	... 7 more

A started database cannot be connected to

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.