zonkyio / embedded-database-spring-test

A library for creating isolated embedded databases for Spring-powered integration tests.
Apache License 2.0
400 stars 37 forks source link

Allow setting data directory as a Path and not convert it to File #147

Closed iaptekar closed 3 years ago

iaptekar commented 3 years ago

Using java.io.File prevents the usage of other FileSystems, in particular in-memory ones such as JimFS. The ability to use something like JimFS should improve performance and also help out in corporate environments where access to local folders is often restricted.

tomix26 commented 3 years ago

Could you be more specific? When I tried to find some occurrences, I did not find anything. Here is my search query: https://github.com/zonkyio/embedded-database-spring-test/search?q=%22java.io.File%22&type=code

If you mean https://github.com/zonkyio/embedded-postgres project, it is not possible to use any other file system here. It's because postgres executables need to be extracted to a filesystem to be able to start a new process in java. I don't know much about JimFS, but I don't think it's possible to run a system process from memory, is it?

iaptekar commented 3 years ago

I know that when I override the work and data directories I have to provide a File. I was wondering if changing this to Paths would allow for the use of something like JimFS. However, I honestly don't know if postgresql would run from it. I was just curious as it would speed things up tremendously. Maybe if only the data directory was moved that would be enough but again I don't know if that's possible.

tomix26 commented 3 years ago

Ok, now I've tested it and I'm pretty sure that JimFS is not applicable for this case. Because I need to know a real path to postgres binaries and target data directory to start a process with required parameters. But when I'm trying to obtain an absolute path from JimfsPath I only get a non-existent mock path /work/test-file.txt that cannot be passed to ProcessBuilder. Similarly, when I'm trying to convert JimfsPath to File it fails with unsupported operation exception.

Here are the commands that need to be executed to start a database: /.../pg-bin/bin/initdb -A trust -U postgres -D /.../pg-data-E UTF-8 /.../pg-bin/bin/pg_ctl -w -D /.../pg-data-o "-p 65432 -F -c timezone=UTC -c synchronous_commit=off -c max_connections=300" start

So at this moment, changing the use of File toPath has no added value and therefore I do not plan to implement it.

I'm closing the issue for now, but feel free to reopen it if you get any new ideas.