mercredi 17 août 2016

Clustered Vertx won't work on integration tests

I have set up an application with Vert.x, which worked fine until I clustered the Vert.x instance.

Eventhough the authentication still works when I try it, the authentication tests fail all the time. It seems that the eventbus doesn't send the messages correctly.

Thats the clustering I did on the server:

public void start() {

    mgr = new HazelcastClusterManager();
    VertxOptions vertxOptions = new VertxOptions();
    vertxOptions.setClusterManager(mgr);
    Vertx.clusteredVertx(vertxOptions, res -> {
        if (res.succeeded()) {
            vertx =res.result();
            eb = vertx.eventBus();
            System.out.println(eb);
            initialiseServer(vertx);
        } else {
            System.out.println("Failed: " + res.cause());
        }
    });

And here's the @BeforeClass method in my tests (I tried to connect to the cluster and then deploy the server to start it):

   @BeforeClass
public static void start(TestContext context) {
    Async async = context.async();
    server = new VertXBiEServer();
    JsonObject mockConfig = new JsonObject().put("auth", true);
    JsonObject config = new JsonObject().put("mockConfig", mockConfig).put("mockServices", true);
    ClusterManager mgr = new HazelcastClusterManager();
    VertxOptions options = new VertxOptions().setClusterManager(mgr);
    Vertx.clusteredVertx(options, clusterResult -> {
        if (clusterResult.succeeded()) {
            VertXBiEServer server = new VertXBiEServer();
            vertx = clusterResult.result();
            eb = vertx.eventBus();
            DeploymentOptions deplOptions = new DeploymentOptions().setConfig(config);
            vertx.deployVerticle(server, deplOptions, res -> {
                if (res.succeeded()) {
                    System.out.println("Deployment of Clusterdata verticle complete");
                    async.complete();
                } else {
                    context.fail();
                }
            });
        } else {
            System.out.println("Error");
        }
    });
}

In my test I try to send a message and then get a reply, which worked before I did the clustering.

 eb.send(AddressConstants.LOGIN , "", rply -> {
        if (!rply.succeeded()) {
            context.fail();
        } 

As I said the login works in the application. However I get following error: java.lang.AssertionError: Test failed in the line context.fail();

Did I do something wrong in the @BeforeClass method? Because I get a reply when I send the message in other classes.

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire