0

我想做一些 Akka 多节点测试,并在达到某个障碍时重新启动一个节点。就像是:

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
} 

问题可以恢复为:

我们可以重现一个节点崩溃然后重新启动的情况吗?

  1. 我们可以重启一个节点吗?
  2. 如果没有,我们可以在其余节点达到 berrier 时启动一个节点吗?
  3. 我们能否将相同的 akka.remote.netty.tcp.port 分配给不同的节点(不应并行运行)。我试过*.opts文件但没有成功,是这样吗?
4

1 回答 1

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 源代码中的以下测试以获取更多提示。

https://github.com/akka/akka/blob/master/akka-cluster/src/multi-jvm/scala/akka/cluster/RestartNodeSpec.scala

https://github.com/akka/akka/blob/master/akka-cluster/src/multi-jvm/scala/akka/cluster/RestartNode2Spec.scala

https://github.com/akka/akka/blob/master/akka-cluster/src/multi-jvm/scala/akka/cluster/RestartNode3Spec.scala

于 2016-12-21T11:33:32.193 回答