gpt4 book ai didi

java - Vertx 测试部署 Verticle 的上下文问题

转载 作者:行者123 更新时间:2023-11-30 06:57:24 25 4
gpt4 key购买 nike

所以这有点偷偷摸摸,它不会 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 = Vertx.vertx(); 更改 Vertx vertx = Rule.vertx(); ,我会收到警告消息到控制台,但问题消失了。

所以,我做错了什么吗?这是一个问题吗?

最佳答案

您使用的是3.3.3版本吗?您可能会遇到以下问题:https://github.com/eclipse/vert.x/issues/1625 (已在 master 中修复)

关于java - Vertx 测试部署 Verticle 的上下文问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41548537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com