Java – dropwizard: how to stop the service programmatically
•
Java
To start the service, I know one that uses the new myservice () run(args). How to stop it?
I need to start and stop the program in the way of setup () and teardown () in my test
Solution
You can start the service in a new thread. Once the test is completed, the service will shut down automatically
However, from dropwizard 0.6 Starting from 2, the dropwizard testing module contains a JUnit rule, which is fully applicable to this use case (see here)
The use of this rule will be as follows:
Class MyTest {
@ClassRule
public static TestRule testRule = new DropwizardServiceRule<MyConfiguration>(MyService.class,Resources.getResource("service.yml").getPath()));
@Test
public void sometest(){
....
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
