如何在Akka多节点测试中重新启动节点?

如何在Akka多节点测试中重新启动节点?,akka,akka-testkit,Akka,Akka Testkit,我想做一些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

我想做一些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
} 
问题可恢复为:

我们能否重新创建一个节点崩溃然后重新启动的情况?

  • 我们可以重新启动一个节点吗
  • 如果没有,我们可以在其他节点到达berrier时启动节点吗
  • 我们是否可以将相同的akka.remote.netty.tcp.port分配给不同的节点(不应该并行运行)。我试过使用文件,但没有成功,是这样吗

  • 您应该能够重新启动
    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源代码中的以下测试以获得更多提示


    您应该能够重新启动
    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源代码中的以下测试以获得更多提示