Allow creating a CuratorTestingServerExtension that starts the testing server in the constructor? #238
Replies: 1 comment
-
Created issue #239 from this discussion, so this is effectively closed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background
The original (i.e. pre-GitHub) implementation of
CuratorTestingServerExtension
did the following in its constructor:The above is equivalent to:
When we re-implemented this in kiwi-test, we chose to do this in the constructor:
And then in the
beforeAll
we calledtestingServer.start()
. Doing it this way is more correct in the way JUnit Jupiter extensions should behave.However, this caused an issue when testing Dropwizard services using the
DropwizardAppExtension
, specifically because Dropwizard does not follow typical Jupiter extension conventions. It looks something like this when we're using the Dropwizard extension and theCuratorTestingServerExtension
:But when using the kiwiproject extension, the above does not work because there is no way to ensure the Curator
TestingServer
starts before the Dropwizard extension launches the test application. As a result, theApp
classes under test can never connect to a the Curator testing Zookeeper server, so we end up mocking things like leader latches insideApp
by doing something like:This is not ideal, and doesn't test the actual leader latch in the
App
class.To allow us to use the Dropwizard extension and the Curator testing extension, we could add a new constructor in the kiwiproject
CuratorTestingServerExtension
that accepts a second argument that forces the testing server to start immediately, i.e. it would callnew TestingServer(port, true)
.While this is not the "correct" way to do most Jupiter extensions, we don't have a choice in this case if we want to use it with the (nonstandard) Dropwizard extension mechanism. So we might do something like:
where
ServerStart
is perhaps anenum
insideCuratorTestingServerExtension
:Again, while this isn't ideal and not the recommended way, we would no longer need to create the
MockLeaderLatchApp
and mock things out when we're trying to do integration testing.Beta Was this translation helpful? Give feedback.
All reactions