Fix test DatabaseRegistryTest#shouldAwaitRunningQueriesBeforeDropping

Rationale:
It may happen that the threads in the test are not properly synchronized and
the one shutting down the db is faster than the first one to grap a reference to it.
Hence it might happen that the test fails.

Details:
- A new latch has been introduced to make sure that the thread are properly sunchronized.
- Test class has been cleaned up by introducing a @Before method.
- Fixed 2 deprecation warnings.
Merge pull request #3108 from davidegrohmann/2.2-fix-flaky-test

[2.2] Fix test DatabaseRegistryTest#shouldAwaitRunningQueriesBeforeDropping