Code Monkey home page Code Monkey logo

Comments (20)

smecsia avatar smecsia commented on July 22, 2024

@zemudkram This might be a bug in de.flapdoodle.embed.process.
We could catch any exceptions during temporary files removal, but I believe it would be better to find out why actual files removal fails.
Do you have any other exceptions in your log above this stack trace?
Temporary directory might be still locked by running Postgres process at the moment of removal, but the process must be killed already, so I suppose this could be the root of the problem.

from postgresql-embedded.

smecsia avatar smecsia commented on July 22, 2024

Please also indicate the version and the operating system, you're using.

from postgresql-embedded.

zemudkram avatar zemudkram commented on July 22, 2024

I was going to say there are no other exceptions, but it does look like there is a null-pointer exception, which has overwritten a log line. There are also several warnings about not being able to delete the files. Here's a more complete log of a typical test run.

2016-02-27 09:43:54,899 [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [datasource-test-context.xml]
2016-02-27 09:43:55,480 [main] INFO  org.springframework.context.support.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext@12843fce: startup date [Sat Feb 27 09:43:55 NZDT 2016]; root of context hierarchy
2016-02-27 09:43:55,839 [main] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c46bcd4: defining beans [postgresService,dataSource,dbCreator,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionManager,transactionInterceptor,autoProxyCreator,channelDao,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor]; root of factory hierarchy
2016-02-27 09:44:04,424 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@6b927fb
2016-02-27 09:44:04,766 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@6ae5aa72
2016-02-27 09:44:05,767 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@222545dc
2016-02-27 09:44:05,768 [main] INFO  com.anzcro.o3.util.db.PostgresService - STARTED EMBEDDED POSTGRES - CONNECTION URL IS jdbc:postgresql://localhost:63844/test?user=test&password=test
2016-02-27 09:44:05,829 [main] INFO  org.springframework.jdbc.datasource.DriverManagerDataSource - Loaded JDBC driver: org.postgresql.Driver
2016-02-27 09:44:06,070 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@7530ad9c
2016-02-27 09:44:06,385 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@394df057
2016-02-27 09:44:06,684 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@65d09a04
2016-02-27 09:44:06,924 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@707194ba
2016-02-27 09:44:07,214 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@45b4c3a9
2016-02-27 09:44:08,075 [Thread-20] WARN  de.flapdoodle.embed.process.runtime.AbstractProcess - Could not delete pid file: /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-87fbeab3-089c-46cf-8b40-f5cd686f326e/pgsql/bin/psql.pid
2016-02-27 09:44:08,076 [Thread-31] INFO  org.springframework.context.support.GenericApplicationContext - Closing 

Here's the line with the NPE: I'm not sure where this NPE is coming from - fairly certain it's not from spring...grepping through the code of this project leads me to PostgresArtifactStore

org.springframework.context.support.GenericApplicationContext@12843fce: startup date [Sat Feb 27 09:43:55 NZDT 2016]; root of context hierarFailed to extract file set: java.lang.NullPointerException
chy

And continues

2016-02-27 09:44:08,076 [Thread-24] WARN  de.flapdoodle.embed.process.runtime.AbstractProcess - Could not delete pid file: /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-87fbeab3-089c-46cf-8b40-f5cd686f326e/pgsql/bin/psql.pid
2016-02-27 09:44:08,075 [Thread-12] WARN  de.flapdoodle.embed.process.runtime.AbstractProcess - Could not delete pid file: /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-87fbeab3-089c-46cf-8b40-f5cd686f326e/pgsql/bin/psql.pid
2016-02-27 09:44:08,075 [Thread-16] WARN  de.flapdoodle.embed.process.runtime.AbstractProcess - Could not delete pid file: /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-87fbeab3-089c-46cf-8b40-f5cd686f326e/pgsql/bin/psql.pid
2016-02-27 09:44:08,080 [Thread-31] INFO  org.springframework.context.support.DefaultLifecycleProcessor - Stopping beans in phase 0
2016-02-27 09:44:08,095 [Thread-1] INFO  de.flapdoodle.embed.process.runtime.ProcessControl - execSuccess: true [kill, -2, 88777]
Exception in thread "Thread-1" 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 ru.yandex.qatools.embed.postgresql.PostgresProcess.deleteTempFiles(PostgresProcess.java:157)
    at ru.yandex.qatools.embed.postgresql.PostgresProcess.stopInternal(PostgresProcess.java:117)
    at de.flapdoodle.embed.process.runtime.AbstractProcess.stop(AbstractProcess.java:170)
    at de.flapdoodle.embed.process.runtime.Executable.stop(Executable.java:73)
    at de.flapdoodle.embed.process.runtime.Executable$JobKiller.run(Executable.java:90)
    at java.lang.Thread.run(Thread.java:745)
2016-02-27 09:44:08,257 [Thread-1] WARN  de.flapdoodle.embed.process.io.file.Files - could not delete /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-87fbeab3-089c-46cf-8b40-f5cd686f326e/db-content-0412a790-1bdb-4460-8a5d-eed03e328b7e. Will try to delete it again when program exits.
2016-02-27 09:44:08,259 [Thread-31] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c46bcd4: defining beans [postgresService,dataSource,dbCreator,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionManager,transactionInterceptor,autoProxyCreator,channelDao,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor]; root of factory hierarchy

Process finished with exit code 0

We are seeing this on MacOS (10.11) and Linux (Ubuntu 15.10 I think) - we haven't tried on Windows yet, since we're mainly a *nix shop.

Should I perhaps raise an issue over at flapdoodle as well?

from postgresql-embedded.

smecsia avatar smecsia commented on July 22, 2024

@zemudkram Thanks for the detailed explanation. It seems that I've managed to resolve this problem. Could you try the version from PR(#27) locally?

from postgresql-embedded.

zemudkram avatar zemudkram commented on July 22, 2024

@smecsia 👍 Sure I will try this out Monday. Thanks for the quick response :)

