Code Monkey home page Code Monkey logo

embedded-postgres's People

Stargazers

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

Watchers

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

embedded-postgres's Issues

Missing some exception information from process execution

Hi, I have recently started using this lib and think it's really convenient feature to have available.
I have a question regarding the exception handling for processes.

So I did a simple test like this to generate an exception.
EmbeddedPostgres.builder().setDataDirectory(".").setPort(5432).start()

This will generate an exception

INFO io.zonky.test.db.postgres.embedded.EmbeddedPostgres Postgres binaries at /var/folders/yx/zq_6p5_j5tqf5fpfgbbfp_qjjc037p/T/embedded-pg/PG-d7f5f3cbfd0f44a07a6d0c5fb002a4ac
INFO io.zonky.test.db.postgres.embedded.EmbeddedPostgres The files belonging to this database system will be owned by user "some_user".
ERROR java.lang.IllegalStateException: Process [/var/folders/yx/zq_6p5_j5tqf5fpfgbbfp_qjjc037p/T/embedded-pg/PG-d7f5f3cbfd0f44a07a6d0c5fb002a4ac/bin/initdb, -A, trust, -U, postgres, -D, ., -E, UTF-8] failed
at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.system(EmbeddedPostgres.java:624)
at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.initdb(EmbeddedPostgres.java:243)
at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:156)
at io.zonky.test.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:577)

So now I know it failed somewhere and which process but no reason as to why?

If I execute this in my terminal instead it will return

/var/folders/yx/zq_6p5_j5tqf5fpfgbbfp_qjjc037p/T/embedded-pg/PG-d7f5f3cbfd0f44a07a6d0c5fb002a4ac/bin/initdb -A trust -U postgres -D . -E UTF-8
The files belonging to this database system will be owned by user "some_user".
This user must also own the server process.

The database cluster will be initialized with locales
  COLLATE:  C
  CTYPE:    UTF-8
  MESSAGES: C
  MONETARY: C
  NUMERIC:  C
  TIME:     C
initdb: could not find suitable text search configuration for locale "UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

initdb: directory "." exists but is not empty
If you want to create a new database system, either remove or empty
the directory "." or run initdb
with an argument other than ".".

So then simply setting ./temp as a new data directory will solve my problem
EmbeddedPostgres.builder().setDataDirectory("./temp").setPort(5432).start()
However, this wasn't something I knew/realised until I saw the error message I got when running it in terminal.

I was wondering why I can't see this information when I run the EmbeddedPostgres? Or maybe there is a way already?

Side note/question
Isn't this line supposed to print something after ...failed"?

throw new IllegalStateException(String.format("Process %s failed%n%s", Arrays.asList(command), IOUtils.toString(process.getErrorStream())));

Using embedded progress with test frameworks outside of JUnit

Hi,

We're interested in using the embedded postgres toolkit for our tests, but without JUnit. We are using ScalaTest.

It appears that the library relies heavily on the assumption of integrating with JUnit.

It looks like we should be able to build our own ScalaTest wrappers, unless there is something we're missing from looking at the code.

Could you advise?

Duplicate postgres binaries

I got this library working briefly... but now I get this :-( ...

[error] java.lang.IllegalStateException: Duplicate postgres binaries
[error]         at io.zonky.test.db.postgres.embedded.DefaultPostgresBinaryResolver.findPgBinary(DefaultPostgresBinaryResolver.java:78)
[error]         at io.zonky.test.db.postgres.embedded.DefaultPostgresBinaryResolver.getPgBinary(DefaultPostgresBinaryResolver.java:60)
[error]         at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.prepareBinaries(EmbeddedPostgres.java:784)
[error]         at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:133)
[error]         at io.zonky.test.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:583)
[error]         at example.backend.WithDbFramework.setup(WithDbFramework.scala:26)

Does anyone have a hint on what might be causing this or how to diagnose?

executing test cases in embedded postgres in maven pre-integration-test phase

Hi Team,

Project: Spring boot 2.0, Maven, Zonky Embedded Postgres,Open Api3.0

I am using Zonky embedded Postgres for JUnit DAO test cases and its working fine in maven build.

Now I have a requirement to integrate open API into spring boot so I have added embedded profiles in the maven pre-integration-test phase to be available for test cases.

But while executing maven pre-intergration-test phase spring boot application is loading H2 database by default in place of embedded postgres , can someone help to find the solution for this problem wether do I need to do any extra configuration to load postgres in place of H2.

Question regarding Junit 5

Hi There,

Do you have any example how to use embedded-postgres with Junit5 and use custom database instead of default postgres database?

Regards,

Syed Ali

Support for Unix sockets

We run in an environment where there are restrictions on using the network for tests. Most jdbc drivers have support for Unix sockets and postgres has options to only listen on Unix sockets. Can there be an option to only listen over Unix sockets?

Cannot use custom version of postgres on Mac

If I try and specify a custom version of Postgres then my tests fail as outlined below. If I use the default version 10.11.0 then everything works fine.

I am using Gradle 6.8
I have added the following to my build.gradle

    configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            if (details.requested.group == 'io.zonky.test.postgres') {
                details.useVersion '10.12.0'
            }
        }

Here is the error message that I get:

2021-01-19 12:07:17,716 [Test worker] INFO  io.zonky.test.db.postgres.embedded.EmbeddedPostgres - Detected a Darwin x86_64 system
2021-01-19 12:07:17,728 [Test worker] INFO  io.zonky.test.db.postgres.embedded.DefaultPostgresBinaryResolver - Detected distribution: 'Unknown'
2021-01-19 12:07:17,734 [Test worker] INFO  io.zonky.test.db.postgres.embedded.DefaultPostgresBinaryResolver - System specific postgres binaries found: postgres-darwin-x86_64.txz
2021-01-19 12:07:17,863 [Test worker] INFO  io.zonky.test.db.postgres.embedded.EmbeddedPostgres - Postgres binaries at /var/folders/p_/chr_twfx2rb_dh293j74hvgm0000gn/T/embedded-pg/PG-27d0af23b0ec8a6e6a4559592ef64d02
2021-01-19 12:07:17,911 [initdb:pid(33613)] INFO  io.zonky.test.db.postgres.embedded.EmbeddedPostgres - dyld: Library not loaded: @loader_path/../lib/libz.1.dylib
2021-01-19 12:07:17,913 [initdb:pid(33613)] INFO  io.zonky.test.db.postgres.embedded.EmbeddedPostgres -   Referenced from: /private/var/folders/p_/chr_twfx2rb_dh293j74hvgm0000gn/T/embedded-pg/PG-27d0af23b0ec8a6e6a4559592ef64d02/lib/libxml2.2.dylib
2021-01-19 12:07:17,913 [initdb:pid(33613)] INFO  io.zonky.test.db.postgres.embedded.EmbeddedPostgres -   Reason: no suitable image found.  Did find:
2021-01-19 12:07:17,913 [initdb:pid(33613)] INFO  io.zonky.test.db.postgres.embedded.EmbeddedPostgres - 	file system relative paths not allowed in hardened programs
2021-01-19 12:07:17,914 [initdb:pid(33613)] INFO  io.zonky.test.db.postgres.embedded.EmbeddedPostgres - no data was returned by command ""/private/var/folders/p_/chr_twfx2rb_dh293j74hvgm0000gn/T/embedded-pg/PG-27d0af23b0ec8a6e6a4559592ef64d02/bin/postgres" -V"
2021-01-19 12:07:17,914 [initdb:pid(33613)] INFO  io.zonky.test.db.postgres.embedded.EmbeddedPostgres - The program "postgres" is needed by initdb but was not found in the
2021-01-19 12:07:17,914 [initdb:pid(33613)] INFO  io.zonky.test.db.postgres.embedded.EmbeddedPostgres - same directory as "/private/var/folders/p_/chr_twfx2rb_dh293j74hvgm0000gn/T/embedded-pg/PG-27d0af23b0ec8a6e6a4559592ef64d02/bin/initdb".
2021-01-19 12:07:17,914 [initdb:pid(33613)] INFO  io.zonky.test.db.postgres.embedded.EmbeddedPostgres - Check your installation.

Postgres not started due to permissions

When am starting EmbeddedPostgres is fails with a strange error. Does anybody know how to fix it?

The files belonging to this database system will be owned by user “xxxx”.
This user must also own the server process.
initdb: invalid locale settings; check LANG and LC_* environment variables

and stack-strace

java.lang.IllegalStateException: Process [target/postgres-working-dir/PG-73dc0043fe7bdb624d5e8726bc457b7e/bin/initdb, -A, trust, -U, postgres, -D, target/postgres-data-dir, -E, UTF-8] failed
                                 
       com.opentable.db.postgres.embedded.EmbeddedPostgres.system  EmbeddedPostgres.java:  602
       com.opentable.db.postgres.embedded.EmbeddedPostgres.initdb  EmbeddedPostgres.java:  221
       com.opentable.db.postgres.embedded.EmbeddedPostgres.<init>  EmbeddedPostgres.java:  142
com.opentable.db.postgres.embedded.EmbeddedPostgres$Builder.start  EmbeddedPostgres.java:  554
                              

Problem with macOS temp directory handling (startups fail with missing postgres binary)

We have encountered problem, where tests using embedded-postgres sometimes start failing due postgres binary missing in the temp directory. Resolving these issues requires removing the embedded-pg directory under /var/folders/foo/bar/T/.

Investigating the problem lead to following conclusions

  • embedded-postgres extracts postgres binaries to folder named embedded-pg under directory returned by java.io.tmpdir system property. Marker file is used in this directory to mark if binaries have been extracted to the directory. If the marker file is present, no extraction is done
  • On my macOS system, java.io.tmpdir resolves to some /var/folders/foo/bar/T/ folder (where foo and bar are some environment dependent folder names)
  • According to http://www.magnusviri.com/what-is-var-folders.html that /T/ directory is the (user specific) temp directory and

By default, files in this location may be cleaned (removed) by the system if they are not accessed in 3 days.

Based on investigation on our failing cases, looks like that 3-day cleanup might (at least sometimes) clean the actual postgres-binaries, but not necessarily the marker file (maybe because the marker file is small?). That can lead to states, where marker file is present, but no actual binaries exists in the directory. That leads postgres start failing until the 'broken' temp directory is removed manually and binaries get extracted properly.

Unfortunately I don't know if there's any nice and simple fix for this. That linked page mentions cache directory at /var/folders/foo/bar/C which apparently should only get cleaned on reboot (and would probably clean everything at once), but I don't know if there's any nice and portable way of getting that location in Java.

Support for Flyway 7

Hello, we tried upgrading Flyway to version 7.0.4 today and got this error:

'int org.flywaydb.core.Flyway.migrate()'
java.lang.NoSuchMethodError: 'int org.flywaydb.core.Flyway.migrate()'
	at io.zonky.test.db.postgres.embedded.FlywayPreparer.prepare(FlywayPreparer.java:49)
	at io.zonky.test.db.postgres.embedded.PreparedDbProvider.createOrFindPreparer(PreparedDbProvider.java:85)
	at io.zonky.test.db.postgres.embedded.PreparedDbProvider.<init>(PreparedDbProvider.java:64)
	at io.zonky.test.db.postgres.embedded.PreparedDbProvider.forPreparer(PreparedDbProvider.java:59)
	at io.zonky.test.db.postgres.junit5.PreparedDbExtension.beforeAll(PreparedDbExtension.java:55)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$7(ClassBasedTestDescriptor.java:359)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllCallbacks(ClassBasedTestDescriptor.java:359)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:189)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:78)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:132)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1510)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:133)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
	at java.base/java.lang.Thread.run(Thread.java:832)

