DropWizard Application Integration Testing

I just read the DropWizard testing docs and fell in love with its built-in capabilities. Integrated testing capabilities . TL DR: it allows your JUnit tests to deploy Jetty instances in memory and, in essence, serve API endpoints (resource methods) since they will exist in the wild. This allows you to actually hit the API endpoints with the client (against localhost ) and see how they work / execute. Excellent!

I am wondering if it is possible to use this DropWizardAppRule (or something similar to it) to start / disconnect my DropWizard application and check that no exceptions were selected (smoke testing); and

Testing the smoke would be useful because there might be some kind of initialization exception that prevents the application from starting (a bad configuration file, etc.), and it would be nice to know about it in advance. Similarly, smoke testing on shutdown is useful, because we may have something that does not close / break off gracefully, and may have a hanging flow that just won’t die, etc.

It would also be nice to test the running server in memory and see where it is being pushed (maybe throwing OOME?).

So, given the following code snippet:

 public class IntegrationTest { @ClassRule public static final DropwizardAppRule<TestConfiguration> RULE = new DropwizardAppRule<TestConfiguration>(MyApp.class, resourceFilePath("my-app-config.yaml")); @Test public void shouldStartWithNoExceptions() { // ??? } @Test public void stressTest10kUsers() { // What exceptions could I check for to see if the server pushed over after // 10,000 random endpoints were hit? } @Test public void shouldShutdownGracefully() { // ??? } } 

I'm asking:

  • How to check server startup without exception?
  • How to check if the server continues to respond and is not dead (due to stress testing)?
  • How to close the server and make sure that the exception was not thrown or that nothing prevented the graceful completion?
+6
source share
1 answer

1.) I think you mean Exceptions that kill the DW application because there are some desirable exceptions, such as WebAppExceptions. So you just need to check if your application is working. If there is a big problem, your DW application does not start and therefore cannot respond to reuqests.

Here are some additional ideas: a.) If you want to test external dependencies, testing in jenkins or on your local machine is not a good idea. To test your application in the LIVE environment, you can create HealthChecks and test it using curling or http-client tools. You should get json like:

 {"deadlocks":{"healthy":true},"database":{"healthy":true}} 

Check this from extern, for example, remove this DW instance from your loadbalancer if the healthchecks singnals are unhealthy. Add one Healthcheck for all the important things, so you can be sure that your application is healthy or not.

b.) Perform some resource tests after starting your application. If you get a response, your DW application will start. c.) Check your journal. Find the log level ERROR or WARN. If there are null entries, you can assume that your application runs without exception.

2.) Just make an HTTP request to your resource ;-) The answer means that your application is running.

3.) I am using ShutdownHooks. There I check all the important things, for example, the DB connection is closed ... It is usually normal to close the application gracefully.

You can add code cut to your Service constructor.

 public YourService(){ ... // In case vm shutdown Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { // what should be closed if forced shudown // .... LOG.info(String.format("--- End of ShutDownHook (%s) ---", APPLICATION_NAME)); } }); ... } 

If this is not the answer, please provide additional information.

+4
source

Source: https://habr.com/ru/post/979574/


All Articles