from postgresql-embedded.

zemudkram avatar zemudkram commented on July 22, 2024

Sorry, I've not been able to try this locally yet. I will give it a shot today.

from postgresql-embedded.

zemudkram avatar zemudkram commented on July 22, 2024

@smecsia I've tested 1.10-SNAPSHOT from PR(#27) and the NPE is not there. So that part of the problem is fixed, I think.

Many of our tests extend from a base class that contains the spring context configuration and common set up code for a particular aspect of our project. When the tests are run individually, the context shuts down correctly, however when run as a suite (usually by selecting the package in my IDE and running all tests in the package) or as part of a maven test run, we still see the IllegalStateException (see stack trace below).

These tests are quite old, and perhaps it's not the best way to be using Spring contexts, but it's what we have to deal with at the moment. I'm inclined to think that this problem resides in the flapdoodle embedded process code, rather than the postgresql-embedded project though.

2016-03-01 08:54:49,357 [main] INFO  org.springframework.context.support.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext@6d8a00e3: startup date [Tue Mar 01 08:54:49 NZDT 2016]; root of context hierarchy
2016-03-01 08:54:49,567 [main] INFO  org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from class path resource [o3test.properties]
2016-03-01 08:54:49,628 [main] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3b088d51: defining beans [propertyPlaceholderConfigurerBusinessBase,postgresService,dbCreator,simpleJdbcTemplate,dataSource,superDataSource,transactionManager,transactionInterceptor,autoProxyCreator,...,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor]; root of factory hierarchy
2016-03-01 08:54:56,971 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@4567f35d
2016-03-01 08:54:57,315 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@6b81ce95
2016-03-01 08:54:58,319 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@2a798d51
2016-03-01 08:54:58,537 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@7f3b84b8
2016-03-01 08:54:58,847 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@7f0eb4b4
2016-03-01 08:54:59,160 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@c8c12ac
2016-03-01 08:54:59,409 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@4ec4f3a0
2016-03-01 08:54:59,678 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@9597028
2016-03-01 08:54:59,989 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@1b7cc17c
2016-03-01 08:55:00,293 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@67c27493
2016-03-01 08:55:00,511 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@5b8dfcc1
2016-03-01 08:55:00,729 [main] INFO  de.flapdoodle.embed.process.runtime.Executable - start ru.yandex.qatools.embed.postgresql.config.PostgresConfig@35e2d654
2016-03-01 08:55:00,815 [main] INFO  org.springframework.jdbc.datasource.DriverManagerDataSource - Loaded JDBC driver: org.postgresql.Driver

...testing....

