To start the service, I know one uses new MyService().run(args)
. How to stop it?
I need to start and stop programmatically for setUp()
and tearDown()
in my tests.
You can start the service in new thread, once the test ends the service will shutdown automatically.
However starting in dropwizard 0.6.2 the dropwizard-testing module contains a junit rule exactly for this use case (see here).
Usage of this rule will look something like this:
Class MyTest {
@ClassRule
public static TestRule testRule = new DropwizardServiceRule<MyConfiguration>(MyService.class,
Resources.getResource("service.yml").getPath()));
@Test
public void someTest(){
....
Keep the environment
variable around and add the following method to your application:
public void stop() throws Exception {
environment.getApplicationContext().getServer().stop();
}
Now you can call myService.stop()
to stop the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With