Dropwizard: How to stop service programmatically

前端 未结 5 767
花落未央
花落未央 2021-01-04 06:13

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

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 06:48

    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(MyService.class,
                        Resources.getResource("service.yml").getPath()));
    
        @Test
        public void someTest(){
        ....
    

提交回复
热议问题