2016-03-01 08:55:06,052 [Thread-32] WARN  de.flapdoodle.embed.process.runtime.AbstractProcess - Could not delete pid file: /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-8b47014f-928d-4d22-b9a6-5f9428bf62f3/pgsql/bin/psql.pid
2016-03-01 08:55:06,052 [Thread-40] WARN  de.flapdoodle.embed.process.io.file.Files - could not delete /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-8b47014f-928d-4d22-b9a6-5f9428bf62f3/pgsql/bin/psql.pid. Will try to delete it again when program exits.
2016-03-01 08:55:06,052 [Thread-47] INFO  org.springframework.context.support.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@6d8a00e3: startup date [Tue Mar 01 08:54:49 NZDT 2016]; root of context hierarchy
2016-03-01 08:55:06,052 [Thread-20] WARN  de.flapdoodle.embed.process.io.file.Files - could not delete /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-8b47014f-928d-4d22-b9a6-5f9428bf62f3/pgsql/bin/psql.pid. Will try to delete it again when program exits.
2016-03-01 08:55:06,052 [Thread-24] WARN  de.flapdoodle.embed.process.io.file.Files - could not delete /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-8b47014f-928d-4d22-b9a6-5f9428bf62f3/pgsql/bin/psql.pid. Will try to delete it again when program exits.
2016-03-01 08:55:06,057 [Thread-47] INFO  org.springframework.context.support.DefaultLifecycleProcessor - Stopping beans in phase 0
2016-03-01 08:55:06,052 [Thread-12] WARN  de.flapdoodle.embed.process.io.file.Files - could not delete /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-8b47014f-928d-4d22-b9a6-5f9428bf62f3/pgsql/bin/psql.pid. Will try to delete it again when program exits.
2016-03-01 08:55:06,053 [Thread-16] WARN  de.flapdoodle.embed.process.runtime.AbstractProcess - Could not delete pid file: /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-8b47014f-928d-4d22-b9a6-5f9428bf62f3/pgsql/bin/psql.pid
2016-03-01 08:55:06,053 [Thread-36] WARN  de.flapdoodle.embed.process.runtime.AbstractProcess - Could not delete pid file: /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-8b47014f-928d-4d22-b9a6-5f9428bf62f3/pgsql/bin/psql.pid
2016-03-01 08:55:06,053 [Thread-28] WARN  de.flapdoodle.embed.process.runtime.AbstractProcess - Could not delete pid file: /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-8b47014f-928d-4d22-b9a6-5f9428bf62f3/pgsql/bin/psql.pid
Exception in thread "Thread-40" 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)

2016-03-01 08:55:06,903 [Thread-6] INFO  de.flapdoodle.embed.process.runtime.ProcessControl - execSuccess: true [kill, -2, 37710]
2016-03-01 08:55:06,903 [Thread-6] WARN  de.flapdoodle.embed.process.runtime.AbstractProcess - Could not delete pid file: /var/folders/22/1f6xflcj60qgv_27xwtyxr1m0000gn/T/postgresql-embed-8b47014f-928d-4d22-b9a6-5f9428bf62f3/pgsql/bin/postgres.pid
2016-03-01 08:55:06,904 [Thread-47] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3b088d51: defining beans [propertyPlaceholderConfigurerBusinessBase,postgresService,dbCreator,simpleJdbcTemplate,dataSource,superDataSource,transactionManager,transactionInterceptor,autoProxyCreator,...,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor]; root of factory hierarchy

Process finished with exit code 0

from postgresql-embedded.

smecsia avatar smecsia commented on July 22, 2024

@zemudkram AFAIU you're using Spring4JUnitRunner (or a kind of) and the independent Spring context for each test class. That's why there are multiple messages about psql executable in the log.
I have some assumptions about the roots of your problem, but first I'd like to ask some questions.

  1. Why don't you share the single Spring context between the tests and single PostgreSQL instance accordingly? This could save you the execution time and also could solve your troubles with the concurrency of instances.
  2. How do you set the port number for each PostgreSQL instance? Is it randomly chosen or Postgres service chooses the first available?

Btw it would be great if you could create the example project, which would allow to reproduce the problem.

from postgresql-embedded.

zemudkram avatar zemudkram commented on July 22, 2024

@smecsia My apologies for taking so long to reply - I've been snowed under a bit lately.

Yes we are using Spring4JUnitRunner, or rather our test classes extend an abstract class that itself extends AbstractJUnit4SpringContextTests. When the tests are run as a suite or via maven on CLI, it seems to spin up one context and one PG for all the tests in the suite. So yes, to answer 1), we do this to some extent, but to be honest we've hacked it in to an existing test structure that relied on an always-up DB (meaning the tests never got run because they hadn't moved with the data). I've built a series of small datasets that are loaded in via DBUnit. I guess the next step is to extend that to all tests that require embeddedPG somehow. The refactoring is never done...

  1. Postgres chooses the first available port, using the same mechanism as in your test suite. The port number is fed into the Spring context using SpringEL.

I'm trying to set up an example project, but it might be some time away, sorry, since I don't have much spare time at the moment :)

from postgresql-embedded.

jnickc avatar jnickc commented on July 22, 2024

I have the same problem
SEVERE: Failed to read PID file (File '/tmp/postgresql-embed-24cf7813-46bb-4adf-bde5-9a2c57ead502/db-content-f508032a-7acf-4916-ae6f-6a7d4357c1ed/postmaster.pid' does not exist)

....Testing....
Exception in thread "Thread-18" java.lang.IllegalArgumentException: /tmp/postgresql-embed-24cf7813-46bb-4adf-bde5-9a2c57ead502/db-content-5796dc45-8f3f-43a4-9106-63d92f7f433e/pg_multixact does not exist
at org.apache.commons.io.FileUtils.cleanDirectory(FileUtils.java:1637)
at org.apache.commons.io.FileUtils.deleteDirectory(FileUtils.java:1535)

And after couple of times running the tests postgresql fails to start with exception:

PSQLException: FATAL: invalid value for parameter "TimeZone":

For running tests I use Spring4JUnitRunner
OS: 14.04.1-Ubuntu SMP Thu Oct 22 09:41:40 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

LC_ALL set to en_US.UTF-8

from postgresql-embedded.

smecsia avatar smecsia commented on July 22, 2024

@jnickc the same problem was discussed here #6. Please try to reboot or just kill the possibly remained psql proess.

from postgresql-embedded.

golimpio avatar golimpio commented on July 22, 2024

It has been more than a year since we last looked at this issue... I was the one that should gave you some feedback, but unfortunately I was unable to revisit this code until now.

Since the original issue (delete temp files) was fixed, I'm wondering if this issue can be closed already.

The second issue @zemudkram had raised (java.lang.IllegalStateException: Shutdown in progress) is a bit harder to debug, but it doesn't look like it's postgresql-embedded fault.

I'll try to resume the sequence of events that are triggering the exception: IllegalStateException("Shutdown in progress") on ApplicationShutdownHooks.

We have a Spring managed service that is responsible for starting and stopping the embedded Postgres (we call it PostgresService).

(1) When the tests are finished, If I'm running the tests from the IDE (IntelliJ) for example, the JUnitStarter will stop the thread before calling our service (PostgresService), and this will clean up the shutdown hooks (ApplicationShutdownHooks.runHooks()) - The behaviour is similar when running from Maven / command line.

(2) After JUnitStarter is done, Spring will stop our service (PostgresService).

(3) The JobKiller thread will now call AbstractProcess.stop() which calls PostgresProcess.stopInternal() > PostgresProcess.sendStopToPostgresqlInstance() > PostgresProcess.shutdownPostgres() > ... > PostgresStarter.newExecutable() > ... > Executable(), which finally calls ProcessControl.addShutdownHook(new Executable.JobKiller());

(4) At this point, since "shutdown hooks" is null, an IllegalStateException is thrown from ApplicationShutdownHooks.add().

As far as I understand, this is something we have to handle over here and it's not the tool's fault.

from postgresql-embedded.

golimpio avatar golimpio commented on July 22, 2024

It would be useful if I could set the daemon process flag to false, so at the Executable constructor, the shutdown hook wouldn't be created (then I'd stop the service manually, if necessary).

    public Executable(Distribution distribution, T config, IRuntimeConfig runtimeConfig, IExtractedFileSet executable) {
        this.distribution = distribution;
        this.config = config;
        this.runtimeConfig = runtimeConfig;
        this.executable = executable;
        if (runtimeConfig.isDaemonProcess()) {
            ProcessControl.addShutdownHook(new Executable.JobKiller());
        }
    }

from postgresql-embedded.

golimpio avatar golimpio commented on July 22, 2024

Also, I'm wondering if de.flapdoodle.embed.process.runtime.ProcessControl.addShutdownHook(Runnable runable) method could just ignore IllegalStateException (the exception that indicates that a shutdown is in progress).

Since the process is already being shutdown, adding a shutdown hook at this point is not possible and it wouldn't make much difference.

But then, it's a hard suggestion to make, since I'm only looking to my use case (it might help others, but it also might break things that I'm not aware of).

from postgresql-embedded.

smecsia avatar smecsia commented on July 22, 2024

@golimpio I'll try to debug this soon. For now you can try to disable "daemon process" option using the runtime configuration, like:

        return new RuntimeConfigBuilder()
                .defaults(Command.Postgres)
                .daemonProcess(false)  // this is the difference from the default configuration
                .artifactStore(new PostgresArtifactStoreBuilder()
                        .defaults(Command.Postgres)
                        .download(new PostgresDownloadConfigBuilder()
                                .defaultsForCommand(Command.Postgres)
                                .build()))
                .build();

from postgresql-embedded.

golimpio avatar golimpio commented on July 22, 2024

@smecsia Sorry, I think I forgot to mention it...

I've tried to disable the "daemon process" before, but it doesn't fully work:

  • When the PostgresProcess constructor is called, the public AbstractProcess(Distribution distribution, T config, IRuntimeConfig runtimeConfig, E executable) will be called.
  • Then you'll see a call to this.onBeforeProcess(runtimeConfig);
  • Which will run runCmd(config, runtimeConfig, InitDb, "Success. You can now start the database server using", 1000);
  • Then further in the same call, PostgresProcess.runCmd( PostgresConfig config, IRuntimeConfig runtimeConfig, Command cmd, String successOutput, Set<String> failOutput, long timeout, String... args) will be called
  • There, inside runCmd, will you see that it creates it's own IRuntimeConfig and ignores the .daemonProcess(false) set in the original RuntimeConfig.
  • At the end a shutdown hook will be added independent of my attempt to disable the "daemon process".

from postgresql-embedded.

golimpio avatar golimpio commented on July 22, 2024

I'm not sure, but perhaps the new IRuntimeConfig created by PostgresProcess.runCmd(...) should import the properties/flags set on the original RuntimeConfig ?

from postgresql-embedded.

smecsia avatar smecsia commented on July 22, 2024

@golimpio I see. Can you please test the version from #87 ?

from postgresql-embedded.

golimpio avatar golimpio commented on July 22, 2024

@smecsia I think this change might break some tests if someone else is setting the "daemon process" to false already (e.g. new RuntimeConfigBuilder().defaults(Command.Postgres).daemonProcess(false)...

Caused by: java.lang.RuntimeException: DaemonProcess(class java.lang.Boolean) already set to false
	at de.flapdoodle.embed.process.builder.AbstractEmbeddedBuilder.set(AbstractEmbeddedBuilder.java:60)
	at de.flapdoodle.embed.process.config.RuntimeConfigBuilder.daemonProcess(RuntimeConfigBuilder.java:73)
	at com.anzcro.o3.util.db.PostgresService.getCachedRuntimeConfig(PostgresService.java:83)
	at com.anzcro.o3.util.db.PostgresService.start(PostgresService.java:55)
	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 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1640)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1581)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511)
	... 42 moreCaused by: java.lang.RuntimeException: DaemonProcess(class java.lang.Boolean) already set to false
	at de.flapdoodle.embed.process.builder.AbstractEmbeddedBuilder.set(AbstractEmbeddedBuilder.java:60)
	at de.flapdoodle.embed.process.config.RuntimeConfigBuilder.daemonProcess(RuntimeConfigBuilder.java:73)
	at com.anzcro.o3.util.db.PostgresService.getCachedRuntimeConfig(PostgresService.java:83)
	at com.anzcro.o3.util.db.PostgresService.start(PostgresService.java:55)
	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 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1640)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1581)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511)
	... 42 more

from postgresql-embedded.

golimpio avatar golimpio commented on July 22, 2024

@smecsia Other than that, I haven't found any other issue.

If I don't set the daemonProcess to false, all tests will run and, as expected, I don't get the shutdown hook error.

from postgresql-embedded.

Related Issues (20)

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.