我正在我的4vcpu和16 of容量(t2.xlarge)的Amazon linux ec2实例上运行一个多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我什么都试过了。I指针是高度赞赏的。谢谢。
我的测试:
"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();
}发布于 2021-11-26 09:30:52
我使用的是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);https://stackoverflow.com/questions/60049156
复制相似问题