lundi 7 septembre 2015

Can not set up clustered Vert.x environment from my JUnit test

I have a junit test where I would like to set up a clustered vert.x environment. It works fine if I run the code in the setUp method from the public static void main() method but not if it is run from the setUpmethod.
The public void handle(AsyncResult<Vertx> res) method is never invoked! Why?

@RunWith(VertxUnitRunner.class)
public class TestMyStuff {
    private Vertx vertx;

    @Before
    public void setUp(TestContext context) throws IOException {

        ClusterManager mgr = new HazelcastClusterManager();
        VertxOptions options = new VertxOptions().setClusterManager(mgr);
        Vertx.clusteredVertx(options, new Handler<AsyncResult<Vertx>>() {
            @Override
            public void handle(AsyncResult<Vertx> res) {
                if(res.succeeded()) {
                    vertx = res.result();

                    DeploymentOptions options = new DeploymentOptions()
                            .setConfig(new JsonObject().put("http.port", 8080)
                            );
                    vertx.deployVerticle(MyWebService.class.getName(), options, context.asyncAssertSuccess());
                    System.out.println("SUCCESS");
                } else {
                    System.out.println("FAILED");
                }
            }
        });
    }

    @Test
    public void printSomething(TestContext context) {
        System.out.println("Print from method printSomething()");
    }

"Print from method printSomething()" is beeing written but not "SUCCESS" or "FAILED" from the handle() method.

Why does not it work in the setUp method but from main()?

Aucun commentaire:

Enregistrer un commentaire