我想做一些Akka Multi Node测试,并在达到某个障碍时重新启动一个节点。类似的东西:
runOn(nodeA) {
// do something while both nodes are up and running
enterBarrier("nodeBCrashes")
// do something while I'm the only node up and running
enterBarrier("bothNodesUp")
// do something with both nodes up and running again
}
runOn(nodeB) {
// do something while both nodes are up and running
crash()
enterBarrier("nodeBCrashes")
// do nothing because I'm out
enterBarrier("bothNodesUp")
start()
// do something with both nodes up and running again
}
这是不可能完成的,至少需要一种方法能够关闭nodeB并使用相同的akka.remote.netty.tcp.port 启动另一个nodeC (这是严格的必要)。像这样的东西
runOn(nodeA) {
// do something while both nodes are up and running
enterBarrier("nodeBCrashes")
// do something while I'm the only node up and running
enterBarrier("bothNodesUp")
// do something with both nodes up and running again
}
runOn(nodeB) {
// do something while both nodes are up and running
enterBarrier("nodeBCrashes")
shutdown()
}
// How I can delay nodeC start until nodeA reaches bothNodesUp barrier?
runOn(nodeC) {
// do something when both nodes are up and running
}
问题可以恢复为:
我们可以重新创建一个节点崩溃然后重新启动的情况吗?
答案 0 :(得分:2)
您应该能够重新启动ActorSystem
重用崩溃的同一个端口。在Akka自己的多节点测试中,他们采取以下措施:
lazy val restartedSecondSystem = ActorSystem(
system,
ConfigFactory.parseString("akka.remote.netty.tcp.port=" + secondUniqueAddress.address.port.get).
withFallback(system.settings.config))
...
runOn(nodeB) {
shutdown(secondSystem)
}
enterBarrier("second-shutdown")
runOn(nodeB) {
Cluster(restartedSecondSystem).joinSeedNodes(seedNodes)
}
在Akka的源代码中查看以下测试以获取更多提示。