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

Add PostgreSQL-independent way for testing imports from Nominatim #515

Merged
merged 7 commits into from
Nov 22, 2020

Conversation

lonvia
Copy link
Collaborator

@lonvia lonvia commented Nov 20, 2020

This PR replaces the disabled import tests with unit tests for the NominatimConnector that implement the database accesses via a H2 in-memory database. The advantage of the H2 solution is that you don't need a PostgreSQL setup to run the tests and that the in-memory database is much faster to setup and tear down. Given that we only run relatively simple SELECT statements, the SQL differences are also minor enough to make the tests useful.

The only issue is with the hstore and geometry datatypes. I've replaced HSTORE with a simple JSON structure and the geometry with H2's own geometry type. That causes some trouble when demarshalling the data that comes from the database. The code for converting the returned values into Java datatypes is nicely encapsulated in DBUtils but I struggled to replace the functions for the tests. Providing my own implementation for the tests ended in 'Jar hell' when ES loads. Mocking static functions wasn't really working either. That is why there is now a DBUtils member in the NominatimConnector with non-static functions that can be mocked. Not pretty but it does the job. This doesn't need to be the final solution. If somebody with a better handle on Java can come up with a better solution, I'd warmly welcome a PR.

The first batch of tests only covers the basic functions of reading from placex, place_addressline and location_property_osmline. More complete tests to come in follow-up PRs.

The framework uses an H2 in-memory database to provide the data.
Given that we only use simple SELECT statements, this is sufficiently
close to the actual usage. The only change required is for hstore
and geometry datatypes. hstore gets replaced by json. For geometry
use H2's own geometry types. Both types need a slightly different
form of marshalling. This is done by mocking the functions in
DBUtils. I haven't found a usable way to replace the static functions,
so DBUtils is now an instantiated class with member functions.
These tests depend on a correctly lodaed Nominatim database.
For that reason they were never run and are possibly outdated
by now because the necessary database cannot be recreated with
today's OSM data.
More clean way of getting a different implementation into the tests.
The code iteself includes an implementation for Postgis-Adaptation.
The tests have an implementation for H2 which the Connector tests
use. Allows to remove all mocking code.
@lonvia lonvia merged commit 5415151 into komoot:master Nov 22, 2020
@lonvia lonvia deleted the test-nominatim-import branch November 22, 2020 21:26
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.

1 participant