Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow customization of data dir between database initialization and start #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vladimirfx
Copy link

I doubt I chose the right name...but it works

Refs: #144

Copy link
Collaborator

@tomix26 tomix26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution. The changes look good, just address the comments bellow and I'll be happy to merge it.

@@ -583,7 +595,7 @@ public EmbeddedPostgres start() throws IOException {
}
return new EmbeddedPostgres(parentDirectory, builderDataDirectory, builderCleanDataDirectory, config,
localeConfig, builderPort, connectConfig, pgBinaryResolver, errRedirector, outRedirector,
pgStartupWait, overrideWorkingDirectory);
pgStartupWait, overrideWorkingDirectory, dataDirectoryCustomizer);
}

@Override
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new variable needs to be included in the equals and hashCode method implementations. Comparing lambda functions isn't easy, so in this case, I would suggest comparing the results of getClass() calls, see the example below:

Objects.equals(dataDirectoryCustomizer != null ? dataDirectoryCustomizer.getClass() : null, builder.dataDirectoryCustomizer != null ? builder.dataDirectoryCustomizer.getClass() : null)

And similar logic in the hashCode method implementation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I would fix this. Thanx for advice!

@@ -47,10 +48,18 @@ public void testEmbeddedPg() throws Exception
@Test
public void testEmbeddedPgCreationWithNestedDataDirectory() throws Exception
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test feels a little bit contrived. Instead of this approach, it would be better to actually modify a configuration file (like postgres.conf, doesn't have to be pg_hba.conf) and then verify through SQL queries that this change is correctly applied.

Similar to this test: https://github.com/zonkyio/embedded-database-spring-test/blob/master/embedded-database-spring-test/src/test/java/io/zonky/test/db/config/ConfigurationPropertiesIntegrationTest.java

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole point of this test is to verify that lambda is called with the proper dir, not to test lambda logic or abilities—it can be anything useful between init and start, even modifications of template databases. So why do we need to check the distinct file modification effect, what do we verify by that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We verify that the entire concept works. The purpose of this pull request is to enable changes to the Postgres process configuration, not just to ensure that the lambda function is called with the correct parameters.

If you make the change below, the test will still pass, but the customizer will have no effect. This means that the test is insufficient. That’s my point.

        lock();

//        if (dataDirectoryCustomizer != null) {
//            dataDirectoryCustomizer.accept(dataDirectory);
//        }

        startPostmaster();

        if (dataDirectoryCustomizer != null) {
            dataDirectoryCustomizer.accept(dataDirectory);
        }

@tomix26 tomix26 added this to the 2.2.0 milestone Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants