Fix formatting

This commit is contained in:
Tyler Benson 2019-07-10 14:18:54 -06:00
parent 53ef8f020f
commit e692605a3b
2 changed files with 63 additions and 59 deletions

View File

@ -13,7 +13,7 @@ class VertxRxWebClientTest extends HttpClientTest<NettyHttpClientDecorator> {
@Shared @Shared
Vertx vertx = Vertx.vertx(new VertxOptions()) Vertx vertx = Vertx.vertx(new VertxOptions())
@Shared @Shared
WebClient client = WebClient.create(vertx); WebClient client = WebClient.create(vertx)
@Override @Override
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) { int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {

View File

@ -26,16 +26,16 @@ public class VertxRxWebTestServer extends AbstractVerticle {
final Vertx vertx = Vertx.vertx(new VertxOptions().setClusterPort(port)); final Vertx vertx = Vertx.vertx(new VertxOptions().setClusterPort(port));
vertx.deployVerticle( vertx.deployVerticle(
VertxRxWebTestServer.class.getName(), VertxRxWebTestServer.class.getName(),
new DeploymentOptions() new DeploymentOptions()
.setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port)) .setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port))
.setInstances(3), .setInstances(3),
res -> { res -> {
if (!res.succeeded()) { if (!res.succeeded()) {
throw new RuntimeException("Cannot deploy server Verticle", res.cause()); throw new RuntimeException("Cannot deploy server Verticle", res.cause());
} }
future.complete(null); future.complete(null);
}); });
future.get(); future.get();
@ -44,69 +44,73 @@ public class VertxRxWebTestServer extends AbstractVerticle {
@Override @Override
public void start(final Future<Void> startFuture) { public void start(final Future<Void> startFuture) {
// final io.vertx.reactivex.core.Vertx vertx = new io.vertx.reactivex.core.Vertx(this.vertx); // final io.vertx.reactivex.core.Vertx vertx = new io.vertx.reactivex.core.Vertx(this.vertx);
final WebClient client = WebClient.create(vertx); final WebClient client = WebClient.create(vertx);
final int port = config().getInteger(CONFIG_HTTP_SERVER_PORT); final int port = config().getInteger(CONFIG_HTTP_SERVER_PORT);
final Router router = Router.router(vertx); final Router router = Router.router(vertx);
final CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx, final CircuitBreaker breaker =
new CircuitBreakerOptions() CircuitBreaker.create(
.setMaxFailures(5) // number of failure before opening the circuit "my-circuit-breaker",
.setTimeout(2000) // consider a failure if the operation does not succeed in time vertx,
// .setFallbackOnFailure(true) // do we call the fallback on failure new CircuitBreakerOptions()
.setResetTimeout(10000) // time spent in open state before attempting to re-try .setMaxFailures(5) // number of failure before opening the circuit
); .setTimeout(2000) // consider a failure if the operation does not succeed in time
// .setFallbackOnFailure(true) // do we call the fallback on failure
.setResetTimeout(10000) // time spent in open state before attempting to re-try
);
router router
.route("/") .route("/")
.handler( .handler(
routingContext -> { routingContext -> {
routingContext.response().putHeader("content-type", "text/html").end("Hello World"); routingContext.response().putHeader("content-type", "text/html").end("Hello World");
}); });
router router
.route("/error") .route("/error")
.handler( .handler(
routingContext -> { routingContext -> {
routingContext.response().setStatusCode(500).end(); routingContext.response().setStatusCode(500).end();
}); });
router router
.route("/proxy") .route("/proxy")
.handler( .handler(
routingContext -> { routingContext -> {
breaker.execute( breaker.execute(
ctx -> { ctx -> {
client.get(port, "localhost", "/test") client
.rxSendBuffer(Optional.ofNullable(routingContext.getBody()).orElse(Buffer.buffer())) .get(port, "localhost", "/test")
.subscribe( .rxSendBuffer(
response -> { Optional.ofNullable(routingContext.getBody()).orElse(Buffer.buffer()))
routingContext .subscribe(
.response() response -> {
.setStatusCode(response.statusCode()) routingContext
.end(response.body()); .response()
.setStatusCode(response.statusCode())
.end(response.body());
});
}); });
}); });
});
router router
.route("/test") .route("/test")
.handler( .handler(
routingContext -> { routingContext -> {
tracedMethod(); tracedMethod();
routingContext.next(); routingContext.next();
}) })
.blockingHandler(RoutingContext::next) .blockingHandler(RoutingContext::next)
.handler( .handler(
routingContext -> { routingContext -> {
routingContext.response().putHeader("content-type", "text/html").end("Hello World"); routingContext.response().putHeader("content-type", "text/html").end("Hello World");
}); });
vertx vertx
.createHttpServer() .createHttpServer()
.requestHandler(router::accept) .requestHandler(router::accept)
.listen(port, h -> startFuture.complete()); .listen(port, h -> startFuture.complete());
} }
@Trace @Trace
private void tracedMethod() { private void tracedMethod() {}
}
} }