[IOTA-36] Unit test for GlobalPerformer
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala b/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
index 15b6ead..3f74cec 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
@@ -162,13 +162,8 @@
* @return (performerID, ActorRef of the performer)
*/
private def createFeyActor(performerID: String, connectionIDs: Array[String], tmpActors:HashMap[String, ActorRef]):(String, ActorRef) = {
- // Performer is a global performer and is already created
- if(GlobalPerformer.activeGlobalPerformers.contains(orchestrationID)
- && GlobalPerformer.activeGlobalPerformers.get(orchestrationID).get.contains(performerID)){
- (performerID, GlobalPerformer.activeGlobalPerformers.get(orchestrationID).get.get(performerID).get)
- }
- // performer was already created
- else if(tmpActors.contains(performerID)){
+ // performer was already created
+ if(tmpActors.contains(performerID)){
(performerID, tmpActors.get(performerID).get)
}
else{
@@ -204,7 +199,13 @@
tmpActors.put(performerID, actor)
(performerID, actor)
}else{
- throw new IllegalPerformerCreation(s"Performer $performerID is not defined in the JSON")
+ // Performer is a global performer and is already created
+ if(GlobalPerformer.activeGlobalPerformers.contains(orchestrationID)
+ && GlobalPerformer.activeGlobalPerformers.get(orchestrationID).get.contains(performerID)){
+ (performerID, GlobalPerformer.activeGlobalPerformers.get(orchestrationID).get.get(performerID).get)
+ }else {
+ throw new IllegalPerformerCreation(s"Performer $performerID is not defined in the JSON")
+ }
}
}
}
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
index 927b87a..5db4760 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
@@ -275,6 +275,23 @@
TestProbe().expectActor(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER")
TestProbe().expectActor(s"$feyPath/$global_orch_name/ENS-GLOBAL")
}
+ "all previous actors restarted" in {
+ val routee = """$a"""
+ val routee2 = """$b"""
+ val routee3 = """$c"""
+ val routee4 = """$d"""
+ globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(s"${feyCoreRef.path.toString}/$global_orch_name")
+ Thread.sleep(500)
+ IdentifyFeyActors.actorsPath should have size (8)
+ IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/GLOBAL_MANAGER")
+ IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/GLOBAL_MANAGER/GLOBAL-TEST")
+ IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL")
+ IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER")
+ IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER/$routee")
+ IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER/$routee2")
+ IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER/$routee3")
+ IdentifyFeyActors.actorsPath should contain(s"$feyPath/$global_orch_name/ENS-GLOBAL/PERFORMER-SCHEDULER/$routee4")
+ }
}
"Stopping orchestration with global performer" should {
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala
index 0acc44c..9bed93b 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala
@@ -45,6 +45,9 @@
var global_managerRef:TestActorRef[GlobalPerformer] = null
var global_managerState:GlobalPerformer = null
+ var ensembleglobal:ActorRef = null
+ var childPerformer:ActorRef = null
+ var globalPerformer: ActorRef = null
"Creating an Global Manager " should {
"result in sending START message to Monitor actor" in {
@@ -54,5 +57,100 @@
global_managerState = global_managerRef.underlyingActor
monitor.expectMsgClass(1.seconds, classOf[Monitor.START])
}
+ s"result in creating an Orchestration child actor with the name '$orch_id'" in {
+ TestProbe().expectActor(s"${orchRef.path.toString}")
+ }
+ s"result in creating an Ensemble child actor with the name '${orchRef.path.toString}/ENS-GLOBAL'" in {
+ ensembleglobal = TestProbe().expectActor(s"${orchRef.path.toString}/ENS-GLOBAL")
+ }
+ s"result in creating a global Performer child actor with the name '${orchRef.path.toString}/GLOBAL_MANAGER/GLOBAL-TEST'" in {
+ globalPerformer = TestProbe().expectActor(s"${orchRef.path.toString}/$global_name/GLOBAL-TEST")
+ TestProbe().expectActor(s"${orchRef.path.toString}/$global_name")
+ }
+ s"result in creating a Performer child actor with the name '${orchRef.path.toString}/ENS-GLOBAL/PERFORMER-SCHEDULER'" in {
+ childPerformer = TestProbe().expectActor(s"${orchRef.path.toString}/ENS-GLOBAL/PERFORMER-SCHEDULER")
+ }
+ s"result in one global actor created for orchestration" in {
+ GlobalPerformer.activeGlobalPerformers should have size(1)
+ GlobalPerformer.activeGlobalPerformers should contain key(orch_id)
+ }
+ s"result in right number of running actors" in {
+ globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+ Thread.sleep(500)
+ IdentifyFeyActors.actorsPath should have size (9)
+ IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}")
+ IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER")
+ IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER/GLOBAL-TEST")
+ IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/ENS-GLOBAL")
+ IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/ENS-GLOBAL/PERFORMER-SCHEDULER")
+ }
+ }
+
+ "Stopping performer inside ensemble" should {
+ "Send stop message to monitor" in {
+ EventFilter.error(pattern = s".*DEAD nPerformers.*", occurrences = 1) intercept {
+ childPerformer ! PoisonPill
+ }
+ //Restarted ensemble
+ monitor.expectMsgClass(1.seconds, classOf[Monitor.START])
+ }
+ }
+
+ "Stopping ensemble" should {
+ "Send stop message to monitor" in {
+ EventFilter.warning(pattern = s".*ACTOR DEAD.*", occurrences = 1) intercept {
+ ensembleglobal ! PoisonPill
+ }
+ //Restarted ensemble
+ monitor.expectMsgClass(1.seconds, classOf[Monitor.TERMINATE])
+ }
+ "result in no orchestration running" in {
+ globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+ Thread.sleep(500)
+ IdentifyFeyActors.actorsPath should have size (3)
+ IdentifyFeyActors.actorsPath should not contain(s"${orchRef.path.toString}/ENS-GLOBAL")
+ }
+ "not affect global performer" in {
+ globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+ Thread.sleep(500)
+ IdentifyFeyActors.actorsPath should have size (3)
+ IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}")
+ IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER")
+ IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER/GLOBAL-TEST")
+ }
+ }
+
+ "Stopping global performer" should {
+ "result in restart the orchestration" in {
+ EventFilter.error(pattern = s".*DEAD Global Performers.*", occurrences = 1) intercept {
+ globalPerformer ! PoisonPill
+ }
+ monitor.expectMsgClass(1.seconds, classOf[Monitor.TERMINATE])
+ }
+ "all previous actors restarted" in {
+ globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+ Thread.sleep(500)
+ IdentifyFeyActors.actorsPath should have size (7)
+ IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}")
+ //TestProbe does not contain the right supervisor estrategy to restart global
+ //IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER")
+ //IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/GLOBAL-MANAGER/GLOBAL-TEST")
+ IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/ENS-GLOBAL")
+ IdentifyFeyActors.actorsPath should contain(s"${orchRef.path.toString}/ENS-GLOBAL/PERFORMER-SCHEDULER")
+ }
+ }
+
+ "Stopping orchestration" should {
+ "result in empty global" in {
+ orchRef ! PoisonPill
+ GlobalPerformer.activeGlobalPerformers.remove("GLOBAL-ORCH")
+ globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+ Thread.sleep(500)
+ IdentifyFeyActors.actorsPath should not contain(s"${orchRef.path.toString}/ENS-GLOBAL")
+ IdentifyFeyActors.actorsPath should not contain(s"${orchRef.path.toString}/GLOBAL-MANAGER")
+ IdentifyFeyActors.actorsPath should not contain(s"${orchRef.path.toString}/GLOBAL-MANAGER/GLOBAL-TEST")
+
+ GlobalPerformer.activeGlobalPerformers should have size(0)
+ }
}
}