所以这有点像一个偷偷摸摸的,它不会100%的时间出现,但情况就是这样:
我创建了一个JUnit
集成类,声明为Rule
以在上下文中运行,然后我从规则中提取vertx
对象。然后我将新的Verticle部署到vertx
,如果尝试部署超过~3-4个Verticle,我会为每个Verticle得到这个:
Jan 09, 2017 2:43:33 PM io.vertx.core.impl.ContextImpl
SEVERE: Unhandled exception
java.lang.IllegalStateException: Result is already complete: succeeded
at io.vertx.core.impl.FutureImpl.checkComplete(FutureImpl.java:164)
at io.vertx.core.impl.FutureImpl.complete(FutureImpl.java:108)
at io.vertx.core.impl.FutureImpl.handle(FutureImpl.java:135)
at io.vertx.core.impl.FutureImpl.handle(FutureImpl.java:23)
at io.vertx.core.eventbus.impl.EventBusImpl.lambda$callCompletionHandlerAsync$2(EventBusImpl.java:340)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:316)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:440)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
at java.lang.Thread.run(Thread.java:745)
导致此问题的代码如下:
@RunWith(VertxUnitRunner.class)
public class VertxTest {
@Rule
public RunTestOnContext rule = new RunTestOnContext(Vertx::vertx);
@Test
public void testLinearExecution(TestContext context) {
Vertx vertx = rule.vertx();
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
this.vertx.eventBus().consumer("bla", event -> {});
}
});
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
this.vertx.eventBus().consumer("bla", event -> {});
}
});
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
this.vertx.eventBus().consumer("bla", event -> {});
}
});
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
this.vertx.eventBus().consumer("bla", event -> {});
}
});
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
this.vertx.eventBus().consumer("bla", event -> {});
}
});
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
this.vertx.eventBus().consumer("bla", event -> {});
}
});
}
}
这可能取决于运行它的机器,但我的猜测是,如果它没有重现,请添加更多这些人以使其更有可能:
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
this.vertx.eventBus().consumer("bla", event -> {});
}
});
另外要提的是,如果我用Vertx vertx = rule.vertx();
更改Vertx vertx = Vertx.vertx();
,我会收到控制台的警告消息,但问题就会消失。
所以,我做错了什么?这是一个问题吗?