Figured I'd ask for Flyway 7 support. Thanks!

Embedded postres as maven plugin

It is possible to use embedded postgres as maven plugin? Like for example H2 DB. Example listed below

         <plugin>
               <groupId>org.flywaydb</groupId>
               <artifactId>flyway-maven-plugin</artifactId>
               <executions>
                   <execution>
                       <phase>generate-sources</phase>
                       <goals>
                           <goal>migrate</goal>
                       </goals>
                   </execution>
               </executions>
               <configuration>
                   <url>jdbc:h2:${project.basedir}/.db/generate;DATABASE_TO_UPPER=false</url>
                   <user>sa</user>
                   <schemas>public</schemas>
                   <locations>
                       <location>filesystem:src/main/resources/db/migration</location>
                   </locations>
               </configuration>
               <dependencies>
                   <dependency>
                       <groupId>com.h2database</groupId>
                       <artifactId>h2</artifactId>
                       <version>${h2.version}</version>
                   </dependency>
               </dependencies>
           </plugin>

Concurrency issues when running modules and tests in parallel

Hi :)

I've ran into this badboy:

    org.postgresql.util.PSQLException: ERROR: source database "template1" is being accessed by other users
      Detail: There are 2 other sessions using the database.
        at app//org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2552)
        at app//org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2284)
        at app//org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:322)
        at app//org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481)
        at app//org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401)
        at app//org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
        at app//org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:153)
        at app//io.zonky.test.db.postgres.embedded.PreparedDbProvider.create(PreparedDbProvider.java:244)
        at app//io.zonky.test.db.postgres.embedded.PreparedDbProvider.access$400(PreparedDbProvider.java:41)
        at app//io.zonky.test.db.postgres.embedded.PreparedDbProvider$PrepPipeline.run(PreparedDbProvider.java:215)
        at [email protected]/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at [email protected]/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at [email protected]/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
        at [email protected]/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
        at [email protected]/java.lang.Thread.run(Thread.java:831)

Versions: Kotlin 1.5.30, Java 16.0.2, Postgres 11.7, jupiter 5.7.2, gradle 7.2, Zonky 1.3.1
As the build time increases over time, We're trying to run most of our tests in parallel. Without success this far. We have hundreds of db-test using a separate dataSource thanks to these embedded-pg repos :) It is hard to reproduce at my 8 core / 16 thread intel cpu (but it happens from time to time), but it fails regularly at the Github Action instance.

gradle settings:

        maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
        systemProperties["junit.jupiter.execution.parallel.enabled"] = true
        systemProperties["junit.jupiter.execution.parallel.mode.default"] = "concurrent"

Code setup (package global)

private class CustomFlywayPreparer() : DatabasePreparer {
    override fun prepare(ds: DataSource) {
        ds.connection
            .prepareStatement("""create role "postgres-admin" """)
            .execute()
        ds.connection
            .prepareStatement("""create EXTENSION IF NOT EXISTS "uuid-ossp"""")
            .execute()
        Flyway.configure().target(MigrationVersion.LATEST).dataSource(dataSource).let {
                  it.initSql("SET ROLE \"postgres-admin\"")
            }
            .load()
            .migrate()
    }
}
private val preparer = CustomFlywayPreparer()
// this is used by all the tests
fun withMigratedDb(test: (dataSource: DataSource) -> Unit) {
    test(createNewDatabase(preparer = preparer))
}
private fun createNewDatabase(preparer: DatabasePreparer): DataSource {
  val provider = PreparedDbProvider.forPreparer(preparer)
  val info = provider.createNewDatabase()
  return provider.createDataSourceFromConnectionInfo(info)
}

Add to documentation how to change PostgreSQL version using Gradle

Hi there,
could you please add some tips to readme file about using this project with Gradle.

The main issue is how to change PostgreSQL version.
There are several ways to do it depending on used Gradle version.

For Gradle 4.6+ you have to activate feature IMPROVED_POM_SUPPORT in settings.gradle file.
enableFeaturePreview('IMPROVED_POM_SUPPORT')
And then add the following rows to your build.gradle file

testImplementation 'io.zonky.test.postgres:embedded-postgres-binaries-bom:11.7.0'
testImplementation 'io.zonky.test:embedded-postgres:1.2.6'

For Gradle 5+ activation of the additional feature is no longer required. You can use 'enforcedPlatform':

testImplementation 'io.zonky.test:embedded-postgres:1.2.6'
testImplementation enforcedPlatform('io.zonky.test.postgres:embedded-postgres-binaries-bom:11.7.0')

I think it would be very helpful for developers.

Not working with spring-boot 2.5.5 version

I have some issue:

  • Gradle project with Gradle version 6.8.1

  • Dependencies of zonky:
    [
    testImplementation 'io.zonky.test:embedded-database-spring-test:2.1.0'
    testImplementation group: 'io.zonky.test', name: 'embedded-postgres', version: '1.3.1'
    ]

