java - Akka java.lang.AssertionError:expectMessage期间超时(3秒)等待
问题描述
我在我的 4vcpu 和 16gb 容量(t2.xlarge)的 Amazon linux ec2 实例上运行 multi-jvm:test。我正在运行 2 个节点。每当我运行 sbt multi-jvm:test 命令时,
java.lang.AssertionError: timeout (3 seconds) during expectMessage while waiting for com.psing069.akka.sample.BankAccount$Account@30331109
我已经尝试了一切。我的指针受到高度赞赏。谢谢你。
我的测试:
"handle updates directly after start" in within(60.seconds) {
runOn(node2) {
bankAccount ! new BankAccount.Deposit(200)
bankAccount ! new BankAccount.Withdraw(100)
}
enterBarrier("updates-done")
awaitAssert {
val probe = TestProbe[Account]()
bankAccount ! new BankAccount.GetBalance(probe.ref)
// val state = probe.expectMessageType[Account](60.seconds)
// state.balance should be (100)
probe.expectMessage(new Account(100))
}
enterBarrier("after-2")
}
我的演员是:
public static class Account {
//String account_number;
int balance;
public Account(int balance){
this.balance = balance;
//this.account_number = account_number;
}
}
private static class InternalGetResponse implements Command {
public final GetResponse<PNCounter> rsp;
public final ActorRef<Account> replyTo;
private InternalGetResponse(GetResponse<PNCounter> rsp, ActorRef<Account> replyTo) {
this.rsp = rsp;
this.replyTo = replyTo;
}
}
private Behavior<Command> onGetBalance(GetBalance command) {
replicator.askGet(
askReplyTo -> new Get<>(dataKey, readMajority, askReplyTo),
rsp -> new InternalGetResponse(rsp, command.replyTo)
);
return Behaviors.same();
}
private Behavior<Command> onInternalGetResponse(InternalGetResponse msg) {
if (msg.rsp instanceof GetSuccess) {
PNCounter data = ((GetSuccess<PNCounter>) msg.rsp).get(dataKey);
msg.replyTo.tell(new Account(data.getValue().intValue()));
} else if (msg.rsp instanceof NotFound) {
msg.replyTo.tell(new Account(0));
} else if (msg.rsp instanceof GetFailure) {
// ReadMajority failure, try again with local read
replicator.askGet(
askReplyTo -> new Get<>(dataKey, Replicator.readLocal(), askReplyTo),
rsp -> new InternalGetResponse(rsp, msg.replyTo)
);
}
return Behaviors.same();
}
解决方案
我用的是Java,但是解决方法是一样的:需要在配置中配置leeway
超时
akka{
loggers = [akka.testkit.TestEventListener]
log-level = DEBUG
test{
filter-leeway = 10 seconds
default-timeout = 12 seconds
}
}
此外,您必须确保在 CI 环境中加载配置。例如,当您创建 ActorSystem 时,加载正确的配置
Config config = ConfigFactory.load("application-test");
ActorSystem system = ActorSystem.create(testSystemName, config);
推荐阅读
- vba - VBA 代码 32 位到 64 位
- pyspark - 未能在 Delta 表中保存结构字段
- php - php:如何使用 simplexml_load_file 解析节点名称中包含“:”的 XML?
- python - 尝试使用 pip 在 Python 中安装 ssl 库时出现语法错误
- python - PySpark/python- 我尝试使用 for 循环,但它返回空数据帧。我该如何解决?
- c# - C# - 数学/逻辑 - 检查哪个值更接近
- neo4j - Neo4J 数据库性能
- javascript - Angular添加具有相同属性的行
- docker - Teamcity 锁定安装在 Docker 容器内的目录
- javascript - 响应式数据表 - 显示数据表警告