How to set global config in JUnit/vertx unit test?

213 views
Skip to first unread message

dominik....@trivago.com

unread,
Aug 25, 2016, 5:59:58 AM8/25/16
to vert.x

Hi everybody,

I am using vertx unit in combination with JUnit for my unit tests.

I have a MainVerticle, which deploys a SubVerticle.

In both verticles, I query some value from config(). When started from the IDE or the fat JAR, I supply the configuration with a -conf /some/path/config.json parameter.

When I run within a JUnit test which tests the MainVerticle, how can I set such a global configuration? If I create a DeploymentOptions() and pass them to the vertx.deploy(MainVerticle.class.getName(), options, handler), they are not automatically forwarded to the SubVerticle, since I don't pass any options when deploying it from inside the MainVerticle.

As a workaround, I deploy the SubVerticle from within the MainVerticle.start(...) like this:
   
vertx.deployVerticle(FetchItemPricesVerticle.class.getName(), new DeploymentOptions().setConfig(config()));

This seems like a hack to me, so my question is: How to simulate a global config in a JUnit test?

Thanks for any suggestions
Dominik

dominik....@trivago.com

unread,
Aug 30, 2016, 11:03:49 AM8/30/16
to vert.x
OK, I kinda found a workaround:

I now deploy all verticles through one "LauncherVerticle". All verticles are deployed with

vertx.deployVerticle(HandleJsonRequestVerticle.class.getName(), new DeploymentOptions().setConfig(config()).setInstances(4), future.completer());

With this, I can configure the system centrally, since all configuration is done within the LauncherVerticle.

I am still not sure if this is "best practice", but it works for me ...
Reply all
Reply to author
Forward
0 new messages