Last active
July 31, 2017 15:39
-
-
Save chefhoobajoob/066fc3c8c5bb5c1c8335135c8d73a43f to your computer and use it in GitHub Desktop.
Reproducer for vertx-health-check-js error when completing futures with status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
vertxStartAsync: function (startFuture) { | |
vertx.executeBlocking(function (blockingFuture) { | |
try { | |
var Router = require("vertx-web-js/router"); | |
var router = Router.router(vertx); | |
var handler = require("vertx-health-checks-js/health_check_handler").create(vertx); | |
handler.register("complete-with-ok", function (future) { | |
console.log('>>> verticle: complete-with-ok: ' + | |
'completing future with: {ok: true}'); | |
future.complete( {ok: true} ); | |
console.log('>>> complete-with-ok: done') | |
}); | |
handler.register("complete-with-nothing", function (future) { | |
console.log('>>> verticle: complete-with-nothing: completing future'); | |
future.complete(); | |
console.log('>>> verticle: complete-with-nothing: done') | |
}); | |
router.get("/health/*").handler(handler.handle); | |
var server = vertx.createHttpServer(); | |
server.requestHandler(router.accept).listen(5050); | |
console.log('>>> verticle: now listening on port 5050') | |
blockingFuture.complete() | |
} catch(error) { | |
blockingFuture.fail(error) | |
} | |
}, function(result, error) { | |
error ? startFuture.fail(error) : startFuture.complete(); | |
}) | |
}, | |
vertxStop: function () { | |
logger.debug('verticle stopped') | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.github.hoobajoob.vertx.health.tests; | |
import io.vertx.ext.unit.Async; | |
import io.vertx.ext.unit.TestContext; | |
import io.vertx.ext.unit.junit.VertxUnitRunner; | |
import io.vertx.rxjava.core.Vertx; | |
import io.vertx.rxjava.ext.web.client.WebClient; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
@RunWith(VertxUnitRunner.class) | |
public class JavascriptHealthChecks { | |
@Test(timeout=10000L) | |
public void test( TestContext context ) { | |
Vertx vertx = Vertx.vertx(); | |
Async deploy = context.async(); | |
System.out.println(">>> test: starting health check verticle"); | |
vertx.deployVerticle( "HealthCheck.js", context.asyncAssertSuccess(id -> deploy.complete()) ); | |
deploy.await(); | |
WebClient client = WebClient.create(vertx); | |
System.out.println(">>> test: sending complete-with-nothing health check"); | |
Async nothing = context.async(); | |
client.get(5050, "localhost", "/health/complete-with-nothing") | |
.send( async -> { | |
if ( async.failed() ) { | |
System.out.println(">>> test: there's a problem, occifer: " + async.cause().getMessage() ); | |
async.cause().printStackTrace(); | |
nothing.complete(); | |
} | |
System.out.println(">>> test: got a (" + async.result().statusCode() + | |
") response:\n" + async.result().bodyAsJsonObject().encode() ); | |
nothing.complete(); | |
}); | |
nothing.await(); | |
System.out.println(">>> test: sending complete-with-ok health check"); | |
Async ok = context.async(); | |
client.get(5050, "localhost", "/health/complete-with-ok") | |
.send( async -> { | |
if ( async.failed() ) { | |
System.out.println(">>> test: there's a problem, occifer: " + async.cause().getMessage() ); | |
async.cause().printStackTrace(); | |
ok.complete(); | |
} | |
System.out.println(">>> test: got a (" + async.result().statusCode() + | |
") response:\n" + async.result().bodyAsJsonObject().encode() ); | |
ok.complete(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Having a look right now.