【发布时间】:2020-05-19 19:05:03
【问题描述】:
我在我的 4vcpu 和 16gb 容量 (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
我什么都试过了。我的指针受到高度赞赏。谢谢。
我的测试:
"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 timeout akka-cluster