  • java class with annotation configuration
    @AutoConfigureWireMock(port = 0) @AutoConfigureEmbeddedDatabase(provider = AutoConfigureEmbeddedDatabase.DatabaseProvider.ZONKY, replace = AutoConfigureEmbeddedDatabase.Replace.ANY) public abstract class Abstract_IT { @Autowired protected ObjectMapper objectMapper; @Autowired protected WireMockServer wireMockServer; @Autowired protected RequestHelper requestHelper; @Autowired protected ResponseHelper responseHelper; @Autowired protected Flyway flyway; }

-Error message

Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
at io.zonky.test.db.EmbeddedDatabaseTestExecutionListener.forEachDatabase(EmbeddedDatabaseTestExecutionListener.java:90)
at io.zonky.test.db.EmbeddedDatabaseTestExecutionListener.resetDatabases(EmbeddedDatabaseTestExecutionListener.java:58)
at io.zonky.test.db.EmbeddedDatabaseTestExecutionListener.beforeTestClass(EmbeddedDatabaseTestExecutionListener.java:34)
at org.springframework.test.context.TestContextManager.beforeTestClass(TestContextManager.java:213)
at org.springframework.test.context.junit.jupiter.SpringExtension.beforeAll(SpringExtension.java:113)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$8(ClassBasedTestDescriptor.java:368)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllCallbacks(ClassBasedTestDescriptor.java:368)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:192)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:78)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:136)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:133)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:829)
Suppressed: java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
at io.zonky.test.db.EmbeddedDatabaseTestExecutionListener.forEachDatabase(EmbeddedDatabaseTestExecutionListener.java:90)
at io.zonky.test.db.EmbeddedDatabaseTestExecutionListener.resetDatabases(EmbeddedDatabaseTestExecutionListener.java:58)
at io.zonky.test.db.EmbeddedDatabaseTestExecutionListener.afterTestClass(EmbeddedDatabaseTestExecutionListener.java:54)
at org.springframework.test.context.TestContextManager.afterTestClass(TestContextManager.java:492)
at org.springframework.test.context.junit.jupiter.SpringExtension.afterAll(SpringExtension.java:122)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeAfterAllCallbacks$14(ClassBasedTestDescriptor.java:434)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeAfterAllCallbacks$15(ClassBasedTestDescriptor.java:434)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeAfterAllCallbacks(ClassBasedTestDescriptor.java:434)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.after(ClassBasedTestDescriptor.java:216)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.after(ClassBasedTestDescriptor.java:78)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:149)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:149)
... 54 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@67424e82]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:143)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:212)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:117)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:74)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:374)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:332)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:123)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
... 70 more
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@67424e82]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:417)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:388)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:335)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
... 100 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463)
... 106 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 110 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@67424e82]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:143)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:212)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:117)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:74)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:374)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:332)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:123)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
... 68 more
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@67424e82]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:417)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:388)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:335)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
... 98 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463)
... 104 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 108 more

How to connect to instance with psql?

Can i create an instance something like

final EmbeddedPostgres pg = EmbeddedPostgres.start();

and connect to it with psq?
psql -h 127.0.0.1 -U postgres -p 5432 -d postgres

Order not maintained on Zonky

I have this select :

select * from unnest(array[
    'R:335901068',
    'A:-659857413',
    'R:-801583335',
    'A:-197178211'
    ])
order by 1

In my local postgres instance (from docker image 9.6) I get this result :

Local

A:-197178211
A:-659857413
R:335901068
R:-801583335

But Zonky instance returns me the following result :

A:-197178211
A:-659857413
R:-801583335
R:335901068

When executed SHOW ALL on both of instances, I've found a difference in locale informations. So I've added the following configuration to the zonky instance.

.setLocaleConfig("locale", "en_US.UTF-8")
.setLocaleConfig("lc-collate", "en_US.UTF-8")
.setLocaleConfig("lc-ctype", "en_US.UTF-8")
.setLocaleConfig("lc-messages", "en_US.UTF-8")
.setLocaleConfig("lc-monetary", "en_US.UTF-8")
.setLocaleConfig("lc-numeric", "en_US.UTF-8")
.setLocaleConfig("lc-time", "en_US.UTF-8")

The result is always different !

Is there any this else to change ?

Config
io.zonky.test:embedded-postgres:1.2.10
io.zonky.test.postgres:embedded-postgres-binaries-bom:9.6.15 (tried with 21 also)

MacOs
Darwin myHost 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec 2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64 x86_64

Database initialization fails on Windows for custom data directory

If I use a custom data directory

EmbeddedPostgres.builder().setDataDirectory("C:/ws/projects/zonkyio/embedded-postgres/test-data").start();

Creation of the database fails:

2021-07-26 14:14:14,540 [main] INFO  i.z.t.d.p.e.EmbeddedPostgres - Detected a Windows x86_64 system [] []
2021-07-26 14:14:14,548 [main] INFO  i.z.t.d.p.e.DefaultPostgresBinaryResolver - Detected distribution: 'Unknown' [] []
2021-07-26 14:14:14,549 [main] INFO  i.z.t.d.p.e.DefaultPostgresBinaryResolver - System specific postgres binaries found: 'postgres-windows-x86_64.txz' [] []
2021-07-26 14:14:14,620 [main] INFO  i.z.t.d.p.e.EmbeddedPostgres - Postgres binaries at D:\Temp\2\embedded-pg\PG-0889a6c23fa62a15a75cf8774df8b36a [] []
2021-07-26 14:14:14,676 [initdb:id(333034015)] INFO  i.z.t.d.p.e.EmbeddedPostgres - The files belonging to this database system will be owned by user "dpeger". [] []
2021-07-26 14:14:14,676 [initdb:id(333034015)] INFO  i.z.t.d.p.e.EmbeddedPostgres - This user must also own the server process. [] []
2021-07-26 14:14:14,676 [initdb:id(333034015)] INFO  i.z.t.d.p.e.EmbeddedPostgres -  [] []
2021-07-26 14:14:14,676 [initdb:id(333034015)] INFO  i.z.t.d.p.e.EmbeddedPostgres - The database cluster will be initialized with locale "English_United Kingdom.1252". [] []
2021-07-26 14:14:14,676 [initdb:id(333034015)] INFO  i.z.t.d.p.e.EmbeddedPostgres - The default text search configuration will be set to "english". [] []
2021-07-26 14:14:14,676 [initdb:id(333034015)] INFO  i.z.t.d.p.e.EmbeddedPostgres -  [] []
2021-07-26 14:14:14,677 [initdb:id(333034015)] INFO  i.z.t.d.p.e.EmbeddedPostgres - Data page checksums are disabled. [] []
2021-07-26 14:14:14,677 [initdb:id(333034015)] INFO  i.z.t.d.p.e.EmbeddedPostgres -  [] []
2021-07-26 14:14:14,677 [initdb:id(333034015)] INFO  i.z.t.d.p.e.EmbeddedPostgres - fixing permissions on existing directory C:/ws/projects/zonkyio/embedded-postgres/test-data ... initdb: could not change permissions of directory "C:/ws/projects/zonkyio/embedded-postgres/test-data": Permission denied [] []
java.lang.IllegalStateException: Process [D:\Temp\2\embedded-pg\PG-0889a6c23fa62a15a75cf8774df8b36a\bin\initdb.exe, -A, trust, -U, postgres, -D, C:\ws\projects\zonkyio\embedded-postgres\test-data, -E, UTF-8] failed
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.system(EmbeddedPostgres.java:632)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.initdb(EmbeddedPostgres.java:252)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:159)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:583)
...

