【问题标题】:How to restart node in Akka Multi Node test?如何在 Akka 多节点测试中重启节点?
【发布时间】:2016-12-20 02:07:49
【问题描述】:

我想做一些 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并启动另一个nodeC具有相同的akka​​.remote.netty.tcp.port(这是严格的必要的)。像这样的

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 文件但没有成功,是这样吗?

【问题讨论】:

    标签: akka akka-testkit


    【解决方案1】:

    您应该能够重新启动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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      • 2017-11-06
      • 2013-09-22
      • 2012-12-16
      • 2021-06-30
      相关资源
      最近更新 更多