iota-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tonyfaust...@apache.org
Subject [10/12] incubator-iota git commit: [IOTA-36] Unit test for GlobalPerformer
Date Tue, 31 Jan 2017 22:29:13 GMT
[IOTA-36] Unit test for GlobalPerformer


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/35a83e9a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/35a83e9a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/35a83e9a

Branch: refs/heads/master
Commit: 35a83e9ae451b78331e0b10f0b5dd202514d4b42
Parents: 048934f
Author: Barbara Gomes <barbaramaltagomes@gmail.com>
Authored: Tue Jan 31 11:56:53 2017 -0800
Committer: Barbara Gomes <barbaramaltagomes@gmail.com>
Committed: Tue Jan 31 11:56:53 2017 -0800

----------------------------------------------------------------------
 .../scala/org/apache/iota/fey/Ensemble.scala    | 17 ++--
 .../scala/org/apache/iota/fey/FeyCoreSpec.scala | 17 ++++
 .../apache/iota/fey/GlobalPerformerSpec.scala   | 98 ++++++++++++++++++++
 3 files changed, 124 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/35a83e9a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
----------------------------------------------------------------------
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 @@ protected class Ensemble(val orchestrationID: String,
     * @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 @@ protected class Ensemble(val orchestrationID: String,
         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")
+        }
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/35a83e9a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
----------------------------------------------------------------------
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 @@ class FeyCoreSpec extends BaseAkkaSpec  {
       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 {

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/35a83e9a/fey-core/src/test/scala/org/apache/iota/fey/GlobalPerformerSpec.scala
----------------------------------------------------------------------
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 @@ class GlobalPerformerSpec extends BaseAkkaSpec{
   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 @@ class GlobalPerformerSpec extends BaseAkkaSpec{
       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)
+    }
   }
 }


Mime
View raw message