This is very strange as my account definitively has "Full Control" privileges (inherited from local Administrators group) on the respective folder. However calling initdb directly from command line fails with the same permission denied error. I tested a little bit and was able to make initdb succeed by granting "Write" permission to the data directory to my account directly. Additionally initdb created non existing data directories on the fly (with the correct permissions).

Although this actually seems to be an issue with posgres' initdb utility I think it would be good to workaround this problem by not eagerly creating the data directory in EmbeddedPostgres:

Simply omitting this line made database initialization succeed.

Tests not pass on mac os

I have joined a new team that use cucumber testing. All features pass on Jenkins and the other developers on linux machines. But not me and another guy that has the same machine as me.

The tests are falling because of the order of elements. On macos the order is not the same as on linux !

In the build file I have

testImplementation 'io.zonky.test:embedded-postgres:1.2.10'
testImplementation enforcedPlatform('io.zonky.test.postgres:embedded-postgres-binaries-bom:9.6.15')

Macbook Pro / macOS Big Sur v11.1

java version "11.0.9" 2020-10-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.9+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)

Any Idea to fix this bug ?

Some log :

17:32:58.299 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : Detected a Darwin x86_64 system
17:32:58.302 INFO i.z.t.d.p.embedded.DefaultPostgresBinaryResolver : Detected distribution: 'Unknown'
17:32:58.305 INFO i.z.t.d.p.embedded.DefaultPostgresBinaryResolver : System specific postgres binaries found: postgres-darwin-x86_64.txz
17:32:58.373 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : Extracting Postgres...
17:33:00.406 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : Postgres binaries at build/pg/PG-5b5c46e3e13176f8e4de48960ea8e163
17:33:01.338 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : The files belonging to this database system will be owned by user "xxxx".
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : This user must also own the server process.
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres :
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : The database cluster will be initialized with locales
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : COLLATE: C
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : CTYPE: fr_FR.UTF-8
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : MESSAGES: C
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : MONETARY: C
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : NUMERIC: C
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : TIME: C
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : The default text search configuration will be set to "french".
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres :
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : Data page checksums are disabled.
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres :
17:33:01.339 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : fixing permissions on existing directory build/pg/data ... ok
17:33:01.340 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : creating subdirectories ... ok
17:33:01.358 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : selecting default max_connections ... 100
17:33:01.388 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : selecting default shared_buffers ... 128MB
17:33:01.392 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : selecting default timezone ... Europe/Paris
17:33:01.392 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : selecting dynamic shared memory implementation ... posix
17:33:01.396 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : creating configuration files ... ok
17:33:02.142 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : running bootstrap script ... ok
17:33:07.436 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : performing post-bootstrap initialization ... ok
17:33:07.454 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : syncing data to disk ... ok
17:33:07.454 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres :
17:33:07.454 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : Success. You can now start the database server using:
17:33:07.454 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres :
17:33:07.454 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : build/pg/PG-5b5c46e3e13176f8e4de48960ea8e163/bin/pg_ctl -D build/pg/data -l logfile start
17:33:07.454 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres :
17:33:07.455 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : 99b1a999-fd20-4311-9bc3-9da1e0e3feae initdb completed in 00:00:07.042
17:33:07.469 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : 99b1a999-fd20-4311-9bc3-9da1e0e3feae postmaster started as Process[pid=42804, exitValue="not exited"] on port 23423. Waiting up to PT10S for server startup to finish.
17:33:07.499 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : LOG: database system was shut down at 2021-04-16 17:33:07 CEST
17:33:07.499 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : LOG: MultiXact member wraparound protections are now enabled
17:33:07.501 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : LOG: database system is ready to accept connections
17:33:07.501 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : LOG: autovacuum launcher started
17:33:07.577 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : LOG: incomplete startup packet
17:33:07.777 INFO i.z.test.db.postgres.embedded.EmbeddedPostgres : 99b1a999-fd20-4311-9bc3-9da1e0e3feae postmaster startup finished in 00:00:00.315

Old working directories are not removed

  1. When a working directory is created, it is created outside the parent directory.

if (builderDataDirectory == null) { builderDataDirectory = Files.createTempDirectory("epg").toFile(); }

But at the moment when a search is performed for obsolete ones, their path is calculated relative to the parent.

