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

瀏覽次數:213 次
跳到第一則未讀訊息

dominik....@trivago.com

未讀,
2016年8月25日 清晨5:59:582016/8/25
收件者: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

未讀,
2016年8月30日 上午11:03:492016/8/30
收件者: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 ...
回覆所有人
回覆作者
轉寄
0 則新訊息