Failures not reported when executeBlocking is invoked without a result handler

Fixes #3009

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
This commit is contained in:
Thomas Segismont
2019-07-03 17:37:05 +02:00
committed by Julien Viet
parent fdac684382
commit 63d5ad764f
2 changed files with 41 additions and 16 deletions

View File

@@ -13,16 +13,10 @@ package io.vertx.core.impl;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.vertx.core.AsyncResult;
import io.vertx.core.Closeable;
import io.vertx.core.Context;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.core.*;
import io.vertx.core.impl.logging.Logger;
import io.vertx.core.impl.logging.LoggerFactory;
import io.vertx.core.json.JsonObject;
import io.vertx.core.spi.metrics.PoolMetrics;
import io.vertx.core.spi.tracing.VertxTracer;
@@ -181,9 +175,13 @@ abstract class ContextImpl extends AbstractContext {
if (metrics != null) {
metrics.end(execMetric, fut.succeeded());
}
if (resultHandler != null) {
fut.setHandler(ar -> context.runOnContext(v -> resultHandler.handle(ar)));
}
fut.setHandler(ar -> {
if (resultHandler != null) {
context.runOnContext(v -> resultHandler.handle(ar));
} else if (ar.failed()) {
context.reportException(ar.cause());
}
});
};
Executor exec = workerPool.executor();
if (queue != null) {

View File

@@ -11,11 +11,7 @@
package io.vertx.core;
import io.vertx.core.impl.ContextInternal;
import io.vertx.core.impl.TaskQueue;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.impl.VertxThread;
import io.vertx.core.impl.WorkerPool;
import io.vertx.core.impl.*;
import io.vertx.test.core.VertxTestBase;
import org.junit.Test;
@@ -317,6 +313,37 @@ public class ContextTest extends VertxTestBase {
await();
}
@Test
public void testExceptionInExecutingBlockingWithContextExceptionHandler() {
RuntimeException expected = new RuntimeException("test");
Context context = vertx.getOrCreateContext();
context.exceptionHandler(t -> {
assertSame(expected, t);
complete();
});
vertx.exceptionHandler(t -> {
fail("Should not be invoked");
});
context.executeBlocking(promise -> {
throw expected;
}, null);
await();
}
@Test
public void testExceptionInExecutingBlockingWithVertxExceptionHandler() {
RuntimeException expected = new RuntimeException("test");
Context context = vertx.getOrCreateContext();
vertx.exceptionHandler(t -> {
assertSame(expected, t);
complete();
});
context.executeBlocking(promise -> {
throw expected;
}, null);
await();
}
@Test
public void testVerticleUseDifferentExecuteBlockingOrderedExecutor() throws Exception {
testVerticleUseDifferentOrderedExecutor(false);