private void cleanOldDataDirectories(File parentDirectory) { final File[] children = parentDirectory.listFiles();

  1. If we still find such a directory, we try to take the lock, but without releasing it, we delete the folder, an exception occurs

try (FileOutputStream fos = new FileOutputStream(lockFile); FileLock lock = fos.getChannel().tryLock()) { if (lock != null) { //..... FileUtils.deleteDirectory(dir); } }

  1. Sometimes, when the test ends abnormally, the "epg-lock" file is not created, so these folders are also not cleared during subsequent runs.

final File lockFile = new File(dir, LOCK_FILE_NAME); final boolean isTooNew = System.currentTimeMillis() - lockFile.lastModified() < 10 * 60 * 1000; if (!lockFile.exists() || isTooNew) { continue; }

v12.1.0 on RHEL 7.8 x86_64?

How can I use a Postgres version newer that the default bundled 10.11 on x86_64? The "embedded-postgres-binaries" only provides 32bit Linux bundles - which I could run on 64-bit Linux, however it seems the code to locate the bundle searches by the x86_64 architecture string reported by my OS and therefore won't pickup the postgres-linux-x86_32.txz bundle.

Update: Looking at this a little bit further, I could implement my own PgBinaryResolver to locate the x86_32 bundle, even if my system if x86_64 - just wanna check if I'm making a simple mistake before I go down that route.

Embedded-postgres in a standalone Java application

How to use embedded-postgres in a standalone Java application and to save the database in a file / directory? I need to run a Java application on windows / linux without installing posgresql server. Use not for tests, but for a small database.

embedded-postgres on Apple Silicon (M1) issue

Hi there,

thanks for the great work in the first place, we were using embedded Postgres for a while now.

Now I switched to a MacBook Pro with the new M1 SoC which has arm64 architecture.
I debugged DefaultPostgresBinaryResolver#getPgBinary and the line

Resource resource = findPgBinary(normalize(format("postgres-%s-%s.txz", system, architecture)));

does not find any binary because it is searching for postgres-darwin-arm_64.txzwhich I didn't find in https://mvnrepository.com/artifact/io.zonky.test.postgres

I assume there will be no release of Postgres for Darwin arm64 soon so is there a way to load the Darwin-amd64 embedded Postgres?

Dependencies we use:

compile("io.zonky.test:embedded-database-spring-test:1.6.1")
dependencyManagement {
        imports {
            mavenBom 'io.zonky.test.postgres:embedded-postgres-binaries-bom:9.6.16'
        }
    }

Thanks

Using embedded progress with spring-cloud-contract

Hi,

I'm trying to use spring-cloud-contract-maven-plugin in a spring application to test my controllers.
But when I try to compile and to accomplish the contracts with mockeds data on SupplyPointStatsContractTest.class I get this error.

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

before I have been using the h2 embedded database, but I have changed it because there are queries that h2 does not support because it is not native postgresql syntax.

Any idea about how to avoid this problem?

How to do transaction control

How do I do tests that use transaction control with commit and rollback? Although I change the autocommit setting to false, the instructions that are executed are commited automatically.

Data not persisted in embedded postgres DB when I use spring-boot-starter-data-jpa

Hi,
I configured embedded-postgres with liquibase in my application. In my integration test I call CrudRepository implementation to persist my data to embedded database. But this data is not persisted in my embedded postgres database instance, rather data is inserted into my real postgres database instance. Data is persisted in embedded postgres db is when i use native sql queries in my test method. Can somebody support to fix this?

My Test class is

package com.bosch.spring;

import com.bosch.spring.dao.Book;
import com.bosch.spring.service.impl.BookServiceImpl;
import io.zonky.test.db.postgres.embedded.LiquibasePreparer;
import io.zonky.test.db.postgres.junit.EmbeddedPostgresRules;
import io.zonky.test.db.postgres.junit.PreparedDbRule;
import liquibase.Contexts;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

@SpringBootTest
@RunWith( SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class CustomTest {

@Autowired
BookServiceImpl bookService;

@Rule
public PreparedDbRule db = EmbeddedPostgresRules.preparedDatabase(LiquibasePreparer.forClasspathLocation("db/changelog/db.changelog-master.yaml", new Contexts("test")));

@Before
public void init() {
    //System.out.println("init");
}

@Test
public void testTablesMade() throws Exception {
    try (Connection c = db.getTestDatabase().getConnection();
         Statement s = c.createStatement()) {
        ResultSet rs = s.executeQuery("SELECT * FROM book");
        rs.next();
        assertEquals("Test Books", rs.getString(1));
    }
}

@Test//test method uses spring crude repository implementation
public void testDB() throws Exception{
bookService.saveBook( new Book("Test Books"));
assertEquals("book is retrieved", "Test Books", bookService.findByName("Test Books").get(0).getName());
}
}

Postgis?

Question: is it possible to enable postgis in some way?

Option to disable shutdown hook

EmbeddedPostgres always sets its own shutdown hook in method startPostmaster():

Runtime.getRuntime().addShutdownHook(newCloserThread());

This gives us some problems in some test scenarios, where we don't have control of the order of shutdown hooks.
Could you please add an option to disable the shutdown hook, e.g.

if (!System.getProperty("ot.epg.no-showdownhook", "false").equals("true")) {
    Runtime.getRuntime().addShutdownHook(newCloserThread());
}

Thanks.

type "geometry" does not exist

Caused by: liquibase.exception.DatabaseException: ERROR: type "geometry" does not exist
Posição: 42 [Failed SQL: ALTER TABLE cipi.coordenada ADD location GEOMETRY]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:356)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:57)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:125)
at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1229)
at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1211)
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:600)

The geometry type is not being recognized.
How can I configure postgis?

How to get the extraction Path ?

Hi,

is there a way to get the exact ans full path ( /tmp/embedded-pg/PG-XYZ ) where the embedded-pg is extraced ? I have to install mysql fdw at runtime and need this path

Another question, with Window, is the embedded-postgres extracted in /tmp ?

Thnak's

macOS Catalina and Mojave fails due to hardened rules

  • Java 11
  • embedded-postgres-binaries-bom 11.7.0
