-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use Flapdoodle Embedded MongoDB for integration tests #436
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
Conversation
Closing & re-opening to force a new CI build. |
Thanks for the PR! I wonder if we want to enable this for the sample applications too? What are your thoughts @vpavic? |
@rwinch I've considered using this in sample app too but eventually decided to limit use to integration tests. My reasoning was the following:
This is in contrast to JDBC samples for example, which use H2 database, since H2 is full-blown RDBMS which also offers easily embeddable web client. |
@vpavic Thank you for your feedback. I somewhat see your point about the samples needing to provide a realistic experience for users. However, we do not want any extra noise for setting up samples. Fladoodle should certainly not be used in production, but I think it is ideal for helping users run a sample application. We are testing the sample with Fladoodle so that is how users should experience it (since we know that is what works). Finally Fladoodle is just downloading the executable and forking a process that starts up a full fledged Mongo instance. This means that this does not differ much from using an embedded relational database. |
@rwinch if we go with Flapdoodle to back the sample app, what happens with the part of the guide that describes usage of Mongo client to query and alter data (how does it work section)? |
@vpavic You can still connect to mongo when using Fladoodle using any Mongo client. |
@rwinch yes, I'm aware of that. But if you have Mongo client it's highly likely you also have Mongo server installed as well, that was one of my arguments for not moving sample app to Flapdoodle. But OK, if that's your preference I'll move the sample app to Flapdoodle. There's one more thing that crossed my mind today, and I've completely neglected it during initial implementation - embedded Flapdoodle instance needs to use random port to avoid any potential conflicts. That means in sample app scenario we also need to communicate this port to the user - is logging the port on startup good enough for this? |
@vpavic Thanks for the response.
That is fair. However, I think there are many people that will not care about performing the steps with the client (they just want to get it running). We should have a disclaimer that you must have a client installed within the guide.
This is an option. Alternatively (and probably preferably), we could default the port to using the standard port and ensure our test configuration overrides this to a random port. |
OK.
Even though this means sample app fails to start for users that run Mongo instance locally? This is somewhat in contradiction to "we do not want any extra noise for setting up samples" argument. |
That is a good point. Let's stick with logging. Perhaps it could even log "if you have the mongo client installed this is the command to connect"? |
@rwinch yes, that should be doable. I'll look into it and update the PR accordingly soon. |
65185b3
to
ed08593
Compare
@rwinch I've updated the PR, please review the changes. |
*/ | ||
@ContextConfiguration | ||
@DirtiesContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious why @DirtiesContext
was necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thing you pointed this out, @DirtiesContext
can be removed now.
I've had issues similar to ones described in #396 with my initial implementation, since I had static port config for embedded MongoDB instance.
Moving to randomly assigned port fixed this.
@vpavic Thanks for the fast turnaround. Overall looks good. I had one comment inline. When you update the documentation make sure that the guide either does not show the Flapdoodle config or it describes that this is just necessary to start mongo and not going to happen in a real world example. |
Yes, of course. Mongo-related config in sample app is in a separate |
It completely slipped my mind that we could use Spring Boot's auto-configuration for an embedded MongoDB instance. I'll change this in next update. |
ed08593
to
f2017aa
Compare
@rwinch I've updated the PR with the documentation/guide. I also tried the Boot's Embedded MongoDB auto-configuration support, however I've run into spring-projects/spring-boot#5487. UPDATE: Somehow I managed to miss the fact that this exception on shutdown also happens when we use manual conf. So I'll update this to auto-configuration anyway. Also it appears that nothing within Boot itself would be able to fix this behavior. |
f2017aa
to
903cac4
Compare
@vpavic Thanks for digging into this so deep and for the quality PR! This is now merged into master |
This resolves #419.
I've signed the CLA.