Detected a Darwin x86_64 system
Detected distribution: 'Unknown'
System specific postgres binaries found: postgres-darwin-x86_64.txz
Postgres binaries at /var/folders/pp/l3ccxdj91_x3tvpq4yllhvg40000gn/T/embedded-pg/PG-5f6dc0830311710916a464ec059175a6
dyld: Library not loaded: @loader_path/../lib/libz.1.dylib
  Referenced from: /private/var/folders/pp/l3ccxdj91_x3tvpq4yllhvg40000gn/T/embedded-pg/PG-5f6dc0830311710916a464ec059175a6/lib/libxml2.2.dylib
  Reason: no suitable image found.  Did find:
        file system relative paths not allowed in hardened programs
no data was returned by command ""/private/var/folders/pp/l3ccxdj91_x3tvpq4yllhvg40000gn/T/embedded-pg/PG-5f6dc0830311710916a464ec059175a6/bin/postgres" -V"
The program "postgres" is needed by initdb but was not found in the
same directory as "/private/var/folders/pp/l3ccxdj91_x3tvpq4yllhvg40000gn/T/embedded-pg/PG-5f6dc0830311710916a464ec059175a6/bin/initdb".
Check your installation.

Does not occur with 11.6.0

Segmentation fault: 11 on macOS Monterey

I seem to be unable to use embedded-postgres (I'm on v1.3.1)

Process [/var/folders/lp/58zt5n313qg4s0d0b_yqnmsc0000gn/T/embedded-pg/PG-a2a9bc65661eac6f108fc920268a87b3/bin/initdb, -A, trust, -U, postgres, -D, /var/folders/lp/58zt5n313qg4s0d0b_yqnmsc0000gn/T/epg16198865472753438309, -E, UTF-8] failed
java.lang.IllegalStateException: Process [/var/folders/lp/58zt5n313qg4s0d0b_yqnmsc0000gn/T/embedded-pg/PG-a2a9bc65661eac6f108fc920268a87b3/bin/initdb, -A, trust, -U, postgres, -D, /var/folders/lp/58zt5n313qg4s0d0b_yqnmsc0000gn/T/epg16198865472753438309, -E, UTF-8] failed
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.system(EmbeddedPostgres.java:632)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.initdb(EmbeddedPostgres.java:252)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:159)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:583)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.start(EmbeddedPostgres.java:477)
$ pwd
/var/folders/lp/58zt5n313qg4s0d0b_yqnmsc0000gn/T/embedded-pg/PG-a2a9bc65661eac6f108fc920268a87b3/bin
$ ./postgres 
Segmentation fault: 11
$ file postgres 
postgres: Mach-O universal binary with 2 architectures: [i386:Mach-O executable i386] [x86_64]
postgres (for architecture i386):	Mach-O executable i386
postgres (for architecture x86_64):	Mach-O 64-bit executable x86_64
$ uname -a
Darwin foo.local 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 x86_64
$  ./initdb -V
initdb (PostgreSQL) 10.18
$  ./pg_ctl -V
pg_ctl (PostgreSQL) 10.18

EmbeddedPostgres not starting in JUnit 5 tests on Windows

Hi, I was previously using v1.2.6, but once I updated to v1.2.8+, my unit tests are unable to start up the embedded Postgres database. I've not changed anything else besides the version of the dependency from 1.2.6 -> 1.2.8 (1.2.7 works fine). I didn't see anything in the release that might require a change.

My code is a utility class used by my JUnit tests to retrieve a Connection as follows:

public class TestDbConnectionPool {
    private final DataSource dataSource;

    public TestDbConnectionPool() {
        try {
            dataSource = EmbeddedPostgres.builder()
                .start() // <-- Failing here
                .getPostgresDatabase();
            createDatabaseTables();
        } catch (final Exception e) {
            throw new AssertionError("Unable to start test DB", e);
        }
    }
    
    public Connection getConnection() {
        try {
            return dataSource.getConnection();
        } catch (final SQLException e) {
            throw new DatabaseConnectionException("Error opening connection", e);
        }
    }
}

The stack trace is:

Caused by: java.io.IOException: Gave up waiting for server to start after 300000ms
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.waitForServerStartup(EmbeddedPostgres.java:331)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.startPostmaster(EmbeddedPostgres.java:281)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:160)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:580)
	at me.zodac.folding.db.postgres.TestDbConnectionPool.<init>(TestDbConnectionPool.java:38)
	... 69 more
Caused by: java.sql.SQLException: connect failed
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.verifyReady(EmbeddedPostgres.java:341)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.waitForServerStartup(EmbeddedPostgres.java:316)
	... 73 more
Caused by: java.net.SocketTimeoutException: connect timed out
	at java.base/java.net.PlainSocketImpl.waitForConnect(Native Method)
	at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:107)
	at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
	at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
	at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
	at java.base/java.net.Socket.connect(Socket.java:591)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.verifyReady(EmbeddedPostgres.java:339)
	... 74 more

Stopped working on IntelliJ 2019.2

Hey, just like for the original otj-pg-embedded project this fork stopped working on my system since upgrading to Mac OS 10.14.6 (latest version). The error I get is java.lang.IllegalStateException: Process [/var/folders/l_/c1b_7t2n39j48k7sbpp54zy00000gn/T/embedded-pg/PG-8eddc1e460ca1c5597350c162933683c/bin/initdb, -A, trust, -U, postgres, -D, /var/folders/l_/c1b_7t2n39j48k7sbpp54zy00000gn/T/epg3835758492450081687, -E, UTF-8] failed.

Deleting the temporary embedded-pg folder does not solve the problem. Do you have any ideas?

CVE in commons-compress 1.20

embedded-postgres uses commons-compress's TarArchiveInputStream to unpack the postgres-Binary. The latest published version of embedded-postgres is 1.3.0 which uses commons-compress 1.20.

Four CVEs have been published for commons-compress 1.20 recently.

  1. http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2021-35515
  2. http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2021-35516
  3. http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2021-35517
  4. http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2021-36090

According to https://issues.apache.org/jira/browse/COMPRESS-586 all of them had been documented to be fixed in 1.21 already but the documentation has disappeared. I can only find the fix for CVE-2021-35516:
https://issues.apache.org/jira/browse/COMPRESS-542.

Please provide an new release of embedded-postgres with an updated version of commons-compress. Either 1.21 or newer, dependent on the feedback of COMPRESS-586.

OverlappingFileLockException

I'm seeing this exception pop up in my CI integration tests rather frequently. I assume it is related to the concurrent execution of the test framework. For me, it is sufficient to simply catch and retry, but perhaps you can find a proper way to handle this:

Caused by: java.nio.channels.OverlappingFileLockException
	at java.base/sun.nio.ch.FileLockTable.checkList(FileLockTable.java:229)
	at java.base/sun.nio.ch.FileLockTable.add(FileLockTable.java:123)
	at java.base/sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1154)
	at java.base/java.nio.channels.FileChannel.tryLock(FileChannel.java:1165)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.prepareBinaries(EmbeddedPostgres.java:810)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:133)
	at io.zonky.test.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:583)
	...

Changing db schema in embedded-postgres doesn't work

I'm using embedded-postgres in version 1.2.6.
Before one test I create a schema - schema_1.
Later in my test I can successfully list the schemas with
select schema_name from information_schema.schemata;

But changing schema with
SET SCHEMA 'schema_1' or
SELECT set_config('search_path', 'schema_1', false)
doesn't work.
My current schema (SELECT current_schema()) still remains public.

I can successfully change the schema with either command on my local postgres installation.

Database refuses to start on windows with privileged user

With versions 1.2.8 and above running

EmbeddedPostgres.builder().start();

on Windows with a privileged user results in the this log output followed by a timeout exception:

2021-07-23 11:27:41,101 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - The files belonging to this database system will be owned by user "dpeger". [] []
2021-07-23 11:27:41,102 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - This user must also own the server process. [] []
2021-07-23 11:27:41,102 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres -  [] []
2021-07-23 11:27:41,102 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - The database cluster will be initialized with locale "English_United Kingdom.1252". [] []
2021-07-23 11:27:41,102 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - The default text search configuration will be set to "english". [] []
2021-07-23 11:27:41,102 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres -  [] []
2021-07-23 11:27:41,102 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - Data page checksums are disabled. [] []
2021-07-23 11:27:41,102 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres -  [] []
2021-07-23 11:27:41,102 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - fixing permissions on existing directory D:/Temp/2/epg5065321025544086736 ... ok [] []
2021-07-23 11:27:41,104 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - creating subdirectories ... ok [] []
2021-07-23 11:27:41,168 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - selecting default max_connections ... 100 [] []
2021-07-23 11:27:41,231 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - selecting default shared_buffers ... 128MB [] []
2021-07-23 11:27:41,231 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - selecting default timezone ... CET [] []
2021-07-23 11:27:41,232 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - selecting dynamic shared memory implementation ... windows [] []
2021-07-23 11:27:41,235 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - creating configuration files ... ok [] []
2021-07-23 11:27:41,894 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - running bootstrap script ... ok [] []
2021-07-23 11:27:43,290 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - performing post-bootstrap initialization ... ok [] []
2021-07-23 11:27:53,826 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - syncing data to disk ... ok [] []
2021-07-23 11:27:53,826 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres -  [] []
2021-07-23 11:27:53,826 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres - Success. You can now start the database server using: [] []
2021-07-23 11:27:53,826 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres -  [] []
2021-07-23 11:27:53,826 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres -     D:/Temp/2/embedded-pg/PG-0889a6c23fa62a15a75cf8774df8b36a/bin/pg_ctl -D ^"D^:^\Temp^\2^\epg5065321025544086736^" -l logfile start [] []
2021-07-23 11:27:53,826 [initdb:id(1711641083)] INFO  i.z.t.d.p.e.EmbeddedPostgres -  [] []
2021-07-23 11:27:53,838 [main] INFO  i.z.t.d.p.e.EmbeddedPostgres - df83925d-b31a-42cf-82f9-cc52176ce149 initdb completed in 00:00:12.807 [] []
2021-07-23 11:27:53,851 [main] INFO  i.z.t.d.p.e.EmbeddedPostgres - df83925d-b31a-42cf-82f9-cc52176ce149 postmaster started as java.lang.ProcessImpl@27fde870 on port 59767.  Waiting up to PT10S for server startup to finish. [] []
2021-07-23 11:27:53,983 [postgres:id(670951536)] INFO  i.z.t.d.p.e.EmbeddedPostgres - Execution of PostgreSQL by a user with administrative permissions is not [] []
2021-07-23 11:27:53,983 [postgres:id(670951536)] INFO  i.z.t.d.p.e.EmbeddedPostgres - permitted. [] []
2021-07-23 11:27:53,983 [postgres:id(670951536)] INFO  i.z.t.d.p.e.EmbeddedPostgres - The server must be started under an unprivileged user ID to prevent [] []
2021-07-23 11:27:53,984 [postgres:id(670951536)] INFO  i.z.t.d.p.e.EmbeddedPostgres - possible system security compromises.  See the documentation for [] []
2021-07-23 11:27:53,984 [postgres:id(670951536)] INFO  i.z.t.d.p.e.EmbeddedPostgres - more information on how to properly start the server. [] []
2021-07-23 11:28:04,075 [main] WARN  c.r.t.t.j.PostgresEmbeddedTestDatabase - No database instance available. Database already closed? [] []

This is caused by switching from pg_ctl to postgres executable for starting up postgres in PR #39. According to the PR this was done to get a proper process tree to ensure the postgres process doesn't stay alive after Java is terminated. Which makes perfect sense.

However as pg_ctl is the recommended/official way to start postgres I think there should at least be an option to switch to pg_ctl or make it system dependent. That is use postgres under unix and pg_ctl under Windows.

Version 1.2.7 is working fine for me under windows.

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.